Pārlūkot izejas kodu

Cleaned up lua sample.
Fixed a couple issues in scripting code.

sgrenier 11 gadi atpakaļ
vecāks
revīzija
e0407ca4d9

+ 29 - 0
gameplay/src/Game.cpp

@@ -192,6 +192,35 @@ bool Game::startup()
             _scriptTarget = new GameScriptTarget();
             _scriptTarget->addScript(scriptPath, Script::GLOBAL);
         }
+        else
+        {
+            // Use the older scripts namespace for loading individual script callback functions
+            Properties* sns = _properties->getNamespace("scripts", true);
+            if (sns)
+            {
+                _scriptTarget = new GameScriptTarget();
+
+                // Define a macro to simplify defining the following script callback registrations
+                #define GP_REG_GAME_SCRIPT_CB(e) if (sns->exists(#e)) _scriptTarget->addScriptCallback(GP_GET_SCRIPT_EVENT(GameScriptTarget, e), sns->getString(#e))
+
+                // Register all supported script callbacks if they are defined
+                GP_REG_GAME_SCRIPT_CB(initialize);
+                GP_REG_GAME_SCRIPT_CB(finalize);
+                GP_REG_GAME_SCRIPT_CB(update);
+                GP_REG_GAME_SCRIPT_CB(render);
+                GP_REG_GAME_SCRIPT_CB(resizeEvent);
+                GP_REG_GAME_SCRIPT_CB(keyEvent);
+                GP_REG_GAME_SCRIPT_CB(touchEvent);
+                GP_REG_GAME_SCRIPT_CB(mouseEvent);
+                GP_REG_GAME_SCRIPT_CB(gestureSwipeEvent);
+                GP_REG_GAME_SCRIPT_CB(gesturePinchEvent);
+                GP_REG_GAME_SCRIPT_CB(gestureTapEvent);
+                GP_REG_GAME_SCRIPT_CB(gestureLongTapevent);
+                GP_REG_GAME_SCRIPT_CB(gestureDragEvent);
+                GP_REG_GAME_SCRIPT_CB(gestureDropEvent);
+                GP_REG_GAME_SCRIPT_CB(gamepadEvent);
+            }
+        }
     }
 
     _state = RUNNING;

+ 16 - 32
gameplay/src/ScriptTarget.cpp

@@ -131,18 +131,6 @@ Script* ScriptTarget::addScript(const char* path, Script::Scope scope)
     if (!script)
         return NULL;
 
-    // For non-global scripts, automatically call the 'attached' event if it is defined
-    // within the script
-    if (scope != Script::GLOBAL)
-    {
-        if (sc->functionExists("attached", script))
-        {
-            char args[256];
-            sprintf(args, "<%s>", getTypeName());
-            sc->executeFunction<void>(script, "attached", args, dynamic_cast<void*>(this));
-        }
-    }
-
     // Attach the script
     ScriptEntry* se = new ScriptEntry(script);
     if (_scripts)
@@ -177,6 +165,18 @@ Script* ScriptTarget::addScript(const char* path, Script::Scope scope)
         re = re->next;
     }
 
+    // For non-global scripts, automatically call the 'attached' event if it is defined
+    // within the script
+    if (scope != Script::GLOBAL)
+    {
+        if (sc->functionExists("attached", script))
+        {
+            char args[256];
+            sprintf(args, "<%s>", getTypeName());
+            sc->executeFunction<void>(script, "attached", args, dynamic_cast<void*>(this));
+        }
+    }
+
     return script;
 }
 
@@ -237,27 +237,11 @@ void ScriptTarget::removeScript(ScriptEntry* se)
     SAFE_RELEASE(script);
 }
 
-void ScriptTarget::addScriptCallback(const char* eventName, const char* function)
+void ScriptTarget::addScriptCallback(const Event* event, const char* function)
 {
-    GP_ASSERT(eventName);
+    GP_ASSERT(event);
     GP_ASSERT(function);
 
-    // Lookup the specified event
-    const Event* event = NULL;
-    RegistryEntry* re = _scriptRegistries;
-    while (re)
-    {
-        if ((event = re->registry->getEvent(eventName)) != NULL)
-            break;
-        re = re->next;
-    }
-
-    if (event == NULL)
-    {
-        GP_WARN("No event named '%s' found for script target while registering function: %s", eventName, function);
-        return;
-    }
-
     // Parse the script name (if it exists) and function out
     std::string scriptPath, func;
     splitURL(function, &scriptPath, &func);
@@ -324,7 +308,7 @@ void ScriptTarget::addScriptCallback(const char* eventName, const char* function
     }
 }
 
-void ScriptTarget::removeScriptCallback(const char* eventName, const char* function)
+void ScriptTarget::removeScriptCallback(const Event* event, const char* function)
 {
     // Parse the script name (if it exists) and function out
     std::string scriptPath, func;
@@ -362,7 +346,7 @@ void ScriptTarget::removeScriptCallback(const char* eventName, const char* funct
         for (; itr != _scriptCallbacks->end(); ++itr)
         {
             // Erase matching callback functions for this event
-            bool forEvent = itr->first->name == eventName;
+            bool forEvent = itr->first == event;
             std::vector<CallbackFunction>& callbacks = itr->second;
             std::vector<CallbackFunction>::iterator itr2 = callbacks.begin();
             while (itr2 != callbacks.end())

+ 4 - 4
gameplay/src/ScriptTarget.h

@@ -252,20 +252,20 @@ public:
     /**
      * Adds the given global script function as a callback for the given event.
      * 
-     * @param eventName The name of the event.
+     * @param event The event to add the callback for.
      * @param function The name of the script function to call when the event is fired; can either be
      *  just the name of a function (if the function's script file has already been loaded), or can be
      *  a URL of the form scriptFile.lua#functionName.
      */
-    void addScriptCallback(const char* eventName, const char* function);
+    void addScriptCallback(const Event* event, const char* function);
 
     /**
      * Removes the given script function as a callback for the given event.
      * 
-     * @param eventName The name of the event.
+     * @param event The event to remove the callback for.
      * @param function The name of the script function.
      */
-    void removeScriptCallback(const char* eventName, const char* function);
+    void removeScriptCallback(const Event* event, const char* function);
 
     /**
      *  Removes all scripts and callbacks from this object.

+ 16 - 4
gameplay/src/lua/lua_AnimationClip.cpp

@@ -368,11 +368,17 @@ int lua_AnimationClip_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -1317,11 +1323,17 @@ int lua_AnimationClip_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_Button.cpp

@@ -361,11 +361,17 @@ int lua_Button_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -3380,11 +3386,17 @@ int lua_Button_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_CheckBox.cpp

@@ -365,11 +365,17 @@ int lua_CheckBox_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -3454,11 +3460,17 @@ int lua_CheckBox_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_Container.cpp

@@ -442,11 +442,17 @@ int lua_Container_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -4108,11 +4114,17 @@ int lua_Container_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_Control.cpp

@@ -356,11 +356,17 @@ int lua_Control_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -3375,11 +3381,17 @@ int lua_Control_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_Form.cpp

@@ -452,11 +452,17 @@ int lua_Form_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -4188,11 +4194,17 @@ int lua_Form_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_ImageControl.cpp

@@ -363,11 +363,17 @@ int lua_ImageControl_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -3470,11 +3476,17 @@ int lua_ImageControl_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_Joint.cpp

@@ -465,11 +465,17 @@ int lua_Joint_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -4333,11 +4339,17 @@ int lua_Joint_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_JoystickControl.cpp

@@ -366,11 +366,17 @@ int lua_JoystickControl_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -3587,11 +3593,17 @@ int lua_JoystickControl_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_Label.cpp

@@ -360,11 +360,17 @@ int lua_Label_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -3414,11 +3420,17 @@ int lua_Label_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_Node.cpp

@@ -464,11 +464,17 @@ int lua_Node_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -4288,11 +4294,17 @@ int lua_Node_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_PhysicsController.cpp

@@ -147,11 +147,17 @@ int lua_PhysicsController_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -1743,11 +1749,17 @@ int lua_PhysicsController_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_RadioButton.cpp

@@ -367,11 +367,17 @@ int lua_RadioButton_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -3491,11 +3497,17 @@ int lua_RadioButton_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_ScriptTarget.cpp

@@ -128,11 +128,17 @@ int lua_ScriptTarget_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -341,11 +347,17 @@ int lua_ScriptTarget_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_Slider.cpp

@@ -375,11 +375,17 @@ int lua_Slider_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -3674,11 +3680,17 @@ int lua_Slider_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_TextBox.cpp

@@ -368,11 +368,17 @@ int lua_TextBox_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -3562,11 +3568,17 @@ int lua_TextBox_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 16 - 4
gameplay/src/lua/lua_Transform.cpp

@@ -478,11 +478,17 @@ int lua_Transform_addScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);
@@ -2248,11 +2254,17 @@ int lua_Transform_removeScriptCallback(lua_State* state)
         case 3:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<ScriptTarget::Event> param1 = gameplay::ScriptUtil::getObjectPointer<ScriptTarget::Event>(2, "ScriptTargetEvent", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'ScriptTarget::Event'.");
+                    lua_error(state);
+                }
 
                 // Get parameter 2 off the stack.
                 const char* param2 = gameplay::ScriptUtil::getString(3, false);

+ 0 - 10
samples/lua/game.config

@@ -7,13 +7,3 @@ window
 }
 
 script = res/game.lua
-
-scripts
-{
-    initialize = res/game.lua#initialize
-    update = res/game.lua#update
-    render = res/game.lua#render
-    finalize = res/game.lua#finalize
-    keyEvent = res/game.lua#keyEvent
-    touchEvent = res/game.lua#touchEvent
-}

+ 52 - 68
samples/lua/res/ai.lua

@@ -1,84 +1,68 @@
--- Create an AIAgent for the box
-_modelNode:setAgent(AIAgent.create())
 
--- Store state machine for agent
-_stateMachine = _modelNode:getAgent():getStateMachine()
+local this = nil
+local animations = { }
 
--- Register AI states
-stateIdle = _stateMachine:addState("idle")
+function attached(node)
+    this = node
 
-stateSpinning = _stateMachine:addState("spinning")
-stateSpinning:addScriptCallback("update", "spinningUpdate")
+    -- Create an AIAgent for the box
+    node:setAgent(AIAgent.create())
 
-stateSpinning = _stateMachine:addState("sliding")
-stateSpinning:addScriptCallback("enter", "slidingEnter")
-stateSpinning:addScriptCallback("exit", "slidingExit")
+    -- Get state machine
+    local stateMachine = node:getAgent():getStateMachine()
 
-stateBouncing = _stateMachine:addState("bouncing")
-stateBouncing:addScriptCallback("enter", "bouncingEnter")
-stateBouncing:addScriptCallback("exit", "bouncingExit")
+    -- Register AI states
+    stateMachine:addState("idle")
+    stateMachine:addState("spin")
+    stateMachine:addState("slide")
+    stateMachine:addState("bounce")
+    stateMachine:addState("scale")
 
-stateScale = _stateMachine:addState("scale")
-stateScale:addScriptCallback("enter", "scaleEnter")
-stateScale:addScriptCallback("exit", "scaleExit")
+    -- Set initial state
+    stateMachine:setState("spin")
 
--- Set initial state
-_stateMachine:setState("spinning")
-
--- Create animations
-_slidingClip = _modelNode:createAnimation("sliding", Transform.ANIMATE_TRANSLATE(), 6, { 0, 250, 750, 1250, 1750, 2000 }, { 0,0,0, 2,0,0, 2,0,-4, -2,0,-4, -2,0,0, 0,0,0 }, Curve.LINEAR):getClip()
-_slidingClip:setRepeatCount(AnimationClip.REPEAT_INDEFINITE())
-_bouncingClip = _modelNode:createAnimation("bouncing", Transform.ANIMATE_TRANSLATE_Y(), 3, { 0, 500, 1000 }, { 0, 0.75, 0 }, Curve.CUBIC_IN_OUT):getClip()
-_bouncingClip:setRepeatCount(AnimationClip.REPEAT_INDEFINITE())
-_scaleClip = _modelNode:createAnimation("scale", Transform.ANIMATE_SCALE(), 3, { 0, 750, 1500 }, { 1,1,1, 2,2,2, 1,1,1 }, Curve.QUADRATIC_IN_OUT):getClip()
-_scaleClip:setRepeatCount(AnimationClip.REPEAT_INDEFINITE())
-
--- Called by game.lua to toggle AI state
-function toggleState()
-    local state = _stateMachine:getActiveState():getId()
-    if state == "spinning" then
-        _stateMachine:setState("sliding")
-    elseif state == "sliding" then
-        _stateMachine:setState("bouncing")
-    elseif state == "bouncing" then
-        _stateMachine:setState("scale")
-    elseif state == "scale" then
-        _stateMachine:setState("idle")
-    elseif state == "idle" then
-        _stateMachine:setState("spinning")
-    end
+    -- Create animations, storing them in a table keyed on state name
+    animations["slide"] = node:createAnimation("slide", Transform.ANIMATE_TRANSLATE(), 6, { 0, 250, 750, 1250, 1750, 2000 }, { 0,0,0, 2,0,0, 2,0,-4, -2,0,-4, -2,0,0, 0,0,0 }, Curve.LINEAR):getClip()
+    animations["slide"]:setRepeatCount(AnimationClip.REPEAT_INDEFINITE())
+    animations["bounce"] = node:createAnimation("bounce", Transform.ANIMATE_TRANSLATE_Y(), 3, { 0, 500, 1000 }, { 0, 0.75, 0 }, Curve.CUBIC_IN_OUT):getClip()
+    animations["bounce"]:setRepeatCount(AnimationClip.REPEAT_INDEFINITE())
+    animations["scale"] = node:createAnimation("scale", Transform.ANIMATE_SCALE(), 3, { 0, 750, 1500 }, { 1,1,1, 2,2,2, 1,1,1 }, Curve.QUADRATIC_IN_OUT):getClip()
+    animations["scale"]:setRepeatCount(AnimationClip.REPEAT_INDEFINITE())
 end
 
--- SPINNING state handlers
-function spinningUpdate(agent, state, elapsedTime)
-    _modelNode:rotateY(elapsedTime * math.rad(0.05))
-end
-
--- SLIDING state handlers
-function slidingEnter(agent, state)
-    _slidingClip:play()
-end
-
-function slidingExit(agent, state)
-    _slidingClip:pause()
-end
-
--- BOUNCING state handlers
-function bouncingEnter(agent, state)
-    _bouncingClip:play()
+function stateEnter(node, state)
+    local clip = animations[state:getId()]
+    if clip then
+        clip:play()
+    end
 end
 
-function bouncingExit(agent, state)
-    _bouncingClip:pause()
+function stateExit(node, state)
+    local clip = animations[state:getId()]
+    if clip then
+        clip:pause()
+    end
 end
 
--- SCALE state handlers
-function scaleEnter(agent, state)
-    _scaleClip:play()
+function stateUpdate(node, state, t)
+    if state:getId() == "spin" then
+        node:rotateY(t * math.rad(0.05))
+    end
 end
 
-function scaleExit(agent, state)
-    _scaleClip:pause()
+-- Put into the global table so it can be called by game.lua to toggle AI state
+function _G.toggleState()
+    local stateMachine = this:getAgent():getStateMachine()
+    local state = stateMachine:getActiveState():getId()
+    if state == "spin" then
+        stateMachine:setState("slide")
+    elseif state == "slide" then
+        stateMachine:setState("bounce")
+    elseif state == "bounce" then
+        stateMachine:setState("scale")
+    elseif state == "scale" then
+        stateMachine:setState("idle")
+    elseif state == "idle" then
+        stateMachine:setState("spin")
+    end
 end
-
-

+ 11 - 9
samples/lua/res/game.lua

@@ -1,6 +1,11 @@
--- This lua script file represents a lua implementation translation of sample00-mesh with a box instead of a duck.
+
+-- Allocate objects to void creating each frame
+local textColor = Vector4.new(0, 0.5, 1, 1)
 
 function initialize()
+
+    Game.setVsync(false)
+
     -- Display splash screen for at least 1 second.
     ScreenDisplayer.start("drawSplash", 1000)
 
@@ -31,18 +36,15 @@ function initialize()
     local model = createGridModel()
     _scene:addNode("grid"):setModel(model)
 
-    dofile("res/ai.lua")
-
     ScreenDisplayer.finish()
 end
 
-function update(elapsedTime)
+function update(t)
+    -- Uncomment the line below to force a more stable and deterministic frame rate, to prevent occassional large garbage collections
+    --collectgarbage()
 end
 
--- Avoid allocating new objects every frame.
-textColor = Vector4.new(0, 0.5, 1, 1)
-
-function render(elapsedTime)
+function render()
     -- Clear the color and depth buffers.
     Game.getInstance():clear(Game.CLEAR_COLOR_DEPTH, Vector4.zero(), 1.0, 0)
 
@@ -50,7 +52,7 @@ function render(elapsedTime)
     _scene:visit("drawScene")
 
     -- Draw the fps.
-    local buffer = string.format("%u\n%s", Game.getInstance():getFrameRate(), _stateMachine:getActiveState():getId())
+    local buffer = string.format("%u\n%s", Game.getInstance():getFrameRate(), _modelNode:getAgent():getStateMachine():getActiveState():getId())
     _font:start()
     _font:drawText(buffer, 5, 1, textColor, _font:getSize())
     _font:finish()

+ 1 - 0
samples/lua/res/lua.scene

@@ -5,5 +5,6 @@ scene
     node box
     {
         material = res/lua.material
+        script = res/ai.lua
     }
 }