// printf support #include // my object's header #include "ScriptedObject.h" ScriptedObject::ScriptedObject(skString fileName, int my_param) : skScriptedExecutable(fileName) { const char *szFile = fileName; printf(" object id %i constructed, associated with script \"%s\"\n", my_param, szFile); // assign the instance parameter m_param = my_param; } // returns a field's value bool ScriptedObject::getValue(const skString& fieldName, const skString& attribute, skRValue& value) { // does it match our member variable? if (fieldName == "m_param") { // copy the value value = m_param; // we found the variable return true; } else { // make sure to call the base class method if we don't control this variable return skScriptedExecutable::getValue(fieldName, attribute, value); } } // sets a field's value bool ScriptedObject::setValue(const skString& fieldName, const skString& attribute, const skRValue& value) { // does it match our member variable? if (fieldName == "m_param") { // assign the new value m_param = value.intValue(); // display information about the assignment printf(" m_param has been assigned the value %i\n", m_param); // we found the variable return true; } else { // make sure to call the base class method if we don't control this variable return skScriptedExecutable::setValue(fieldName, attribute, value); } } // calls a method in this object bool ScriptedObject::method(const skString& methodName, skRValueArray& arguments,skRValue& returnValue) { // see if this is out exported method "foo' if (IS_METHOD(methodName, "foo")) { // foo(arguments[0].intValue()); skRValue param = arguments[0]; foo(param.intValue()); return true; } else { // make sure to call the base class method if we don't control this method return skScriptedExecutable::method(methodName, arguments, returnValue); } } void ScriptedObject::foo(int p) { printf(" foo! %i\n", p); }