ScriptObject now looks for a default member for everything that it can not handle, meaning that scripts based on values now work.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@72 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-11-01 17:54:14 +00:00
parent f18bdafab1
commit ea5be88bdb
7 changed files with 63 additions and 24 deletions
+11 -2
View File
@@ -23,8 +23,8 @@ ScriptValueP ScriptValue::next() { throw InternalEr
ScriptValueP ScriptValue::makeIterator() const { throw ScriptError( _("Can't convert from ")+typeName()+_(" to collection")); }
int ScriptValue::itemCount() const { throw ScriptError( _("Can't convert from ")+typeName()+_(" to collection")); }
void ScriptValue::signalDependent(Context&, const Dependency&, const String& name) {}
ScriptValueP ScriptValue::dependencies(Context&, const Dependency&) const { return dependency_dummy; }
ScriptValueP ScriptValue::dependencyMember(const String& name, const Dependency&) const { return dependency_dummy; }
ScriptValueP ScriptValue::dependencies(Context&, const Dependency&) const { return dependency_dummy; }
// ----------------------------------------------------------------------------- : Iterators
@@ -167,6 +167,15 @@ class ScriptString : public ScriptValue {
}
}
virtual int itemCount() const { return (int)value.size(); }
virtual ScriptValueP getMember(const String& name) const {
// get member returns characters
long index;
if (name.ToLong(&index) && index >= 0 && (size_t)index < value.size()) {
return toScript(String(1,value[index]));
} else {
throw ScriptError(_("String \"") + value + _("\" has no member ") + name);
}
}
private:
String value;
};