Browse Source

Clean-up and bug fixes to Lua bindings:
- Fixed a regression introduced in v3.0 that could cause a Lua stack leak, causing eventual crash in some Lua-based games.
- Fixed a number of problematic and potentially unsafe Lua usage scenarios, where passing a subclass object to a function that expects a base class could cause a crash. This fix was accomplished by adding support for automatic and safe conversion between base classes and subclasses (and vice-versa) when passing objects from Lua to C++.
- Removed the global 'convert' Lua function since it was unsafe. Instead, when manual object casting is required in Lua, such as when needing to convert a base class to a known subclass to access subclass-specific interfaces, the Lua bindings now support a safe 'to(type)' function on all polymorphic classes.
- When using the new built-in 'to(type)' conversion function, nil will be returned if no suitable conversion exists. Similarly, when attempting to pass an incompatible object type to a Lua C++ function, the function will gracefully fail and log a script error.

Steve Grenier 10 years ago
parent
commit
f13282ebba
100 changed files with 3872 additions and 4466 deletions
  1. 2 1
      gameplay/src/Base.h
  2. 5 0
      gameplay/src/Joint.cpp
  3. 8 0
      gameplay/src/Joint.h
  4. 1 1
      gameplay/src/Logger.cpp
  5. 1 0
      gameplay/src/PhysicsCollisionObject.cpp
  6. 2 1
      gameplay/src/Scene.cpp
  7. 200 151
      gameplay/src/ScriptController.cpp
  8. 123 104
      gameplay/src/ScriptController.h
  9. 48 143
      gameplay/src/ScriptController.inl
  10. 5 5
      gameplay/src/ScriptTarget.cpp
  11. 1 1
      gameplay/src/Terrain.h
  12. 85 35
      gameplay/src/lua/lua_AIAgent.cpp
  13. 0 13
      gameplay/src/lua/lua_AIAgent.h
  14. 17 16
      gameplay/src/lua/lua_AIAgentListener.cpp
  15. 0 4
      gameplay/src/lua/lua_AIAgentListener.h
  16. 17 16
      gameplay/src/lua/lua_AIController.cpp
  17. 0 4
      gameplay/src/lua/lua_AIController.h
  18. 54 53
      gameplay/src/lua/lua_AIMessage.cpp
  19. 0 21
      gameplay/src/lua/lua_AIMessage.h
  20. 77 27
      gameplay/src/lua/lua_AIState.cpp
  21. 0 9
      gameplay/src/lua/lua_AIState.h
  22. 22 21
      gameplay/src/lua/lua_AIStateListener.cpp
  23. 0 7
      gameplay/src/lua/lua_AIStateListener.h
  24. 25 24
      gameplay/src/lua/lua_AIStateMachine.cpp
  25. 0 8
      gameplay/src/lua/lua_AIStateMachine.h
  26. 70 20
      gameplay/src/lua/lua_AbsoluteLayout.cpp
  27. 0 7
      gameplay/src/lua/lua_AbsoluteLayout.h
  28. 88 38
      gameplay/src/lua/lua_Animation.cpp
  29. 0 16
      gameplay/src/lua/lua_Animation.h
  30. 148 93
      gameplay/src/lua/lua_AnimationClip.cpp
  31. 0 42
      gameplay/src/lua/lua_AnimationClip.h
  32. 17 16
      gameplay/src/lua/lua_AnimationClipListener.cpp
  33. 0 4
      gameplay/src/lua/lua_AnimationClipListener.h
  34. 15 14
      gameplay/src/lua/lua_AnimationController.cpp
  35. 0 3
      gameplay/src/lua/lua_AnimationController.h
  36. 112 27
      gameplay/src/lua/lua_AnimationTarget.cpp
  37. 0 10
      gameplay/src/lua/lua_AnimationTarget.h
  38. 21 20
      gameplay/src/lua/lua_AnimationValue.cpp
  39. 0 6
      gameplay/src/lua/lua_AnimationValue.h
  40. 68 18
      gameplay/src/lua/lua_AudioBuffer.cpp
  41. 0 6
      gameplay/src/lua/lua_AudioBuffer.h
  42. 14 13
      gameplay/src/lua/lua_AudioController.cpp
  43. 0 3
      gameplay/src/lua/lua_AudioController.h
  44. 88 38
      gameplay/src/lua/lua_AudioListener.cpp
  45. 0 14
      gameplay/src/lua/lua_AudioListener.h
  46. 110 55
      gameplay/src/lua/lua_AudioSource.cpp
  47. 0 23
      gameplay/src/lua/lua_AudioSource.h
  48. 38 37
      gameplay/src/lua/lua_BoundingBox.cpp
  49. 0 14
      gameplay/src/lua/lua_BoundingBox.h
  50. 34 33
      gameplay/src/lua/lua_BoundingSphere.cpp
  51. 0 12
      gameplay/src/lua/lua_BoundingSphere.h
  52. 91 41
      gameplay/src/lua/lua_Bundle.cpp
  53. 0 16
      gameplay/src/lua/lua_Bundle.h
  54. 101 220
      gameplay/src/lua/lua_Button.cpp
  55. 0 114
      gameplay/src/lua/lua_Button.h
  56. 138 81
      gameplay/src/lua/lua_Camera.cpp
  57. 0 36
      gameplay/src/lua/lua_Camera.h
  58. 72 15
      gameplay/src/lua/lua_CameraListener.cpp
  59. 0 4
      gameplay/src/lua/lua_CameraListener.h
  60. 98 224
      gameplay/src/lua/lua_CheckBox.cpp
  61. 0 117
      gameplay/src/lua/lua_CheckBox.h
  62. 96 243
      gameplay/src/lua/lua_Container.cpp
  63. 0 139
      gameplay/src/lua/lua_Container.h
  64. 111 217
      gameplay/src/lua/lua_Control.cpp
  65. 0 112
      gameplay/src/lua/lua_Control.h
  66. 26 16
      gameplay/src/lua/lua_ControlListener.cpp
  67. 0 4
      gameplay/src/lua/lua_ControlListener.h
  68. 95 45
      gameplay/src/lua/lua_Curve.cpp
  69. 0 18
      gameplay/src/lua/lua_Curve.h
  70. 85 35
      gameplay/src/lua/lua_DepthStencilTarget.cpp
  71. 0 13
      gameplay/src/lua/lua_DepthStencilTarget.h
  72. 103 16
      gameplay/src/lua/lua_Drawable.cpp
  73. 0 5
      gameplay/src/lua/lua_Drawable.h
  74. 89 39
      gameplay/src/lua/lua_Effect.cpp
  75. 0 15
      gameplay/src/lua/lua_Effect.h
  76. 41 40
      gameplay/src/lua/lua_FileSystem.cpp
  77. 0 15
      gameplay/src/lua/lua_FileSystem.h
  78. 76 26
      gameplay/src/lua/lua_FlowLayout.cpp
  79. 0 10
      gameplay/src/lua/lua_FlowLayout.h
  80. 101 51
      gameplay/src/lua/lua_Font.cpp
  81. 0 21
      gameplay/src/lua/lua_Font.h
  82. 95 251
      gameplay/src/lua/lua_Form.cpp
  83. 0 148
      gameplay/src/lua/lua_Form.h
  84. 211 58
      gameplay/src/lua/lua_FrameBuffer.cpp
  85. 0 23
      gameplay/src/lua/lua_FrameBuffer.h
  86. 39 38
      gameplay/src/lua/lua_Frustum.cpp
  87. 0 16
      gameplay/src/lua/lua_Frustum.h
  88. 138 137
      gameplay/src/lua/lua_Game.cpp
  89. 0 64
      gameplay/src/lua/lua_Game.h
  90. 35 34
      gameplay/src/lua/lua_Gamepad.cpp
  91. 0 13
      gameplay/src/lua/lua_Gamepad.h
  92. 25 24
      gameplay/src/lua/lua_Gesture.cpp
  93. 0 7
      gameplay/src/lua/lua_Gesture.h
  94. 224 146
      gameplay/src/lua/lua_Global.cpp
  95. 4 0
      gameplay/src/lua/lua_Global.h
  96. 85 35
      gameplay/src/lua/lua_HeightField.cpp
  97. 0 13
      gameplay/src/lua/lua_HeightField.h
  98. 79 29
      gameplay/src/lua/lua_Image.cpp
  99. 0 10
      gameplay/src/lua/lua_Image.h
  100. 98 225
      gameplay/src/lua/lua_ImageControl.cpp

+ 2 - 1
gameplay/src/Base.h

@@ -22,6 +22,7 @@
 #include <set>
 #include <stack>
 #include <map>
+#include <unordered_map>
 #include <queue>
 #include <algorithm>
 #include <limits>
@@ -116,7 +117,7 @@ extern int strcmpnocase(const char* s1, const char* s2);
     #pragma warning( disable : 4244 )
     #pragma warning( disable : 4267 )
     #pragma warning( disable : 4311 )
-	#pragma warning( disable : 4316 )
+    #pragma warning( disable : 4316 )
     #pragma warning( disable : 4390 )
     #pragma warning( disable : 4800 )
     #pragma warning( disable : 4996 )

+ 5 - 0
gameplay/src/Joint.cpp

@@ -35,6 +35,11 @@ Node::Type Joint::getType() const
     return Node::JOINT;
 }
 
+const char* Joint::getTypeName() const
+{
+    return "Joint";
+}
+
 Scene* Joint::getScene() const
 {
     // Overrides Node::getScene() to search the node our skins.

+ 8 - 0
gameplay/src/Joint.h

@@ -34,6 +34,14 @@ public:
      */
     Scene* getScene() const;
 
+    /**
+     * Extends ScriptTarget::getTypeName() to return the type name of this class.
+     *
+     * @return The type name of this class: "Joint"
+     * @see ScriptTarget::getTypeName()
+     */
+    const char* getTypeName() const;
+
     /**
      * Returns the inverse bind pose matrix for this joint.
      * 

+ 1 - 1
gameplay/src/Logger.cpp

@@ -65,7 +65,7 @@ void Logger::log(Level level, const char* message, ...)
     else if (state.logFunctionLua)
     {
         // Pass call to registered Lua log function
-        Game::getInstance()->getScriptController()->executeFunction<void>(state.logFunctionLua, "[Logger::Level]s", level, str);
+        Game::getInstance()->getScriptController()->executeFunction<void>(state.logFunctionLua, "[Logger::Level]s", NULL, level, str);
     }
     else
     {

+ 1 - 0
gameplay/src/PhysicsCollisionObject.cpp

@@ -325,6 +325,7 @@ void PhysicsCollisionObject::ScriptListener::collisionEvent(PhysicsCollisionObje
 {
     Game::getInstance()->getScriptController()->executeFunction<void>(function.c_str(), 
         "[PhysicsCollisionObject::CollisionListener::EventType]<PhysicsCollisionObject::CollisionPair><Vector3><Vector3>",
+        NULL,
         type, &collisionPair, &contactPointA, &contactPointB);
 }
 

+ 2 - 1
gameplay/src/Scene.cpp

@@ -200,7 +200,8 @@ void Scene::visitNode(Node* node, const char* visitMethod)
     ScriptController* sc = Game::getInstance()->getScriptController();
 
     // Invoke the visit method for this node.
-    if (!sc->executeFunction<bool>(visitMethod, "<Node>", dynamic_cast<void*>(node)))
+    bool result;
+    if (!sc->executeFunction<bool>(visitMethod, "<Node>", &result, (void*)node) || !result)
         return;
 
     // If this node has a model with a mesh skin, visit the joint hierarchy within it

+ 200 - 151
gameplay/src/ScriptController.cpp

@@ -4,6 +4,14 @@
 
 #ifndef GP_NO_LUA_BINDINGS
 #include "lua/lua_all_bindings.h"
+#else
+// Need to define global functions expoed by lua bindings that are used by ScriptController
+#define luaConvertObjectPointer(ptr, fromType, toType) NULL
+static const std::vector<std::string>& luaGetClassRelatives(const char* type)
+{
+    static std::vector<std::string> empty;
+    return empty;
+}
 #endif
 
 #define GENERATE_LUA_GET_POINTER(type, checkFunc) \
@@ -410,9 +418,9 @@ const char* ScriptController::getString(const char* name, Script* script)
 void* ScriptController::getObjectPointer(const char* type, const char* name, Script* script)
 {
     PUSH_NESTED_VARIABLE(name, NULL, script);
-    void* userData = lua_isuserdata(_lua, -1) ? luaL_checkudata(_lua, -1, type) : NULL;
+    void* ptr = lua_islightuserdata(_lua, -1) ? lua_touserdata(_lua, -1) : ScriptUtil::getUserDataObjectPointer(-1, type);
     POP_NESTED_VARIABLE();
-    return ((ScriptUtil::LuaObject*)userData)->instance;
+    return ptr;
 }
 
 void ScriptController::setBool(const char* name, bool v, Script* script)
@@ -718,7 +726,6 @@ void ScriptController::initialize()
 
 #ifndef GP_NO_LUA_BINDINGS
     lua_RegisterAllBindings();
-    ScriptUtil::registerFunction("convert", ScriptController::convert);
 #endif
 
     // Append to the LUA_PATH to allow scripts to be found in the resource folder on all platforms
@@ -762,7 +769,7 @@ void ScriptController::finalize()
     _timeListeners.clear();
 
     if (_lua)
-	{
+    {
         // Perform a full garbage collection cycle.
         // Note that this does NOT free any global variables declared in scripts, since 
         // they are stored in the global state and are still referenced. Only after 
@@ -770,19 +777,19 @@ void ScriptController::finalize()
         lua_gc(_lua, LUA_GCCOLLECT, 0);
 
         lua_close(_lua);
-		_lua = NULL;
-	}
+        _lua = NULL;
+    }
 }
 
-void ScriptController::executeFunctionHelper(int resultCount, const char* func, const char* args, va_list* list, Script* script)
+bool ScriptController::executeFunctionHelper(int resultCount, const char* func, const char* args, va_list* list, Script* script)
 {
-	if (!_lua)
-		return; // handles calling this method after script is finalized
+    if (!_lua)
+        return false; // handles calling this method after script is finalized
 
     if (func == NULL)
     {
         GP_ERROR("Lua function name must be non-null.");
-        return;
+        return false;
     }
 
     // If script was not specified and we are currently executing another function,
@@ -799,7 +806,7 @@ void ScriptController::executeFunctionHelper(int resultCount, const char* func,
     if (!getNestedVariable(_lua, func, env))
     {
         GP_WARN("Failed to call function '%s'", func);
-        return;
+        return false;
     }
 
     const char* sig = args;
@@ -905,45 +912,18 @@ void ScriptController::executeFunctionHelper(int resultCount, const char* func,
     pushScript(script);
 
     // Perform the function call.
-    if (lua_pcall(_lua, argumentCount, resultCount, 0) != 0)
+    // This will push 'resultCount' values onto the stack if it succeeds.
+    // Otherwise (if it fails) it will push an error string onto the stack.
+    bool success = lua_pcall(_lua, argumentCount, resultCount, 0) == 0;
+    if (!success)
+    {
         GP_WARN("Failed to call function '%s' with error '%s'.", func, lua_tostring(_lua, -1));
+        lua_pop(_lua, 1); // pop the error
+    }
 
     popScript();
-}
-
-int ScriptController::convert(lua_State* state)
-{
-    // Get the number of parameters.
-    int paramCount = lua_gettop(state);
-    // Attempt to match the parameters to a valid binding.
-    switch (paramCount)
-    {
-        case 2:
-        {
-            if (lua_type(state, 1) == LUA_TUSERDATA && lua_type(state, 2) == LUA_TSTRING )
-            {
-                // Get parameter 2
-                const char* param2 = ScriptUtil::getString(2, false);
-                if (param2 != NULL)
-                {
-                    luaL_getmetatable(state, param2);
-                    lua_setmetatable(state, -3);
-                }
-                return 0;
-            }
 
-            lua_pushstring(state, "lua_convert - Failed to match the given parameters to a valid function signature.");
-            lua_error(state);
-            break;
-        }
-        default:
-        {
-            lua_pushstring(state, "Invalid number of parameters (expected 2).");
-            lua_error(state);
-            break;
-        }
-    }
-    return 0;
+    return success;
 }
 
 void ScriptController::schedule(float timeOffset, const char* function)
@@ -1003,7 +983,7 @@ void ScriptController::ScriptTimeListener::timeEvent(long timeDiff, void* cookie
         list.erase(itr);
 
     // Call the script function
-    Game::getInstance()->getScriptController()->executeFunction<void>(script, function.c_str(), "l", timeDiff);
+    Game::getInstance()->getScriptController()->executeFunction<void>(script, function.c_str(), "l", NULL, timeDiff);
 
     // Free ourself.
     // IMPORTANT: Don't do anything else after this line!!
@@ -1013,481 +993,490 @@ void ScriptController::ScriptTimeListener::timeEvent(long timeDiff, void* cookie
 // Helper macros.
 #define SCRIPT_EXECUTE_FUNCTION_NO_PARAM(script, type, checkfunc) \
     int top = lua_gettop(_lua); \
-    executeFunctionHelper(1, func, NULL, NULL, script); \
-    type value = (type)checkfunc(_lua, -1); \
-    lua_pop(_lua, -1); \
+    bool success = executeFunctionHelper(1, func, NULL, NULL, script); \
+    if (out && success) \
+        *out = (type)checkfunc(_lua, -1); \
     lua_settop(_lua, top); \
-    return value;
+    return success;
 
 #define SCRIPT_EXECUTE_FUNCTION_PARAM(script, type, checkfunc) \
     int top = lua_gettop(_lua); \
     va_list list; \
-    va_start(list, args); \
-    executeFunctionHelper(1, func, args, &list, script); \
-    type value = (type)checkfunc(_lua, -1); \
-    lua_pop(_lua, -1); \
+    va_start(list, out); \
+    bool success = executeFunctionHelper(1, func, args, &list, script); \
+    if (out && success) \
+        *out = (type)checkfunc(_lua, -1); \
     va_end(list); \
     lua_settop(_lua, top); \
-    return value;
+    return success;
 
 #define SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(script, type, checkfunc) \
     int top = lua_gettop(_lua); \
-    executeFunctionHelper(1, func, args, list, script); \
-    type value = (type)checkfunc(_lua, -1); \
-    lua_pop(_lua, -1); \
+    bool success = executeFunctionHelper(1, func, args, list, script); \
+    if (out && success) \
+        *out = (type)checkfunc(_lua, -1); \
     lua_settop(_lua, top); \
-    return value;
+    return success;
 
-template<> void ScriptController::executeFunction<void>(const char* func)
+template<> bool ScriptController::executeFunction<void>(const char* func, void* out)
 {
-    executeFunction<void>((Script*)NULL, func);
+    return executeFunction<void>((Script*)NULL, func, out);
 }
 
-template<> bool ScriptController::executeFunction<bool>(const char* func)
+template<> bool ScriptController::executeFunction<bool>(const char* func, bool* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(NULL, bool, ScriptUtil::luaCheckBool);
 }
 
-template<> char ScriptController::executeFunction<char>(const char* func)
+template<> bool ScriptController::executeFunction<char>(const char* func, char* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(NULL, char, luaL_checkint);
 }
 
-template<> short ScriptController::executeFunction<short>(const char* func)
+template<> bool ScriptController::executeFunction<short>(const char* func, short* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(NULL, short, luaL_checkint);
 }
 
-template<> int ScriptController::executeFunction<int>(const char* func)
+template<> bool ScriptController::executeFunction<int>(const char* func, int* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(NULL, int, luaL_checkint);
 }
 
-template<> long ScriptController::executeFunction<long>(const char* func)
+template<> bool ScriptController::executeFunction<long>(const char* func, long* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(NULL, long, luaL_checklong);
 }
 
-template<> unsigned char ScriptController::executeFunction<unsigned char>(const char* func)
+template<> bool ScriptController::executeFunction<unsigned char>(const char* func, unsigned char* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(NULL, unsigned char, luaL_checkunsigned);
 }
 
-template<> unsigned short ScriptController::executeFunction<unsigned short>(const char* func)
+template<> bool ScriptController::executeFunction<unsigned short>(const char* func, unsigned short* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(NULL, unsigned short, luaL_checkunsigned);
 }
 
-template<> unsigned int ScriptController::executeFunction<unsigned int>(const char* func)
+template<> bool ScriptController::executeFunction<unsigned int>(const char* func, unsigned int* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(NULL, unsigned int, luaL_checkunsigned);
 }
 
-template<> unsigned long ScriptController::executeFunction<unsigned long>(const char* func)
+template<> bool ScriptController::executeFunction<unsigned long>(const char* func, unsigned long* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(NULL, unsigned long, luaL_checkunsigned);
 }
 
-template<> float ScriptController::executeFunction<float>(const char* func)
+template<> bool ScriptController::executeFunction<float>(const char* func, float* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(NULL, float, luaL_checknumber);
 }
 
-template<> double ScriptController::executeFunction<double>(const char* func)
+template<> bool ScriptController::executeFunction<double>(const char* func, double* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(NULL, double, luaL_checknumber);
 }
 
-template<> std::string ScriptController::executeFunction<std::string>(const char* func)
+template<> bool ScriptController::executeFunction<std::string>(const char* func, std::string* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(NULL, std::string, luaL_checkstring);
 }
 
-template<> void ScriptController::executeFunction<void>(Script* script, const char* func)
+template<> bool ScriptController::executeFunction<void>(Script* script, const char* func, void* out)
 {
     int top = lua_gettop(_lua);
-    executeFunctionHelper(0, func, NULL, NULL, script);
+    bool success = executeFunctionHelper(0, func, NULL, NULL, script);
     lua_settop(_lua, top);
+    return success;
 }
 
-template<> bool ScriptController::executeFunction<bool>(Script* script, const char* func)
+template<> bool ScriptController::executeFunction<bool>(Script* script, const char* func, bool* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(script, bool, ScriptUtil::luaCheckBool);
 }
 
-template<> char ScriptController::executeFunction<char>(Script* script, const char* func)
+template<> bool ScriptController::executeFunction<char>(Script* script, const char* func, char* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(script, char, luaL_checkint);
 }
 
-template<> short ScriptController::executeFunction<short>(Script* script, const char* func)
+template<> bool ScriptController::executeFunction<short>(Script* script, const char* func, short* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(script, short, luaL_checkint);
 }
 
-template<> int ScriptController::executeFunction<int>(Script* script, const char* func)
+template<> bool ScriptController::executeFunction<int>(Script* script, const char* func, int* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(script, int, luaL_checkint);
 }
 
-template<> long ScriptController::executeFunction<long>(Script* script, const char* func)
+template<> bool ScriptController::executeFunction<long>(Script* script, const char* func, long* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(script, long, luaL_checklong);
 }
 
-template<> unsigned char ScriptController::executeFunction<unsigned char>(Script* script, const char* func)
+template<> bool ScriptController::executeFunction<unsigned char>(Script* script, const char* func, unsigned char* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(script, unsigned char, luaL_checkunsigned);
 }
 
-template<> unsigned short ScriptController::executeFunction<unsigned short>(Script* script, const char* func)
+template<> bool ScriptController::executeFunction<unsigned short>(Script* script, const char* func, unsigned short* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(script, unsigned short, luaL_checkunsigned);
 }
 
-template<> unsigned int ScriptController::executeFunction<unsigned int>(Script* script, const char* func)
+template<> bool ScriptController::executeFunction<unsigned int>(Script* script, const char* func, unsigned int* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(script, unsigned int, luaL_checkunsigned);
 }
 
-template<> unsigned long ScriptController::executeFunction<unsigned long>(Script* script, const char* func)
+template<> bool ScriptController::executeFunction<unsigned long>(Script* script, const char* func, unsigned long* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(script, unsigned long, luaL_checkunsigned);
 }
 
-template<> float ScriptController::executeFunction<float>(Script* script, const char* func)
+template<> bool ScriptController::executeFunction<float>(Script* script, const char* func, float* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(script, float, luaL_checknumber);
 }
 
-template<> double ScriptController::executeFunction<double>(Script* script, const char* func)
+template<> bool ScriptController::executeFunction<double>(Script* script, const char* func, double* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(script, double, luaL_checknumber);
 }
 
-template<> std::string ScriptController::executeFunction<std::string>(Script* script, const char* func)
+template<> bool ScriptController::executeFunction<std::string>(Script* script, const char* func, std::string* out)
 {
     SCRIPT_EXECUTE_FUNCTION_NO_PARAM(script, std::string, luaL_checkstring);
 }
 
 /** Template specialization. */
-template<> void ScriptController::executeFunction<void>(const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<void>(const char* func, const char* args, void* out, ...)
 {
     int top = lua_gettop(_lua);
     va_list list;
-    va_start(list, args);
-    executeFunctionHelper(0, func, args, &list, NULL);
+    va_start(list, out);
+    bool success = executeFunctionHelper(0, func, args, &list, NULL);
     va_end(list);
     lua_settop(_lua, top);
+    return success;
 }
 
 /** Template specialization. */
-template<> bool ScriptController::executeFunction<bool>(const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<bool>(const char* func, const char* args, bool* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(NULL, bool, ScriptUtil::luaCheckBool);
 }
 
 /** Template specialization. */
-template<> char ScriptController::executeFunction<char>(const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<char>(const char* func, const char* args, char* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(NULL, char, luaL_checkint);
 }
 
 /** Template specialization. */
-template<> short ScriptController::executeFunction<short>(const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<short>(const char* func, const char* args, short* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(NULL, short, luaL_checkint);
 }
 
 /** Template specialization. */
-template<> int ScriptController::executeFunction<int>(const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<int>(const char* func, const char* args, int* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(NULL, int, luaL_checkint);
 }
 
 /** Template specialization. */
-template<> long ScriptController::executeFunction<long>(const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<long>(const char* func, const char* args, long* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(NULL, long, luaL_checklong);
 }
 
 /** Template specialization. */
-template<> unsigned char ScriptController::executeFunction<unsigned char>(const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<unsigned char>(const char* func, const char* args, unsigned char* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(NULL, unsigned char, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> unsigned short ScriptController::executeFunction<unsigned short>(const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<unsigned short>(const char* func, const char* args, unsigned short* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(NULL, unsigned short, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> unsigned int ScriptController::executeFunction<unsigned int>(const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<unsigned int>(const char* func, const char* args, unsigned int* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(NULL, unsigned int, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> unsigned long ScriptController::executeFunction<unsigned long>(const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<unsigned long>(const char* func, const char* args, unsigned long* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(NULL, unsigned long, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> float ScriptController::executeFunction<float>(const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<float>(const char* func, const char* args, float* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(NULL, float, luaL_checknumber);
 }
 
 /** Template specialization. */
-template<> double ScriptController::executeFunction<double>(const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<double>(const char* func, const char* args, double* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(NULL, double, luaL_checknumber);
 }
 
 /** Template specialization. */
-template<> std::string ScriptController::executeFunction<std::string>(const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<std::string>(const char* func, const char* args, std::string* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(NULL, std::string, luaL_checkstring);
 }
 
 /** Template specialization. */
-template<> void ScriptController::executeFunction<void>(Script* script, const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<void>(Script* script, const char* func, const char* args, void* out, ...)
 {
     int top = lua_gettop(_lua);
     va_list list;
-    va_start(list, args);
-    executeFunctionHelper(0, func, args, &list, script);
+    va_start(list, out);
+    bool success = executeFunctionHelper(0, func, args, &list, script);
     va_end(list);
     lua_settop(_lua, top);
+    return success;
 }
 
 /** Template specialization. */
-template<> bool ScriptController::executeFunction<bool>(Script* script, const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<bool>(Script* script, const char* func, const char* args, bool* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(script, bool, ScriptUtil::luaCheckBool);
 }
 
 /** Template specialization. */
-template<> char ScriptController::executeFunction<char>(Script* script, const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<char>(Script* script, const char* func, const char* args, char* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(script, char, luaL_checkint);
 }
 
 /** Template specialization. */
-template<> short ScriptController::executeFunction<short>(Script* script, const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<short>(Script* script, const char* func, const char* args, short* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(script, short, luaL_checkint);
 }
 
 /** Template specialization. */
-template<> int ScriptController::executeFunction<int>(Script* script, const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<int>(Script* script, const char* func, const char* args, int* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(script, int, luaL_checkint);
 }
 
 /** Template specialization. */
-template<> long ScriptController::executeFunction<long>(Script* script, const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<long>(Script* script, const char* func, const char* args, long* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(script, long, luaL_checklong);
 }
 
 /** Template specialization. */
-template<> unsigned char ScriptController::executeFunction<unsigned char>(Script* script, const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<unsigned char>(Script* script, const char* func, const char* args, unsigned char* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(script, unsigned char, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> unsigned short ScriptController::executeFunction<unsigned short>(Script* script, const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<unsigned short>(Script* script, const char* func, const char* args, unsigned short* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(script, unsigned short, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> unsigned int ScriptController::executeFunction<unsigned int>(Script* script, const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<unsigned int>(Script* script, const char* func, const char* args, unsigned int* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(script, unsigned int, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> unsigned long ScriptController::executeFunction<unsigned long>(Script* script, const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<unsigned long>(Script* script, const char* func, const char* args, unsigned long* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(script, unsigned long, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> float ScriptController::executeFunction<float>(Script* script, const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<float>(Script* script, const char* func, const char* args, float* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(script, float, luaL_checknumber);
 }
 
 /** Template specialization. */
-template<> double ScriptController::executeFunction<double>(Script* script, const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<double>(Script* script, const char* func, const char* args, double* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(script, double, luaL_checknumber);
 }
 
 /** Template specialization. */
-template<> std::string ScriptController::executeFunction<std::string>(Script* script, const char* func, const char* args, ...)
+template<> bool ScriptController::executeFunction<std::string>(Script* script, const char* func, const char* args, std::string* out, ...)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM(script, std::string, luaL_checkstring);
 }
 
 /** Template specialization. */
-template<> void ScriptController::executeFunction<void>(const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<void>(const char* func, const char* args, void* out, va_list* list)
 {
-    executeFunctionHelper(0, func, args, list, NULL);
+    int top = lua_gettop(_lua);
+    bool success = executeFunctionHelper(0, func, args, list, NULL);
+    lua_settop(_lua, top);
+    return success;
 }
 
 /** Template specialization. */
-template<> bool ScriptController::executeFunction<bool>(const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<bool>(const char* func, const char* args, bool* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(NULL, bool, ScriptUtil::luaCheckBool);
 }
 
 /** Template specialization. */
-template<> char ScriptController::executeFunction<char>(const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<char>(const char* func, const char* args, char* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(NULL, char, luaL_checkint);
 }
 
 /** Template specialization. */
-template<> short ScriptController::executeFunction<short>(const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<short>(const char* func, const char* args, short* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(NULL, short, luaL_checkint);
 }
 
 /** Template specialization. */
-template<> int ScriptController::executeFunction<int>(const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<int>(const char* func, const char* args, int* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(NULL, int, luaL_checkint);
 }
 
 /** Template specialization. */
-template<> long ScriptController::executeFunction<long>(const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<long>(const char* func, const char* args, long* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(NULL, long, luaL_checklong);
 }
 
 /** Template specialization. */
-template<> unsigned char ScriptController::executeFunction<unsigned char>(const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<unsigned char>(const char* func, const char* args, unsigned char* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(NULL, unsigned char, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> unsigned short ScriptController::executeFunction<unsigned short>(const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<unsigned short>(const char* func, const char* args, unsigned short* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(NULL, unsigned short, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> unsigned int ScriptController::executeFunction<unsigned int>(const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<unsigned int>(const char* func, const char* args, unsigned int* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(NULL, unsigned int, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> unsigned long ScriptController::executeFunction<unsigned long>(const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<unsigned long>(const char* func, const char* args, unsigned long* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(NULL, unsigned long, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> float ScriptController::executeFunction<float>(const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<float>(const char* func, const char* args, float* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(NULL, float, luaL_checknumber);
 }
 
 /** Template specialization. */
-template<> double ScriptController::executeFunction<double>(const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<double>(const char* func, const char* args, double* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(NULL, double, luaL_checknumber);
 }
 
 /** Template specialization. */
-template<> std::string ScriptController::executeFunction<std::string>(const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<std::string>(const char* func, const char* args, std::string* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(NULL, std::string, luaL_checkstring);
 }
 
 /** Template specialization. */
-template<> void ScriptController::executeFunction<void>(Script* script, const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<void>(Script* script, const char* func, const char* args, void* out, va_list* list)
 {
-    executeFunctionHelper(0, func, args, list, script);
+    int top = lua_gettop(_lua);
+    bool success = executeFunctionHelper(0, func, args, list, script);
+    lua_settop(_lua, top);
+    return success;
 }
 
 /** Template specialization. */
-template<> bool ScriptController::executeFunction<bool>(Script* script, const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<bool>(Script* script, const char* func, const char* args, bool* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(script, bool, ScriptUtil::luaCheckBool);
 }
 
 /** Template specialization. */
-template<> char ScriptController::executeFunction<char>(Script* script, const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<char>(Script* script, const char* func, const char* args, char* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(script, char, luaL_checkint);
 }
 
 /** Template specialization. */
-template<> short ScriptController::executeFunction<short>(Script* script, const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<short>(Script* script, const char* func, const char* args, short* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(script, short, luaL_checkint);
 }
 
 /** Template specialization. */
-template<> int ScriptController::executeFunction<int>(Script* script, const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<int>(Script* script, const char* func, const char* args, int* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(script, int, luaL_checkint);
 }
 
 /** Template specialization. */
-template<> long ScriptController::executeFunction<long>(Script* script, const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<long>(Script* script, const char* func, const char* args, long* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(script, long, luaL_checklong);
 }
 
 /** Template specialization. */
-template<> unsigned char ScriptController::executeFunction<unsigned char>(Script* script, const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<unsigned char>(Script* script, const char* func, const char* args, unsigned char* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(script, unsigned char, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> unsigned short ScriptController::executeFunction<unsigned short>(Script* script, const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<unsigned short>(Script* script, const char* func, const char* args, unsigned short* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(script, unsigned short, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> unsigned int ScriptController::executeFunction<unsigned int>(Script* script, const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<unsigned int>(Script* script, const char* func, const char* args, unsigned int* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(script, unsigned int, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> unsigned long ScriptController::executeFunction<unsigned long>(Script* script, const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<unsigned long>(Script* script, const char* func, const char* args, unsigned long* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(script, unsigned long, luaL_checkunsigned);
 }
 
 /** Template specialization. */
-template<> float ScriptController::executeFunction<float>(Script* script, const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<float>(Script* script, const char* func, const char* args, float* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(script, float, luaL_checknumber);
 }
 
 /** Template specialization. */
-template<> double ScriptController::executeFunction<double>(Script* script, const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<double>(Script* script, const char* func, const char* args, double* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(script, double, luaL_checknumber);
 }
 
 /** Template specialization. */
-template<> std::string ScriptController::executeFunction<std::string>(Script* script, const char* func, const char* args, va_list* list)
+template<> bool ScriptController::executeFunction<std::string>(Script* script, const char* func, const char* args, std::string* out, va_list* list)
 {
     SCRIPT_EXECUTE_FUNCTION_PARAM_LIST(script, std::string, luaL_checkstring);
 }
@@ -1681,8 +1670,10 @@ void ScriptUtil::registerClass(const char* name, const luaL_Reg* members, lua_CF
     // Create the metatable and populate it with the member functions.
     lua_pushliteral(sc->_lua, "__metatable");
     luaL_newmetatable(sc->_lua, name);
+
     if (members)
         luaL_setfuncs(sc->_lua, members, 0);
+
     lua_pushstring(sc->_lua, "__index");
     lua_pushvalue(sc->_lua, -2);
     lua_settable(sc->_lua, -3);
@@ -1732,11 +1723,6 @@ void ScriptUtil::registerFunction(const char* luaFunction, lua_CFunction cppFunc
     lua_setglobal(Game::getInstance()->getScriptController()->_lua, luaFunction);
 }
 
-void ScriptUtil::setGlobalHierarchyPair(const std::string& base, const std::string& derived)
-{
-    Game::getInstance()->getScriptController()->_hierarchy[base].push_back(derived);
-}
-
 ScriptUtil::LuaArray<bool> ScriptUtil::getBoolPointer(int index)
 {
     GENERATE_LUA_GET_POINTER(bool, luaCheckBool);
@@ -1787,6 +1773,69 @@ ScriptUtil::LuaArray<double> ScriptUtil::getDoublePointer(int index)
     GENERATE_LUA_GET_POINTER(double, (double)luaL_checknumber);
 }
 
+void* ScriptUtil::getUserDataObjectPointer(int index, const char* type)
+{
+    ScriptController* sc = Game::getInstance()->getScriptController();
+
+    // Get the base raw userdata pointer
+    void* p = lua_touserdata(sc->_lua, index);
+    if (p == NULL)
+    {
+        // No userdata at the given index
+        return NULL;
+    }
+
+    // Push metatable of userdata object.
+    if (!lua_getmetatable(sc->_lua, index))
+    {
+        // No metatable associated with user object, might simply be lightuserdata
+        return NULL;
+    }
+
+    // Push metatable for the specified type.
+    luaL_getmetatable(sc->_lua, type);
+
+    // If the metatables are equal, the object is exactly the type specified
+    if (lua_rawequal(sc->_lua, -1, -2))
+    {
+        // Found a match : pop both metatables.
+        lua_pop(sc->_lua, 2);
+
+        // Return the address as-is
+        return ((ScriptUtil::LuaObject*)p)->instance;
+    }
+
+    // Pop metatable for the given type : instead, we'll check other types
+    // in the inheritance tree of the type.
+    lua_pop(sc->_lua, 1);
+
+    const std::vector<std::string>& types = luaGetClassRelatives(type);
+    for (size_t i = 0, count = types.size(); i < count; i++)
+    {
+        const std::string& relatedType = types[i];
+
+        // Push relative type metatable
+        luaL_getmetatable(sc->_lua, relatedType.c_str());
+
+        // Compare the object's metatable to this relative's metatable
+        if (lua_rawequal(sc->_lua, -1, -2))
+        {
+            // Found a match : pop both metatables.
+            lua_pop(sc->_lua, 2);
+
+            // Need to convert the raw userdata pointer to a valid object pointer of the given type
+            return luaConvertObjectPointer(((ScriptUtil::LuaObject*)p)->instance, relatedType.c_str(), type);
+        }
+        // Pop relative type metatable
+        lua_pop(sc->_lua, 1);
+    }
+
+    // Pop metatable of userdata object
+    lua_pop(sc->_lua, 1);
+
+    return NULL;
+}
+
 const char* ScriptUtil::getString(int index, bool isStdString)
 {
     if (lua_type(Game::getInstance()->getScriptController()->_lua, index) == LUA_TSTRING)

+ 123 - 104
gameplay/src/ScriptController.h

@@ -42,24 +42,26 @@ public:
      * Calls a zero-parameter global function.
      * 
      * @param func The name of the function to call.
-     * 
-     * @return The return value of the executed Lua function.
+     * @param out Pointer to populate with the return value if the function succeeds, or NULL.
+     *
+     * @return True if the function is successfully executed, false otherwise.
      *
      * @script{ignore}
      */
-    template<typename T> T executeFunction(const char* func);
+    template<typename T> bool executeFunction(const char* func, T* out);
 
     /**
      * Calls a zero-parameter function.
      * 
      * @param script The script to execute the function on, or NULL for the global script environment.
      * @param func The name of the function to call.
-     * 
-     * @return The return value of the executed Lua function.
+     * @param out Pointer to populate with the return value if the function succeeds, or NULL.
+     *
+     * @return True if the function is successfully executed, false otherwise.
      *
      * @script{ignore}
      */
-    template<typename T> T executeFunction(Script* script, const char* func);
+    template<typename T> bool executeFunction(Script* script, const char* func, T* out);
 
     /**
      * Calls a global function using the given parameters.
@@ -81,13 +83,14 @@ public:
      *      - 'p' - pointer
      *      - '<object-type>' - a <b>pointer</b> to an object of the given type (where the qualified type name is enclosed by angle brackets).
      *      - '[enum-type]' - an enumerated value of the given type (where the qualified type name is enclosed by square brackets).
+     * @param out Pointer to populate with the return value if the function succeeds, or NULL.
      * @param ... Parameters to pass to the script fucntion, as specified by the args parameter.
      *
-     * @return The return value of the executed Lua function.
+     * @return True if the function is successfully executed, false otherwise.
      *
      * @script{ignore}
      */
-    template<typename T> T executeFunction(const char* func, const char* args, ...);
+    template<typename T> bool executeFunction(const char* func, const char* args, T* out, ...);
 
     /**
      * Calls the a function from the specified script, using the given parameters.
@@ -110,13 +113,14 @@ public:
      *      - 'p' - pointer
      *      - '<object-type>' - a <b>pointer</b> to an object of the given type (where the qualified type name is enclosed by angle brackets).
      *      - '[enum-type]' - an enumerated value of the given type (where the qualified type name is enclosed by square brackets).
+     * @param out Pointer to populate with the return value if the function succeeds, or NULL.
      * @param ... Parameters to pass to the script fucntion, as specified by the args parameter.
      * 
-     * @return The return value of the executed Lua function.
+     * @return True if the function is successfully executed, false otherwise.
      *
      * @script{ignore}
      */
-    template<typename T> T executeFunction(Script* script, const char* func, const char* args, ...);
+    template<typename T> bool executeFunction(Script* script, const char* func, const char* args, T* out, ...);
 
     /**
      * Calls the specified global Lua function using the given parameters.
@@ -138,13 +142,14 @@ public:
      *      - 'p' - pointer
      *      - '<object-type>' - a <b>pointer</b> to an object of the given type (where the qualified type name is enclosed by angle brackets).
      *      - '[enum-type]' - an enumerated value of the given type (where the qualified type name is enclosed by square brackets).
+     * @param out Pointer to populate with the return value if the function succeeds, or NULL.
      * @param list The variable argument list containing the function's parameters, or NULL for an empty parameter list.
      *
-     * @return The return value of the executed Lua function.
+     * @return True if the function is successfully executed, false otherwise.
      *
      * @script{ignore}
      */
-    template<typename T> T executeFunction(const char* func, const char* args, va_list* list);
+    template<typename T> bool executeFunction(const char* func, const char* args, T* out, va_list* list);
 
     /**
      * Calls the specified global Lua function using the given parameters.
@@ -167,13 +172,14 @@ public:
      *      - 'p' - pointer
      *      - '<object-type>' - a <b>pointer</b> to an object of the given type (where the qualified type name is enclosed by angle brackets).
      *      - '[enum-type]' - an enumerated value of the given type (where the qualified type name is enclosed by square brackets).
+     * @param out Pointer to populate with the return value if the function succeeds, or NULL.
      * @param list The variable argument list containing the function's parameters, or NULL for an empty parameter list.
      *
-     * @return The return value of the executed Lua function.
+     * @return True if the function is successfully executed, false otherwise.
      *
      * @script{ignore}
      */
-    template<typename T> T executeFunction(Script* script, const char* func, const char* args, va_list* list);
+    template<typename T> bool executeFunction(Script* script, const char* func, const char* args, T* out, va_list* list);
 
     /**
      * Gets the global boolean script variable with the given name.
@@ -620,7 +626,11 @@ private:
     /**
      * Calls the specified Lua function using the given parameters.
      * 
-     * @param resultCount The expected number of returned values.
+     * Note that this function may push one or more nested tables onto the stack, as neccessary
+     * to execute the function. It will also push 'resultCount' results onto the stack.
+     * The caller must ensure the stack is cleaned up afterwards.
+     *
+     * @param resultCount The expected number of returned values that will be pushed onto the stack.
      * @param func The name of the function to call.
      * @param args The optional argument signature of the function, as a string of the form
      *      'xxx', where each 'x' is a parameter type and must be one of:
@@ -641,8 +651,9 @@ private:
      *      - '[enum-type]' - an enumerated value of the given type (where the qualified type name is enclosed by square brackets).
      * @param list The variable argument list.
      * @param script Optional script to execute the function in, or NULL for to execute it in the global environment.
+     * @return True if the function is executed and results were pushed, false if an error occurred (in which case nothing is pushed).
      */
-    void executeFunctionHelper(int resultCount, const char* func, const char* args, va_list* list, Script* script = NULL);
+    bool executeFunctionHelper(int resultCount, const char* func, const char* args, va_list* list, Script* script = NULL);
 
     /**
      * Converts a Gameplay userdata value to the type with the given class name.
@@ -686,173 +697,172 @@ private:
 
     lua_State* _lua;
     unsigned int _returnCount;
-    std::map<std::string, std::vector<std::string> > _hierarchy;
     std::map<std::string, std::vector<Script*> > _scripts;
     std::vector<Script*> _envStack;
     std::list<ScriptTimeListener*> _timeListeners;
 };
 
 /** Template specialization. */
-template<> void ScriptController::executeFunction<void>(const char* func);
+template<> bool ScriptController::executeFunction<void>(const char* func, void* out);
 /** Template specialization. */
-template<> bool ScriptController::executeFunction<bool>(const char* func);
+template<> bool ScriptController::executeFunction<bool>(const char* func, bool* out);
 /** Template specialization. */
-template<> char ScriptController::executeFunction<char>(const char* func);
+template<> bool ScriptController::executeFunction<char>(const char* func, char* out);
 /** Template specialization. */
-template<> short ScriptController::executeFunction<short>(const char* func);
+template<> bool ScriptController::executeFunction<short>(const char* func, short* out);
 /** Template specialization. */
-template<> int ScriptController::executeFunction<int>(const char* func);
+template<> bool ScriptController::executeFunction<int>(const char* func, int* out);
 /** Template specialization. */
-template<> long ScriptController::executeFunction<long>(const char* func);
+template<> bool ScriptController::executeFunction<long>(const char* func, long* out);
 /** Template specialization. */
-template<> unsigned char ScriptController::executeFunction<unsigned char>(const char* func);
+template<> bool ScriptController::executeFunction<unsigned char>(const char* func, unsigned char* out);
 /** Template specialization. */
-template<> unsigned short ScriptController::executeFunction<unsigned short>(const char* func);
+template<> bool ScriptController::executeFunction<unsigned short>(const char* func, unsigned short* out);
 /** Template specialization. */
-template<> unsigned int ScriptController::executeFunction<unsigned int>(const char* func);
+template<> bool ScriptController::executeFunction<unsigned int>(const char* func, unsigned int* out);
 /** Template specialization. */
-template<> unsigned long ScriptController::executeFunction<unsigned long>(const char* func);
+template<> bool ScriptController::executeFunction<unsigned long>(const char* func, unsigned long* out);
 /** Template specialization. */
-template<> float ScriptController::executeFunction<float>(const char* func);
+template<> bool ScriptController::executeFunction<float>(const char* func, float* out);
 /** Template specialization. */
-template<> double ScriptController::executeFunction<double>(const char* func);
+template<> bool ScriptController::executeFunction<double>(const char* func, double* out);
 /** Template specialization. */
-template<> std::string ScriptController::executeFunction<std::string>(const char* func);
+template<> bool ScriptController::executeFunction<std::string>(const char* func, std::string* out);
 
 /** Template specialization. */
-template<> void ScriptController::executeFunction<void>(Script* script, const char* func);
+template<> bool ScriptController::executeFunction<void>(Script* script, const char* func, void* out);
 /** Template specialization. */
-template<> bool ScriptController::executeFunction<bool>(Script* script, const char* func);
+template<> bool ScriptController::executeFunction<bool>(Script* script, const char* func, bool* out);
 /** Template specialization. */
-template<> char ScriptController::executeFunction<char>(Script* script, const char* func);
+template<> bool ScriptController::executeFunction<char>(Script* script, const char* func, char* out);
 /** Template specialization. */
-template<> short ScriptController::executeFunction<short>(Script* script, const char* func);
+template<> bool ScriptController::executeFunction<short>(Script* script, const char* func, short* out);
 /** Template specialization. */
-template<> int ScriptController::executeFunction<int>(Script* script, const char* func);
+template<> bool ScriptController::executeFunction<int>(Script* script, const char* func, int* out);
 /** Template specialization. */
-template<> long ScriptController::executeFunction<long>(Script* script, const char* func);
+template<> bool ScriptController::executeFunction<long>(Script* script, const char* func, long* out);
 /** Template specialization. */
-template<> unsigned char ScriptController::executeFunction<unsigned char>(Script* script, const char* func);
+template<> bool ScriptController::executeFunction<unsigned char>(Script* script, const char* func, unsigned char* out);
 /** Template specialization. */
-template<> unsigned short ScriptController::executeFunction<unsigned short>(Script* script, const char* func);
+template<> bool ScriptController::executeFunction<unsigned short>(Script* script, const char* func, unsigned short* out);
 /** Template specialization. */
-template<> unsigned int ScriptController::executeFunction<unsigned int>(Script* script, const char* func);
+template<> bool ScriptController::executeFunction<unsigned int>(Script* script, const char* func, unsigned int* out);
 /** Template specialization. */
-template<> unsigned long ScriptController::executeFunction<unsigned long>(Script* script, const char* func);
+template<> bool ScriptController::executeFunction<unsigned long>(Script* script, const char* func, unsigned long* out);
 /** Template specialization. */
-template<> float ScriptController::executeFunction<float>(Script* script, const char* func);
+template<> bool ScriptController::executeFunction<float>(Script* script, const char* func, float* out);
 /** Template specialization. */
-template<> double ScriptController::executeFunction<double>(Script* script, const char* func);
+template<> bool ScriptController::executeFunction<double>(Script* script, const char* func, double* out);
 /** Template specialization. */
-template<> std::string ScriptController::executeFunction<std::string>(Script* script, const char* func);
+template<> bool ScriptController::executeFunction<std::string>(Script* script, const char* func, std::string* out);
 
 /** Template specialization. */
-template<> void ScriptController::executeFunction<void>(const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<void>(const char* func, const char* args, void* out, ...);
 /** Template specialization. */
-template<> bool ScriptController::executeFunction<bool>(const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<bool>(const char* func, const char* args, bool* out, ...);
 /** Template specialization. */
-template<> char ScriptController::executeFunction<char>(const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<char>(const char* func, const char* args, char* out, ...);
 /** Template specialization. */
-template<> short ScriptController::executeFunction<short>(const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<short>(const char* func, const char* args, short* out, ...);
 /** Template specialization. */
-template<> int ScriptController::executeFunction<int>(const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<int>(const char* func, const char* args, int* out, ...);
 /** Template specialization. */
-template<> long ScriptController::executeFunction<long>(const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<long>(const char* func, const char* args, long* out, ...);
 /** Template specialization. */
-template<> unsigned char ScriptController::executeFunction<unsigned char>(const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<unsigned char>(const char* func, const char* args, unsigned char* out, ...);
 /** Template specialization. */
-template<> unsigned short ScriptController::executeFunction<unsigned short>(const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<unsigned short>(const char* func, const char* args, unsigned short* out, ...);
 /** Template specialization. */
-template<> unsigned int ScriptController::executeFunction<unsigned int>(const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<unsigned int>(const char* func, const char* args, unsigned int* out, ...);
 /** Template specialization. */
-template<> unsigned long ScriptController::executeFunction<unsigned long>(const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<unsigned long>(const char* func, const char* args, unsigned long* out, ...);
 /** Template specialization. */
-template<> float ScriptController::executeFunction<float>(const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<float>(const char* func, const char* args, float* out, ...);
 /** Template specialization. */
-template<> double ScriptController::executeFunction<double>(const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<double>(const char* func, const char* args, double* out, ...);
 /** Template specialization. */
-template<> std::string ScriptController::executeFunction<std::string>(const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<std::string>(const char* func, const char* args, std::string* out, ...);
 
 /** Template specialization. */
-template<> void ScriptController::executeFunction<void>(Script* script, const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<void>(Script* script, const char* func, const char* args, void* out, ...);
 /** Template specialization. */
-template<> bool ScriptController::executeFunction<bool>(Script* script, const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<bool>(Script* script, const char* func, const char* args, bool* out, ...);
 /** Template specialization. */
-template<> char ScriptController::executeFunction<char>(Script* script, const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<char>(Script* script, const char* func, const char* args, char* out, ...);
 /** Template specialization. */
-template<> short ScriptController::executeFunction<short>(Script* script, const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<short>(Script* script, const char* func, const char* args, short* out, ...);
 /** Template specialization. */
-template<> int ScriptController::executeFunction<int>(Script* script, const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<int>(Script* script, const char* func, const char* args, int* out, ...);
 /** Template specialization. */
-template<> long ScriptController::executeFunction<long>(Script* script, const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<long>(Script* script, const char* func, const char* args, long* out, ...);
 /** Template specialization. */
-template<> unsigned char ScriptController::executeFunction<unsigned char>(Script* script, const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<unsigned char>(Script* script, const char* func, const char* args, unsigned char* out, ...);
 /** Template specialization. */
-template<> unsigned short ScriptController::executeFunction<unsigned short>(Script* script, const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<unsigned short>(Script* script, const char* func, const char* args, unsigned short* out, ...);
 /** Template specialization. */
-template<> unsigned int ScriptController::executeFunction<unsigned int>(Script* script, const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<unsigned int>(Script* script, const char* func, const char* args, unsigned int* out, ...);
 /** Template specialization. */
-template<> unsigned long ScriptController::executeFunction<unsigned long>(Script* script, const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<unsigned long>(Script* script, const char* func, const char* args, unsigned long* out, ...);
 /** Template specialization. */
-template<> float ScriptController::executeFunction<float>(Script* script, const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<float>(Script* script, const char* func, const char* args, float* out, ...);
 /** Template specialization. */
-template<> double ScriptController::executeFunction<double>(Script* script, const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<double>(Script* script, const char* func, const char* args, double* out, ...);
 /** Template specialization. */
-template<> std::string ScriptController::executeFunction<std::string>(Script* script, const char* func, const char* args, ...);
+template<> bool ScriptController::executeFunction<std::string>(Script* script, const char* func, const char* args, std::string* out, ...);
 
 /** Template specialization. */
-template<> void ScriptController::executeFunction<void>(const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<void>(const char* func, const char* args, void* out, va_list* list);
 /** Template specialization. */
-template<> bool ScriptController::executeFunction<bool>(const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<bool>(const char* func, const char* args, bool* out, va_list* list);
 /** Template specialization. */
-template<> char ScriptController::executeFunction<char>(const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<char>(const char* func, const char* args, char* out, va_list* list);
 /** Template specialization. */
-template<> short ScriptController::executeFunction<short>(const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<short>(const char* func, const char* args, short* out, va_list* list);
 /** Template specialization. */
-template<> int ScriptController::executeFunction<int>(const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<int>(const char* func, const char* args, int* out, va_list* list);
 /** Template specialization. */
-template<> long ScriptController::executeFunction<long>(const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<long>(const char* func, const char* args, long* out, va_list* list);
 /** Template specialization. */
-template<> unsigned char ScriptController::executeFunction<unsigned char>(const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<unsigned char>(const char* func, const char* args, unsigned char* out, va_list* list);
 /** Template specialization. */
-template<> unsigned short ScriptController::executeFunction<unsigned short>(const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<unsigned short>(const char* func, const char* args, unsigned short* out, va_list* list);
 /** Template specialization. */
-template<> unsigned int ScriptController::executeFunction<unsigned int>(const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<unsigned int>(const char* func, const char* args, unsigned int* out, va_list* list);
 /** Template specialization. */
-template<> unsigned long ScriptController::executeFunction<unsigned long>(const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<unsigned long>(const char* func, const char* args, unsigned long* out, va_list* list);
 /** Template specialization. */
-template<> float ScriptController::executeFunction<float>(const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<float>(const char* func, const char* args, float* out, va_list* list);
 /** Template specialization. */
-template<> double ScriptController::executeFunction<double>(const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<double>(const char* func, const char* args, double* out, va_list* list);
 /** Template specialization. */
-template<> std::string ScriptController::executeFunction<std::string>(const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<std::string>(const char* func, const char* args, std::string* out, va_list* list);
 
 /** Template specialization. */
-template<> void ScriptController::executeFunction<void>(Script* script, const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<void>(Script* script, const char* func, const char* args, void* out, va_list* list);
 /** Template specialization. */
-template<> bool ScriptController::executeFunction<bool>(Script* script, const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<bool>(Script* script, const char* func, const char* args, bool* out, va_list* list);
 /** Template specialization. */
-template<> char ScriptController::executeFunction<char>(Script* script, const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<char>(Script* script, const char* func, const char* args, char* out, va_list* list);
 /** Template specialization. */
-template<> short ScriptController::executeFunction<short>(Script* script, const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<short>(Script* script, const char* func, const char* args, short* out, va_list* list);
 /** Template specialization. */
-template<> int ScriptController::executeFunction<int>(Script* script, const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<int>(Script* script, const char* func, const char* args, int* out, va_list* list);
 /** Template specialization. */
-template<> long ScriptController::executeFunction<long>(Script* script, const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<long>(Script* script, const char* func, const char* args, long* out, va_list* list);
 /** Template specialization. */
-template<> unsigned char ScriptController::executeFunction<unsigned char>(Script* script, const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<unsigned char>(Script* script, const char* func, const char* args, unsigned char* out, va_list* list);
 /** Template specialization. */
-template<> unsigned short ScriptController::executeFunction<unsigned short>(Script* script, const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<unsigned short>(Script* script, const char* func, const char* args, unsigned short* out, va_list* list);
 /** Template specialization. */
-template<> unsigned int ScriptController::executeFunction<unsigned int>(Script* script, const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<unsigned int>(Script* script, const char* func, const char* args, unsigned int* out, va_list* list);
 /** Template specialization. */
-template<> unsigned long ScriptController::executeFunction<unsigned long>(Script* script, const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<unsigned long>(Script* script, const char* func, const char* args, unsigned long* out, va_list* list);
 /** Template specialization. */
-template<> float ScriptController::executeFunction<float>(Script* script, const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<float>(Script* script, const char* func, const char* args, float* out, va_list* list);
 /** Template specialization. */
-template<> double ScriptController::executeFunction<double>(Script* script, const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<double>(Script* script, const char* func, const char* args, double* out, va_list* list);
 /** Template specialization. */
-template<> std::string ScriptController::executeFunction<std::string>(Script* script, const char* func, const char* args, va_list* list);
+template<> bool ScriptController::executeFunction<std::string>(Script* script, const char* func, const char* args, std::string* out, va_list* list);
 
 /**
  * Functions and structures used by the generated Lua script bindings.
@@ -1013,14 +1023,6 @@ public:
      */
     static void registerFunction(const char* luaFunction, lua_CFunction cppFunction);
 
-    /**
-     * Sets an inheritance pair within the global inheritance hierarchy (base, derived).
-     * 
-     * @param base The base class of the inheritance pair.
-     * @param derived The derived class of the inheritance pair.
-     */
-    static void setGlobalHierarchyPair(const std::string& base, const std::string& derived);
-
     /**
      * Gets a pointer to a bool (as an array-use SAFE_DELETE_ARRAY to clean up) for the given stack index.
      * 
@@ -1113,9 +1115,11 @@ public:
 
     /**
      * Gets an object pointer of the given type for the given stack index.
+     *
+     * This method supports both objects and arrays/tables of objects.
      * 
-     * @param type The type of object pointer to retrieve.
      * @param index The stack index.
+     * @param type The type of object pointer to retrieve.
      * @param nonNull Whether the pointer must be non-null (e.g. if the parameter we 
      *      are retrieving is actually a reference or by-value parameter).
      * @param success An out parameter that is set to true if the Lua parameter was successfully
@@ -1127,6 +1131,21 @@ public:
     template <typename T>
     static LuaArray<T> getObjectPointer(int index, const char* type, bool nonNull, bool* success);
 
+    /**
+     * Gets a raw pointer that points to the correct address for the given type interface.
+     *
+     * This method requires that the type at the specified stack index is of type userdata
+     * and is in the inheritence chain of the given type. If either of these are not true,
+     * NULL will be returned.
+     *
+     * @param index The stack index.
+     * @param type The type of object pointer to retrieve.
+     *
+     * @return The raw pointer or <code>NULL</code> if the data at the stack index
+     *        is not an object of the given type.
+     */
+    static void* getUserDataObjectPointer(int index, const char* type);
+
     /**
      * Gets a string for the given stack index.
      * 

+ 48 - 143
gameplay/src/ScriptController.inl

@@ -136,67 +136,8 @@ ScriptUtil::LuaArray<T> ScriptUtil::getObjectPointer(int index, const char* type
         lua_pushnil(sc->_lua);
         for (; lua_next(sc->_lua, index) != 0 && i < size; i++)
         {
-            // Process each item in the array - make sure they are of valid types.
-            void* p = lua_touserdata(sc->_lua, -1);
-            if (p == NULL)
-            {
-                arr.set(i, (T*)NULL);
-            }
-            else
-            {
-                bool foundMatch = false;
-
-                // Push array element metatable.
-                if (lua_getmetatable(sc->_lua, -1))
-                {
-                    // Push param type metatable.
-                    luaL_getmetatable(sc->_lua, type);
-                    if (lua_rawequal(sc->_lua, -1, -2))
-                    {
-                        // Pop param type metatable.
-                        lua_pop(sc->_lua, 1);
-
-                        // Matched the declared parameter type.
-                        arr.set(i, (T*)((ScriptUtil::LuaObject*)p)->instance);
-                        foundMatch = true;
-                    }
-                    else
-                    {
-                        // Pop param type metatable.
-                        lua_pop(sc->_lua, 1);
-
-                        // Check if it matches any of the derived types' metatables.
-                        const std::vector<std::string>& types = sc->_hierarchy[type];
-                        for (size_t k = 0, count = types.size(); k < count; k++)
-                        {
-                            // Push dervied type metatable.
-                            luaL_getmetatable(sc->_lua, types[k].c_str());
-                            if (lua_rawequal(sc->_lua, -1, -2))
-                            {
-                                // Pop derived type metatable.
-                                lua_pop(sc->_lua, 1);
-
-                                // Matched a derived type.
-                                arr.set(i, (T*)((ScriptUtil::LuaObject*)p)->instance);
-                                foundMatch = true;
-                                break;
-                            }
-                            // Pop derived type metatable
-                            lua_pop(sc->_lua, 1);
-                        }
-                    }
-
-                    // Pop array element metatable.
-                    lua_pop(sc->_lua, 1);
-                }
-
-                if (!foundMatch)
-                {
-                    GP_WARN("Invalid type passed for an array element for parameter index %d.", index);
-                    arr.set(i, (T*)NULL);
-                    *success = false;
-                }
-            }
+            void* p = getUserDataObjectPointer(-1, type);
+            arr.set(i, (T*)p);
 
             // Pop 'value' and key 'key' for lua_next.
             lua_pop(sc->_lua, 1);
@@ -206,113 +147,77 @@ ScriptUtil::LuaArray<T> ScriptUtil::getObjectPointer(int index, const char* type
     }
 
     // Type is not nil and not a table, so it should be USERDATA.
-    void* p = lua_touserdata(sc->_lua, index);
-    if (p != NULL)
+    void* p = getUserDataObjectPointer(index, type);
+    if (p == NULL && nonNull)
     {
-        // Push object metatable.
-        if (lua_getmetatable(sc->_lua, index))
-        {
-            // Push param type metatable.
-            luaL_getmetatable(sc->_lua, type);
-            if (lua_rawequal(sc->_lua, -1, -2))
-            {
-                // Pop both metatables.
-                lua_pop(sc->_lua, 2);
-
-                T* ptr = (T*)((ScriptUtil::LuaObject*)p)->instance;
-                if (ptr == NULL && nonNull)
-                {
-                    GP_WARN("Attempting to pass NULL for required non-NULL parameter at index %d (likely a reference or by-value parameter).", index);
-                    return LuaArray<T>((T*)NULL);
-                }
-
-                // Type is valid.
-                *success = true;
-                return LuaArray<T>(ptr);
-            }
-            // Pop param type metable.
-            lua_pop(sc->_lua, 1);
-
-            // Check if it matches any of the derived types' metatables.
-            const std::vector<std::string>& types = sc->_hierarchy[type];
-            for (size_t i = 0, count = types.size(); i < count; i++)
-            {
-                // Push derived type metatable.
-                luaL_getmetatable(sc->_lua, types[i].c_str());
-                if (lua_rawequal(sc->_lua, -1, -2))
-                {
-                    // Pop both metatables.
-                    lua_pop(sc->_lua, 2);
-
-                    T* ptr = (T*)((ScriptUtil::LuaObject*)p)->instance;
-                    if (ptr == NULL && nonNull)
-                    {
-                        GP_WARN("Attempting to pass NULL for required non-NULL parameter at index %d (likely a reference or by-value parameter).", index);
-                        return LuaArray<T>((T*)NULL);
-                    }
-
-                    // Type is valid (matches a derived type).
-                    *success = true;
-                    return LuaArray<T>(ptr);
-                }
-                // Pop derived type metatable.
-                lua_pop(sc->_lua, 1);
-            }
-
-            // Pop object metatable.
-            lua_pop(sc->_lua, 1);
-        }
+        GP_WARN("Attempting to pass NULL for required non-NULL parameter at index %d (likely a reference or by-value parameter).", index);
+        return LuaArray<T>((T*)NULL);
+    }
+    else
+    {
+        *success = true;
     }
 
-    // If we made it here, type was not nil, and it could not be mapped to a valid object pointer.
-    //GP_WARN("Failed to retrieve a valid object pointer of type '%s' for parameter %d.", type, index);
-
-    return LuaArray<T>((T*)NULL);
+    return LuaArray<T>((T*)p);
 }
 
-template<typename T> T ScriptController::executeFunction(const char* func)
+template<typename T> bool ScriptController::executeFunction(const char* func, T* out)
 {
-    return executeFunction<T>((Script*)NULL, func);
+    return executeFunction<T>((Script*)NULL, func, out);
 }
 
-template<typename T> T ScriptController::executeFunction(Script* script, const char* func)
+template<typename T> bool ScriptController::executeFunction(Script* script, const char* func, T* out)
 {
-    executeFunctionHelper(1, func, NULL, NULL, script);
-    T value = (T)((ScriptUtil::LuaObject*)lua_touserdata(_lua, -1))->instance;
-    lua_pop(_lua, -1);
-    return value;
+    // Userdata / object type expected - all other return types have template specializations.
+    // Non-userdata types will return NULL.
+    int top = lua_gettop(_lua);
+    bool success = executeFunctionHelper(1, func, NULL, NULL, script);
+    if (out && success)
+        *out = (T)((ScriptUtil::LuaObject*)lua_touserdata(_lua, -1))->instance;
+    lua_settop(top);
+    return success;
 }
 
-template<typename T> T ScriptController::executeFunction(const char* func, const char* args, ...)
+template<typename T> bool ScriptController::executeFunction(const char* func, const char* args, T* out, ...)
 {
     va_list list;
-    va_start(list, args);
-    T value = executeFunction<T>((Script*)NULL, func, args, list);
+    va_start(list, out);
+    bool success = executeFunction<T>((Script*)NULL, func, args, out, list);
     va_end(list);
-    return value;
+    return success;
 }
 
-template<typename T> T ScriptController::executeFunction(Script* script, const char* func, const char* args, ...)
+template<typename T> bool ScriptController::executeFunction(Script* script, const char* func, const char* args, T* out, ...)
 {
     va_list list;
-    va_start(list, args);
-    T value = executeFunction<T>(script, func, args, list);
+    va_start(list, out);
+    bool success = executeFunction<T>(script, func, args, out, list);
     va_end(list);
-    return value;
+    return success;
 }
 
-template<typename T> T ScriptController::executeFunction(const char* func, const char* args, va_list* list)
+template<typename T> bool ScriptController::executeFunction(const char* func, const char* args, T* out, va_list* list)
 {
-    return executeFunctionHelper(1, func, args, list, (Script*)NULL);
+    // Userdata / object type expected - all other return types have template specializations.
+    // Non-userdata types will return NULL.
+    int top = lua_gettop(_lua);
+    bool success = executeFunctionHelper(1, func, args, list, (Script*)NULL);
+    if (out && success)
+        *out = (T)((ScriptUtil::LuaObject*)lua_touserdata(_lua, -1))->instance;
+    lua_settop(top);
+    return success;
 }
 
-template<typename T> T ScriptController::executeFunction(Script* script, const char* func, const char* args, va_list* list)
+template<typename T> bool ScriptController::executeFunction(Script* script, const char* func, const char* args, T* out, va_list* list)
 {
-    executeFunctionHelper(1, func, args, list, script);
-
-    T value = (T)((ScriptUtil::LuaObject*)lua_touserdata(_lua, -1))->instance;
-    lua_pop(_lua, -1);
-    return value;
+    // Userdata / object type expected - all other return types have template specializations.
+    // Non-userdata types will return NULL.
+    int top = lua_gettop(_lua);
+    bool success = executeFunctionHelper(1, func, args, list, script);
+    if (out && success)
+        *out = (T)((ScriptUtil::LuaObject*)lua_touserdata(_lua, -1))->instance;
+    lua_settop(_lua, top);
+    return success;
 }
 
 }

+ 5 - 5
gameplay/src/ScriptTarget.cpp

@@ -168,9 +168,7 @@ Script* ScriptTarget::addScript(const char* path)
     // Automatically call the 'attached' event if it is defined within the script
     if (sc->functionExists("attached", script))
     {
-        char args[256];
-        sprintf(args, "<%s>", getTypeName());
-        sc->executeFunction<void>(script, "attached", args, dynamic_cast<void*>(this));
+        sc->executeFunction<void>(script, "attached", "<ScriptTarget>", NULL, (void*)this);
     }
 
     return script;
@@ -435,7 +433,7 @@ template<> void ScriptTarget::fireScriptEvent<void>(const Event* event, ...)
         for (size_t i = 0, count = callbacks.size(); i < count; ++i)
         {
             CallbackFunction& cb = callbacks[i];
-            sc->executeFunction<void>(cb.script, cb.function.c_str(), event->args.c_str(), &list);
+            sc->executeFunction<void>(cb.script, cb.function.c_str(), event->args.c_str(), NULL, &list);
         }
     }
 
@@ -461,8 +459,10 @@ template<> bool ScriptTarget::fireScriptEvent<bool>(const Event* event, ...)
         for (size_t i = 0, count = callbacks.size(); i < count; ++i)
         {
             CallbackFunction& cb = callbacks[i];
-            if (sc->executeFunction<bool>(cb.script, cb.function.c_str(), event->args.c_str(), &list))
+            bool result = false;
+            if (sc->executeFunction<bool>(cb.script, cb.function.c_str(), event->args.c_str(), &result, &list) && result)
             {
+                // Handled, break out early
                 va_end(list);
                 return true;
             }

+ 1 - 1
gameplay/src/Terrain.h

@@ -81,7 +81,7 @@ class TerrainAutoBindingResolver;
  *
  * @see http://gameplay3d.github.io/GamePlay/docs/file-formats.html#wiki-Terrain
  */
-class Terrain : public Ref, public Drawable, private Transform::Listener
+class Terrain : public Ref, public Drawable, public Transform::Listener
 {
     friend class Node;
     friend class PhysicsController;

+ 85 - 35
gameplay/src/lua/lua_AIAgent.cpp

@@ -7,34 +7,12 @@
 #include "Game.h"
 #include "Node.h"
 #include "Ref.h"
+#include "Ref.h"
 
 namespace gameplay
 {
 
-void luaRegister_AIAgent()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_AIAgent_addRef},
-        {"getId", lua_AIAgent_getId},
-        {"getNode", lua_AIAgent_getNode},
-        {"getRefCount", lua_AIAgent_getRefCount},
-        {"getStateMachine", lua_AIAgent_getStateMachine},
-        {"isEnabled", lua_AIAgent_isEnabled},
-        {"release", lua_AIAgent_release},
-        {"setEnabled", lua_AIAgent_setEnabled},
-        {"setListener", lua_AIAgent_setListener},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"create", lua_AIAgent_static_create},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AIAgent", lua_members, NULL, lua_AIAgent__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static AIAgent* getInstance(lua_State* state)
 {
@@ -43,7 +21,7 @@ static AIAgent* getInstance(lua_State* state)
     return (AIAgent*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AIAgent__gc(lua_State* state)
+static int lua_AIAgent__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -81,7 +59,7 @@ int lua_AIAgent__gc(lua_State* state)
     return 0;
 }
 
-int lua_AIAgent_addRef(lua_State* state)
+static int lua_AIAgent_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -113,7 +91,7 @@ int lua_AIAgent_addRef(lua_State* state)
     return 0;
 }
 
-int lua_AIAgent_getId(lua_State* state)
+static int lua_AIAgent_getId(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -148,7 +126,7 @@ int lua_AIAgent_getId(lua_State* state)
     return 0;
 }
 
-int lua_AIAgent_getNode(lua_State* state)
+static int lua_AIAgent_getNode(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -192,7 +170,7 @@ int lua_AIAgent_getNode(lua_State* state)
     return 0;
 }
 
-int lua_AIAgent_getRefCount(lua_State* state)
+static int lua_AIAgent_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -227,7 +205,7 @@ int lua_AIAgent_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_AIAgent_getStateMachine(lua_State* state)
+static int lua_AIAgent_getStateMachine(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -271,7 +249,7 @@ int lua_AIAgent_getStateMachine(lua_State* state)
     return 0;
 }
 
-int lua_AIAgent_isEnabled(lua_State* state)
+static int lua_AIAgent_isEnabled(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -306,7 +284,7 @@ int lua_AIAgent_isEnabled(lua_State* state)
     return 0;
 }
 
-int lua_AIAgent_release(lua_State* state)
+static int lua_AIAgent_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -338,7 +316,7 @@ int lua_AIAgent_release(lua_State* state)
     return 0;
 }
 
-int lua_AIAgent_setEnabled(lua_State* state)
+static int lua_AIAgent_setEnabled(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -374,7 +352,7 @@ int lua_AIAgent_setEnabled(lua_State* state)
     return 0;
 }
 
-int lua_AIAgent_setListener(lua_State* state)
+static int lua_AIAgent_setListener(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -416,7 +394,7 @@ int lua_AIAgent_setListener(lua_State* state)
     return 0;
 }
 
-int lua_AIAgent_static_create(lua_State* state)
+static int lua_AIAgent_static_create(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -453,4 +431,76 @@ int lua_AIAgent_static_create(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of AIAgent
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    AIAgent* ptrObject = reinterpret_cast<AIAgent*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_AIAgent_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_AIAgent_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    AIAgent* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_AIAgent()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_AIAgent_addRef},
+        {"getId", lua_AIAgent_getId},
+        {"getNode", lua_AIAgent_getNode},
+        {"getRefCount", lua_AIAgent_getRefCount},
+        {"getStateMachine", lua_AIAgent_getStateMachine},
+        {"isEnabled", lua_AIAgent_isEnabled},
+        {"release", lua_AIAgent_release},
+        {"setEnabled", lua_AIAgent_setEnabled},
+        {"setListener", lua_AIAgent_setListener},
+        {"to", lua_AIAgent_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"create", lua_AIAgent_static_create},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AIAgent", lua_members, NULL, lua_AIAgent__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("AIAgent", __convertTo);
+}
+
 }

+ 0 - 13
gameplay/src/lua/lua_AIAgent.h

@@ -5,19 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AIAgent.
-int lua_AIAgent__gc(lua_State* state);
-int lua_AIAgent_addRef(lua_State* state);
-int lua_AIAgent_getId(lua_State* state);
-int lua_AIAgent_getNode(lua_State* state);
-int lua_AIAgent_getRefCount(lua_State* state);
-int lua_AIAgent_getStateMachine(lua_State* state);
-int lua_AIAgent_isEnabled(lua_State* state);
-int lua_AIAgent_release(lua_State* state);
-int lua_AIAgent_setEnabled(lua_State* state);
-int lua_AIAgent_setListener(lua_State* state);
-int lua_AIAgent_static_create(lua_State* state);
-
 void luaRegister_AIAgent();
 
 }

+ 17 - 16
gameplay/src/lua/lua_AIAgentListener.cpp

@@ -11,20 +11,6 @@
 namespace gameplay
 {
 
-void luaRegister_AIAgentListener()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"messageReceived", lua_AIAgentListener_messageReceived},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-    scopePath.push_back("AIAgent");
-
-    gameplay::ScriptUtil::registerClass("AIAgentListener", lua_members, NULL, lua_AIAgentListener__gc, lua_statics, scopePath);
-}
-
 static AIAgent::Listener* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "AIAgentListener");
@@ -32,7 +18,7 @@ static AIAgent::Listener* getInstance(lua_State* state)
     return (AIAgent::Listener*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AIAgentListener__gc(lua_State* state)
+static int lua_AIAgentListener__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -70,7 +56,7 @@ int lua_AIAgentListener__gc(lua_State* state)
     return 0;
 }
 
-int lua_AIAgentListener_messageReceived(lua_State* state)
+static int lua_AIAgentListener_messageReceived(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -115,4 +101,19 @@ int lua_AIAgentListener_messageReceived(lua_State* state)
     return 0;
 }
 
+void luaRegister_AIAgentListener()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"messageReceived", lua_AIAgentListener_messageReceived},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+    scopePath.push_back("AIAgent");
+
+    gameplay::ScriptUtil::registerClass("AIAgentListener", lua_members, NULL, lua_AIAgentListener__gc, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 4
gameplay/src/lua/lua_AIAgentListener.h

@@ -5,10 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AIAgent::Listener.
-int lua_AIAgentListener__gc(lua_State* state);
-int lua_AIAgentListener_messageReceived(lua_State* state);
-
 void luaRegister_AIAgentListener();
 
 }

+ 17 - 16
gameplay/src/lua/lua_AIController.cpp

@@ -9,20 +9,6 @@
 namespace gameplay
 {
 
-void luaRegister_AIController()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"findAgent", lua_AIController_findAgent},
-        {"sendMessage", lua_AIController_sendMessage},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AIController", lua_members, NULL, NULL, lua_statics, scopePath);
-}
-
 static AIController* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "AIController");
@@ -30,7 +16,7 @@ static AIController* getInstance(lua_State* state)
     return (AIController*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AIController_findAgent(lua_State* state)
+static int lua_AIController_findAgent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -78,7 +64,7 @@ int lua_AIController_findAgent(lua_State* state)
     return 0;
 }
 
-int lua_AIController_sendMessage(lua_State* state)
+static int lua_AIController_sendMessage(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -148,4 +134,19 @@ int lua_AIController_sendMessage(lua_State* state)
     return 0;
 }
 
+void luaRegister_AIController()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"findAgent", lua_AIController_findAgent},
+        {"sendMessage", lua_AIController_sendMessage},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AIController", lua_members, NULL, NULL, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 4
gameplay/src/lua/lua_AIController.h

@@ -5,10 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AIController.
-int lua_AIController_findAgent(lua_State* state);
-int lua_AIController_sendMessage(lua_State* state);
-
 void luaRegister_AIController();
 
 }

+ 54 - 53
gameplay/src/lua/lua_AIMessage.cpp

@@ -8,40 +8,6 @@
 namespace gameplay
 {
 
-void luaRegister_AIMessage()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"getBoolean", lua_AIMessage_getBoolean},
-        {"getDouble", lua_AIMessage_getDouble},
-        {"getFloat", lua_AIMessage_getFloat},
-        {"getId", lua_AIMessage_getId},
-        {"getInt", lua_AIMessage_getInt},
-        {"getLong", lua_AIMessage_getLong},
-        {"getParameterCount", lua_AIMessage_getParameterCount},
-        {"getParameterType", lua_AIMessage_getParameterType},
-        {"getReceiver", lua_AIMessage_getReceiver},
-        {"getSender", lua_AIMessage_getSender},
-        {"getString", lua_AIMessage_getString},
-        {"setBoolean", lua_AIMessage_setBoolean},
-        {"setDouble", lua_AIMessage_setDouble},
-        {"setFloat", lua_AIMessage_setFloat},
-        {"setInt", lua_AIMessage_setInt},
-        {"setLong", lua_AIMessage_setLong},
-        {"setString", lua_AIMessage_setString},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"create", lua_AIMessage_static_create},
-        {"destroy", lua_AIMessage_static_destroy},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AIMessage", lua_members, NULL, NULL, lua_statics, scopePath);
-}
-
 static AIMessage* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "AIMessage");
@@ -49,7 +15,7 @@ static AIMessage* getInstance(lua_State* state)
     return (AIMessage*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AIMessage_getBoolean(lua_State* state)
+static int lua_AIMessage_getBoolean(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -88,7 +54,7 @@ int lua_AIMessage_getBoolean(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_getDouble(lua_State* state)
+static int lua_AIMessage_getDouble(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -127,7 +93,7 @@ int lua_AIMessage_getDouble(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_getFloat(lua_State* state)
+static int lua_AIMessage_getFloat(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -166,7 +132,7 @@ int lua_AIMessage_getFloat(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_getId(lua_State* state)
+static int lua_AIMessage_getId(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -201,7 +167,7 @@ int lua_AIMessage_getId(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_getInt(lua_State* state)
+static int lua_AIMessage_getInt(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -240,7 +206,7 @@ int lua_AIMessage_getInt(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_getLong(lua_State* state)
+static int lua_AIMessage_getLong(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -279,7 +245,7 @@ int lua_AIMessage_getLong(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_getParameterCount(lua_State* state)
+static int lua_AIMessage_getParameterCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -314,7 +280,7 @@ int lua_AIMessage_getParameterCount(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_getParameterType(lua_State* state)
+static int lua_AIMessage_getParameterType(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -353,7 +319,7 @@ int lua_AIMessage_getParameterType(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_getReceiver(lua_State* state)
+static int lua_AIMessage_getReceiver(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -388,7 +354,7 @@ int lua_AIMessage_getReceiver(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_getSender(lua_State* state)
+static int lua_AIMessage_getSender(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -423,7 +389,7 @@ int lua_AIMessage_getSender(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_getString(lua_State* state)
+static int lua_AIMessage_getString(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -462,7 +428,7 @@ int lua_AIMessage_getString(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_setBoolean(lua_State* state)
+static int lua_AIMessage_setBoolean(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -502,7 +468,7 @@ int lua_AIMessage_setBoolean(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_setDouble(lua_State* state)
+static int lua_AIMessage_setDouble(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -542,7 +508,7 @@ int lua_AIMessage_setDouble(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_setFloat(lua_State* state)
+static int lua_AIMessage_setFloat(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -582,7 +548,7 @@ int lua_AIMessage_setFloat(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_setInt(lua_State* state)
+static int lua_AIMessage_setInt(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -622,7 +588,7 @@ int lua_AIMessage_setInt(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_setLong(lua_State* state)
+static int lua_AIMessage_setLong(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -662,7 +628,7 @@ int lua_AIMessage_setLong(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_setString(lua_State* state)
+static int lua_AIMessage_setString(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -702,7 +668,7 @@ int lua_AIMessage_setString(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_static_create(lua_State* state)
+static int lua_AIMessage_static_create(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -760,7 +726,7 @@ int lua_AIMessage_static_create(lua_State* state)
     return 0;
 }
 
-int lua_AIMessage_static_destroy(lua_State* state)
+static int lua_AIMessage_static_destroy(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -800,4 +766,39 @@ int lua_AIMessage_static_destroy(lua_State* state)
     return 0;
 }
 
+void luaRegister_AIMessage()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"getBoolean", lua_AIMessage_getBoolean},
+        {"getDouble", lua_AIMessage_getDouble},
+        {"getFloat", lua_AIMessage_getFloat},
+        {"getId", lua_AIMessage_getId},
+        {"getInt", lua_AIMessage_getInt},
+        {"getLong", lua_AIMessage_getLong},
+        {"getParameterCount", lua_AIMessage_getParameterCount},
+        {"getParameterType", lua_AIMessage_getParameterType},
+        {"getReceiver", lua_AIMessage_getReceiver},
+        {"getSender", lua_AIMessage_getSender},
+        {"getString", lua_AIMessage_getString},
+        {"setBoolean", lua_AIMessage_setBoolean},
+        {"setDouble", lua_AIMessage_setDouble},
+        {"setFloat", lua_AIMessage_setFloat},
+        {"setInt", lua_AIMessage_setInt},
+        {"setLong", lua_AIMessage_setLong},
+        {"setString", lua_AIMessage_setString},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"create", lua_AIMessage_static_create},
+        {"destroy", lua_AIMessage_static_destroy},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AIMessage", lua_members, NULL, NULL, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 21
gameplay/src/lua/lua_AIMessage.h

@@ -5,27 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AIMessage.
-int lua_AIMessage_getBoolean(lua_State* state);
-int lua_AIMessage_getDouble(lua_State* state);
-int lua_AIMessage_getFloat(lua_State* state);
-int lua_AIMessage_getId(lua_State* state);
-int lua_AIMessage_getInt(lua_State* state);
-int lua_AIMessage_getLong(lua_State* state);
-int lua_AIMessage_getParameterCount(lua_State* state);
-int lua_AIMessage_getParameterType(lua_State* state);
-int lua_AIMessage_getReceiver(lua_State* state);
-int lua_AIMessage_getSender(lua_State* state);
-int lua_AIMessage_getString(lua_State* state);
-int lua_AIMessage_setBoolean(lua_State* state);
-int lua_AIMessage_setDouble(lua_State* state);
-int lua_AIMessage_setFloat(lua_State* state);
-int lua_AIMessage_setInt(lua_State* state);
-int lua_AIMessage_setLong(lua_State* state);
-int lua_AIMessage_setString(lua_State* state);
-int lua_AIMessage_static_create(lua_State* state);
-int lua_AIMessage_static_destroy(lua_State* state);
-
 void luaRegister_AIMessage();
 
 }

+ 77 - 27
gameplay/src/lua/lua_AIState.cpp

@@ -9,30 +9,12 @@
 #include "Game.h"
 #include "Node.h"
 #include "Ref.h"
+#include "Ref.h"
 
 namespace gameplay
 {
 
-void luaRegister_AIState()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_AIState_addRef},
-        {"getId", lua_AIState_getId},
-        {"getRefCount", lua_AIState_getRefCount},
-        {"release", lua_AIState_release},
-        {"setListener", lua_AIState_setListener},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"create", lua_AIState_static_create},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AIState", lua_members, NULL, lua_AIState__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static AIState* getInstance(lua_State* state)
 {
@@ -41,7 +23,7 @@ static AIState* getInstance(lua_State* state)
     return (AIState*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AIState__gc(lua_State* state)
+static int lua_AIState__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -79,7 +61,7 @@ int lua_AIState__gc(lua_State* state)
     return 0;
 }
 
-int lua_AIState_addRef(lua_State* state)
+static int lua_AIState_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -111,7 +93,7 @@ int lua_AIState_addRef(lua_State* state)
     return 0;
 }
 
-int lua_AIState_getId(lua_State* state)
+static int lua_AIState_getId(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -146,7 +128,7 @@ int lua_AIState_getId(lua_State* state)
     return 0;
 }
 
-int lua_AIState_getRefCount(lua_State* state)
+static int lua_AIState_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -181,7 +163,7 @@ int lua_AIState_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_AIState_release(lua_State* state)
+static int lua_AIState_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -213,7 +195,7 @@ int lua_AIState_release(lua_State* state)
     return 0;
 }
 
-int lua_AIState_setListener(lua_State* state)
+static int lua_AIState_setListener(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -255,7 +237,7 @@ int lua_AIState_setListener(lua_State* state)
     return 0;
 }
 
-int lua_AIState_static_create(lua_State* state)
+static int lua_AIState_static_create(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -301,4 +283,72 @@ int lua_AIState_static_create(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of AIState
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    AIState* ptrObject = reinterpret_cast<AIState*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_AIState_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_AIState_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    AIState* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_AIState()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_AIState_addRef},
+        {"getId", lua_AIState_getId},
+        {"getRefCount", lua_AIState_getRefCount},
+        {"release", lua_AIState_release},
+        {"setListener", lua_AIState_setListener},
+        {"to", lua_AIState_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"create", lua_AIState_static_create},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AIState", lua_members, NULL, lua_AIState__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("AIState", __convertTo);
+}
+
 }

+ 0 - 9
gameplay/src/lua/lua_AIState.h

@@ -5,15 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AIState.
-int lua_AIState__gc(lua_State* state);
-int lua_AIState_addRef(lua_State* state);
-int lua_AIState_getId(lua_State* state);
-int lua_AIState_getRefCount(lua_State* state);
-int lua_AIState_release(lua_State* state);
-int lua_AIState_setListener(lua_State* state);
-int lua_AIState_static_create(lua_State* state);
-
 void luaRegister_AIState();
 
 }

+ 22 - 21
gameplay/src/lua/lua_AIStateListener.cpp

@@ -13,22 +13,6 @@
 namespace gameplay
 {
 
-void luaRegister_AIStateListener()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"stateEnter", lua_AIStateListener_stateEnter},
-        {"stateExit", lua_AIStateListener_stateExit},
-        {"stateUpdate", lua_AIStateListener_stateUpdate},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-    scopePath.push_back("AIState");
-
-    gameplay::ScriptUtil::registerClass("AIStateListener", lua_members, lua_AIStateListener__init, lua_AIStateListener__gc, lua_statics, scopePath);
-}
-
 static AIState::Listener* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "AIStateListener");
@@ -36,7 +20,7 @@ static AIState::Listener* getInstance(lua_State* state)
     return (AIState::Listener*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AIStateListener__gc(lua_State* state)
+static int lua_AIStateListener__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -74,7 +58,7 @@ int lua_AIStateListener__gc(lua_State* state)
     return 0;
 }
 
-int lua_AIStateListener__init(lua_State* state)
+static int lua_AIStateListener__init(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -111,7 +95,7 @@ int lua_AIStateListener__init(lua_State* state)
     return 0;
 }
 
-int lua_AIStateListener_stateEnter(lua_State* state)
+static int lua_AIStateListener_stateEnter(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -163,7 +147,7 @@ int lua_AIStateListener_stateEnter(lua_State* state)
     return 0;
 }
 
-int lua_AIStateListener_stateExit(lua_State* state)
+static int lua_AIStateListener_stateExit(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -215,7 +199,7 @@ int lua_AIStateListener_stateExit(lua_State* state)
     return 0;
 }
 
-int lua_AIStateListener_stateUpdate(lua_State* state)
+static int lua_AIStateListener_stateUpdate(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -271,4 +255,21 @@ int lua_AIStateListener_stateUpdate(lua_State* state)
     return 0;
 }
 
+void luaRegister_AIStateListener()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"stateEnter", lua_AIStateListener_stateEnter},
+        {"stateExit", lua_AIStateListener_stateExit},
+        {"stateUpdate", lua_AIStateListener_stateUpdate},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+    scopePath.push_back("AIState");
+
+    gameplay::ScriptUtil::registerClass("AIStateListener", lua_members, lua_AIStateListener__init, lua_AIStateListener__gc, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 7
gameplay/src/lua/lua_AIStateListener.h

@@ -5,13 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AIState::Listener.
-int lua_AIStateListener__gc(lua_State* state);
-int lua_AIStateListener__init(lua_State* state);
-int lua_AIStateListener_stateEnter(lua_State* state);
-int lua_AIStateListener_stateExit(lua_State* state);
-int lua_AIStateListener_stateUpdate(lua_State* state);
-
 void luaRegister_AIStateListener();
 
 }

+ 25 - 24
gameplay/src/lua/lua_AIStateMachine.cpp

@@ -11,24 +11,6 @@
 namespace gameplay
 {
 
-void luaRegister_AIStateMachine()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addState", lua_AIStateMachine_addState},
-        {"getActiveState", lua_AIStateMachine_getActiveState},
-        {"getAgent", lua_AIStateMachine_getAgent},
-        {"getState", lua_AIStateMachine_getState},
-        {"removeState", lua_AIStateMachine_removeState},
-        {"setState", lua_AIStateMachine_setState},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AIStateMachine", lua_members, NULL, NULL, lua_statics, scopePath);
-}
-
 static AIStateMachine* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "AIStateMachine");
@@ -36,7 +18,7 @@ static AIStateMachine* getInstance(lua_State* state)
     return (AIStateMachine*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AIStateMachine_addState(lua_State* state)
+static int lua_AIStateMachine_addState(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -105,7 +87,7 @@ int lua_AIStateMachine_addState(lua_State* state)
     return 0;
 }
 
-int lua_AIStateMachine_getActiveState(lua_State* state)
+static int lua_AIStateMachine_getActiveState(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -149,7 +131,7 @@ int lua_AIStateMachine_getActiveState(lua_State* state)
     return 0;
 }
 
-int lua_AIStateMachine_getAgent(lua_State* state)
+static int lua_AIStateMachine_getAgent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -193,7 +175,7 @@ int lua_AIStateMachine_getAgent(lua_State* state)
     return 0;
 }
 
-int lua_AIStateMachine_getState(lua_State* state)
+static int lua_AIStateMachine_getState(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -241,7 +223,7 @@ int lua_AIStateMachine_getState(lua_State* state)
     return 0;
 }
 
-int lua_AIStateMachine_removeState(lua_State* state)
+static int lua_AIStateMachine_removeState(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -283,7 +265,7 @@ int lua_AIStateMachine_removeState(lua_State* state)
     return 0;
 }
 
-int lua_AIStateMachine_setState(lua_State* state)
+static int lua_AIStateMachine_setState(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -355,4 +337,23 @@ int lua_AIStateMachine_setState(lua_State* state)
     return 0;
 }
 
+void luaRegister_AIStateMachine()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addState", lua_AIStateMachine_addState},
+        {"getActiveState", lua_AIStateMachine_getActiveState},
+        {"getAgent", lua_AIStateMachine_getAgent},
+        {"getState", lua_AIStateMachine_getState},
+        {"removeState", lua_AIStateMachine_removeState},
+        {"setState", lua_AIStateMachine_setState},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AIStateMachine", lua_members, NULL, NULL, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 8
gameplay/src/lua/lua_AIStateMachine.h

@@ -5,14 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AIStateMachine.
-int lua_AIStateMachine_addState(lua_State* state);
-int lua_AIStateMachine_getActiveState(lua_State* state);
-int lua_AIStateMachine_getAgent(lua_State* state);
-int lua_AIStateMachine_getState(lua_State* state);
-int lua_AIStateMachine_removeState(lua_State* state);
-int lua_AIStateMachine_setState(lua_State* state);
-
 void luaRegister_AIStateMachine();
 
 }

+ 70 - 20
gameplay/src/lua/lua_AbsoluteLayout.cpp

@@ -9,25 +9,12 @@
 #include "Game.h"
 #include "Layout.h"
 #include "Ref.h"
+#include "Layout.h"
 
 namespace gameplay
 {
 
-void luaRegister_AbsoluteLayout()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_AbsoluteLayout_addRef},
-        {"getRefCount", lua_AbsoluteLayout_getRefCount},
-        {"getType", lua_AbsoluteLayout_getType},
-        {"release", lua_AbsoluteLayout_release},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AbsoluteLayout", lua_members, NULL, lua_AbsoluteLayout__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static AbsoluteLayout* getInstance(lua_State* state)
 {
@@ -36,7 +23,7 @@ static AbsoluteLayout* getInstance(lua_State* state)
     return (AbsoluteLayout*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AbsoluteLayout__gc(lua_State* state)
+static int lua_AbsoluteLayout__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -74,7 +61,7 @@ int lua_AbsoluteLayout__gc(lua_State* state)
     return 0;
 }
 
-int lua_AbsoluteLayout_addRef(lua_State* state)
+static int lua_AbsoluteLayout_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -106,7 +93,7 @@ int lua_AbsoluteLayout_addRef(lua_State* state)
     return 0;
 }
 
-int lua_AbsoluteLayout_getRefCount(lua_State* state)
+static int lua_AbsoluteLayout_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -141,7 +128,7 @@ int lua_AbsoluteLayout_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_AbsoluteLayout_getType(lua_State* state)
+static int lua_AbsoluteLayout_getType(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -176,7 +163,7 @@ int lua_AbsoluteLayout_getType(lua_State* state)
     return 0;
 }
 
-int lua_AbsoluteLayout_release(lua_State* state)
+static int lua_AbsoluteLayout_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -208,4 +195,67 @@ int lua_AbsoluteLayout_release(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of AbsoluteLayout
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    AbsoluteLayout* ptrObject = reinterpret_cast<AbsoluteLayout*>(ptr);
+
+    if (strcmp(typeName, "Layout") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Layout*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_AbsoluteLayout_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_AbsoluteLayout_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    AbsoluteLayout* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_AbsoluteLayout()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_AbsoluteLayout_addRef},
+        {"getRefCount", lua_AbsoluteLayout_getRefCount},
+        {"getType", lua_AbsoluteLayout_getType},
+        {"release", lua_AbsoluteLayout_release},
+        {"to", lua_AbsoluteLayout_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AbsoluteLayout", lua_members, NULL, lua_AbsoluteLayout__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("AbsoluteLayout", __convertTo);
+}
+
 }

+ 0 - 7
gameplay/src/lua/lua_AbsoluteLayout.h

@@ -5,13 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AbsoluteLayout.
-int lua_AbsoluteLayout__gc(lua_State* state);
-int lua_AbsoluteLayout_addRef(lua_State* state);
-int lua_AbsoluteLayout_getRefCount(lua_State* state);
-int lua_AbsoluteLayout_getType(lua_State* state);
-int lua_AbsoluteLayout_release(lua_State* state);
-
 void luaRegister_AbsoluteLayout();
 
 }

+ 88 - 38
gameplay/src/lua/lua_Animation.cpp

@@ -11,34 +11,12 @@
 #include "Properties.h"
 #include "Ref.h"
 #include "Transform.h"
+#include "Ref.h"
 
 namespace gameplay
 {
 
-void luaRegister_Animation()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_Animation_addRef},
-        {"createClip", lua_Animation_createClip},
-        {"createClips", lua_Animation_createClips},
-        {"getClip", lua_Animation_getClip},
-        {"getClipCount", lua_Animation_getClipCount},
-        {"getDuration", lua_Animation_getDuration},
-        {"getId", lua_Animation_getId},
-        {"getRefCount", lua_Animation_getRefCount},
-        {"pause", lua_Animation_pause},
-        {"play", lua_Animation_play},
-        {"release", lua_Animation_release},
-        {"stop", lua_Animation_stop},
-        {"targets", lua_Animation_targets},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("Animation", lua_members, NULL, lua_Animation__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static Animation* getInstance(lua_State* state)
 {
@@ -47,7 +25,7 @@ static Animation* getInstance(lua_State* state)
     return (Animation*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_Animation__gc(lua_State* state)
+static int lua_Animation__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -85,7 +63,7 @@ int lua_Animation__gc(lua_State* state)
     return 0;
 }
 
-int lua_Animation_addRef(lua_State* state)
+static int lua_Animation_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -117,7 +95,7 @@ int lua_Animation_addRef(lua_State* state)
     return 0;
 }
 
-int lua_Animation_createClip(lua_State* state)
+static int lua_Animation_createClip(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -173,7 +151,7 @@ int lua_Animation_createClip(lua_State* state)
     return 0;
 }
 
-int lua_Animation_createClips(lua_State* state)
+static int lua_Animation_createClips(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -209,7 +187,7 @@ int lua_Animation_createClips(lua_State* state)
     return 0;
 }
 
-int lua_Animation_getClip(lua_State* state)
+static int lua_Animation_getClip(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -316,7 +294,7 @@ int lua_Animation_getClip(lua_State* state)
     return 0;
 }
 
-int lua_Animation_getClipCount(lua_State* state)
+static int lua_Animation_getClipCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -351,7 +329,7 @@ int lua_Animation_getClipCount(lua_State* state)
     return 0;
 }
 
-int lua_Animation_getDuration(lua_State* state)
+static int lua_Animation_getDuration(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -386,7 +364,7 @@ int lua_Animation_getDuration(lua_State* state)
     return 0;
 }
 
-int lua_Animation_getId(lua_State* state)
+static int lua_Animation_getId(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -421,7 +399,7 @@ int lua_Animation_getId(lua_State* state)
     return 0;
 }
 
-int lua_Animation_getRefCount(lua_State* state)
+static int lua_Animation_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -456,7 +434,7 @@ int lua_Animation_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_Animation_pause(lua_State* state)
+static int lua_Animation_pause(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -506,7 +484,7 @@ int lua_Animation_pause(lua_State* state)
     return 0;
 }
 
-int lua_Animation_play(lua_State* state)
+static int lua_Animation_play(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -556,7 +534,7 @@ int lua_Animation_play(lua_State* state)
     return 0;
 }
 
-int lua_Animation_release(lua_State* state)
+static int lua_Animation_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -588,7 +566,7 @@ int lua_Animation_release(lua_State* state)
     return 0;
 }
 
-int lua_Animation_stop(lua_State* state)
+static int lua_Animation_stop(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -638,7 +616,7 @@ int lua_Animation_stop(lua_State* state)
     return 0;
 }
 
-int lua_Animation_targets(lua_State* state)
+static int lua_Animation_targets(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -683,4 +661,76 @@ int lua_Animation_targets(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of Animation
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    Animation* ptrObject = reinterpret_cast<Animation*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_Animation_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_Animation_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    Animation* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_Animation()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_Animation_addRef},
+        {"createClip", lua_Animation_createClip},
+        {"createClips", lua_Animation_createClips},
+        {"getClip", lua_Animation_getClip},
+        {"getClipCount", lua_Animation_getClipCount},
+        {"getDuration", lua_Animation_getDuration},
+        {"getId", lua_Animation_getId},
+        {"getRefCount", lua_Animation_getRefCount},
+        {"pause", lua_Animation_pause},
+        {"play", lua_Animation_play},
+        {"release", lua_Animation_release},
+        {"stop", lua_Animation_stop},
+        {"targets", lua_Animation_targets},
+        {"to", lua_Animation_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("Animation", lua_members, NULL, lua_Animation__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("Animation", __convertTo);
+}
+
 }

+ 0 - 16
gameplay/src/lua/lua_Animation.h

@@ -5,22 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Animation.
-int lua_Animation__gc(lua_State* state);
-int lua_Animation_addRef(lua_State* state);
-int lua_Animation_createClip(lua_State* state);
-int lua_Animation_createClips(lua_State* state);
-int lua_Animation_getClip(lua_State* state);
-int lua_Animation_getClipCount(lua_State* state);
-int lua_Animation_getDuration(lua_State* state);
-int lua_Animation_getId(lua_State* state);
-int lua_Animation_getRefCount(lua_State* state);
-int lua_Animation_pause(lua_State* state);
-int lua_Animation_play(lua_State* state);
-int lua_Animation_release(lua_State* state);
-int lua_Animation_stop(lua_State* state);
-int lua_Animation_targets(lua_State* state);
-
 void luaRegister_Animation();
 
 }

+ 148 - 93
gameplay/src/lua/lua_AnimationClip.cpp

@@ -11,63 +11,13 @@
 #include "Ref.h"
 #include "ScriptController.h"
 #include "ScriptTarget.h"
+#include "Ref.h"
+#include "ScriptTarget.h"
 
 namespace gameplay
 {
 
-void luaRegister_AnimationClip()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addBeginListener", lua_AnimationClip_addBeginListener},
-        {"addEndListener", lua_AnimationClip_addEndListener},
-        {"addListener", lua_AnimationClip_addListener},
-        {"addRef", lua_AnimationClip_addRef},
-        {"addScript", lua_AnimationClip_addScript},
-        {"addScriptCallback", lua_AnimationClip_addScriptCallback},
-        {"clearScripts", lua_AnimationClip_clearScripts},
-        {"crossFade", lua_AnimationClip_crossFade},
-        {"getActiveDuration", lua_AnimationClip_getActiveDuration},
-        {"getAnimation", lua_AnimationClip_getAnimation},
-        {"getBlendWeight", lua_AnimationClip_getBlendWeight},
-        {"getDuration", lua_AnimationClip_getDuration},
-        {"getElapsedTime", lua_AnimationClip_getElapsedTime},
-        {"getEndTime", lua_AnimationClip_getEndTime},
-        {"getId", lua_AnimationClip_getId},
-        {"getLoopBlendTime", lua_AnimationClip_getLoopBlendTime},
-        {"getRefCount", lua_AnimationClip_getRefCount},
-        {"getRepeatCount", lua_AnimationClip_getRepeatCount},
-        {"getScriptEvent", lua_AnimationClip_getScriptEvent},
-        {"getSpeed", lua_AnimationClip_getSpeed},
-        {"getStartTime", lua_AnimationClip_getStartTime},
-        {"getTypeName", lua_AnimationClip_getTypeName},
-        {"hasScriptListener", lua_AnimationClip_hasScriptListener},
-        {"isPlaying", lua_AnimationClip_isPlaying},
-        {"pause", lua_AnimationClip_pause},
-        {"play", lua_AnimationClip_play},
-        {"release", lua_AnimationClip_release},
-        {"removeBeginListener", lua_AnimationClip_removeBeginListener},
-        {"removeEndListener", lua_AnimationClip_removeEndListener},
-        {"removeListener", lua_AnimationClip_removeListener},
-        {"removeScript", lua_AnimationClip_removeScript},
-        {"removeScriptCallback", lua_AnimationClip_removeScriptCallback},
-        {"setActiveDuration", lua_AnimationClip_setActiveDuration},
-        {"setBlendWeight", lua_AnimationClip_setBlendWeight},
-        {"setLoopBlendTime", lua_AnimationClip_setLoopBlendTime},
-        {"setRepeatCount", lua_AnimationClip_setRepeatCount},
-        {"setSpeed", lua_AnimationClip_setSpeed},
-        {"stop", lua_AnimationClip_stop},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"REPEAT_INDEFINITE", lua_AnimationClip_static_REPEAT_INDEFINITE},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AnimationClip", lua_members, NULL, lua_AnimationClip__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static AnimationClip* getInstance(lua_State* state)
 {
@@ -76,7 +26,7 @@ static AnimationClip* getInstance(lua_State* state)
     return (AnimationClip*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AnimationClip__gc(lua_State* state)
+static int lua_AnimationClip__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -114,7 +64,7 @@ int lua_AnimationClip__gc(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_addBeginListener(lua_State* state)
+static int lua_AnimationClip_addBeginListener(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -156,7 +106,7 @@ int lua_AnimationClip_addBeginListener(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_addEndListener(lua_State* state)
+static int lua_AnimationClip_addEndListener(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -198,7 +148,7 @@ int lua_AnimationClip_addEndListener(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_addListener(lua_State* state)
+static int lua_AnimationClip_addListener(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -244,7 +194,7 @@ int lua_AnimationClip_addListener(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_addRef(lua_State* state)
+static int lua_AnimationClip_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -276,7 +226,7 @@ int lua_AnimationClip_addRef(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_addScript(lua_State* state)
+static int lua_AnimationClip_addScript(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -324,7 +274,7 @@ int lua_AnimationClip_addScript(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_addScriptCallback(lua_State* state)
+static int lua_AnimationClip_addScriptCallback(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -370,7 +320,7 @@ int lua_AnimationClip_addScriptCallback(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_clearScripts(lua_State* state)
+static int lua_AnimationClip_clearScripts(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -402,7 +352,7 @@ int lua_AnimationClip_clearScripts(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_crossFade(lua_State* state)
+static int lua_AnimationClip_crossFade(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -448,7 +398,7 @@ int lua_AnimationClip_crossFade(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getActiveDuration(lua_State* state)
+static int lua_AnimationClip_getActiveDuration(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -483,7 +433,7 @@ int lua_AnimationClip_getActiveDuration(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getAnimation(lua_State* state)
+static int lua_AnimationClip_getAnimation(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -527,7 +477,7 @@ int lua_AnimationClip_getAnimation(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getBlendWeight(lua_State* state)
+static int lua_AnimationClip_getBlendWeight(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -562,7 +512,7 @@ int lua_AnimationClip_getBlendWeight(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getDuration(lua_State* state)
+static int lua_AnimationClip_getDuration(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -597,7 +547,7 @@ int lua_AnimationClip_getDuration(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getElapsedTime(lua_State* state)
+static int lua_AnimationClip_getElapsedTime(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -632,7 +582,7 @@ int lua_AnimationClip_getElapsedTime(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getEndTime(lua_State* state)
+static int lua_AnimationClip_getEndTime(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -667,7 +617,7 @@ int lua_AnimationClip_getEndTime(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getId(lua_State* state)
+static int lua_AnimationClip_getId(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -702,7 +652,7 @@ int lua_AnimationClip_getId(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getLoopBlendTime(lua_State* state)
+static int lua_AnimationClip_getLoopBlendTime(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -737,7 +687,7 @@ int lua_AnimationClip_getLoopBlendTime(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getRefCount(lua_State* state)
+static int lua_AnimationClip_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -772,7 +722,7 @@ int lua_AnimationClip_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getRepeatCount(lua_State* state)
+static int lua_AnimationClip_getRepeatCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -807,7 +757,7 @@ int lua_AnimationClip_getRepeatCount(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getScriptEvent(lua_State* state)
+static int lua_AnimationClip_getScriptEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -855,7 +805,7 @@ int lua_AnimationClip_getScriptEvent(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getSpeed(lua_State* state)
+static int lua_AnimationClip_getSpeed(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -890,7 +840,7 @@ int lua_AnimationClip_getSpeed(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getStartTime(lua_State* state)
+static int lua_AnimationClip_getStartTime(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -925,7 +875,7 @@ int lua_AnimationClip_getStartTime(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getTypeName(lua_State* state)
+static int lua_AnimationClip_getTypeName(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -960,7 +910,7 @@ int lua_AnimationClip_getTypeName(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_hasScriptListener(lua_State* state)
+static int lua_AnimationClip_hasScriptListener(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1023,7 +973,7 @@ int lua_AnimationClip_hasScriptListener(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_isPlaying(lua_State* state)
+static int lua_AnimationClip_isPlaying(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1058,7 +1008,7 @@ int lua_AnimationClip_isPlaying(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_pause(lua_State* state)
+static int lua_AnimationClip_pause(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1090,7 +1040,7 @@ int lua_AnimationClip_pause(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_play(lua_State* state)
+static int lua_AnimationClip_play(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1122,7 +1072,7 @@ int lua_AnimationClip_play(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_release(lua_State* state)
+static int lua_AnimationClip_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1154,7 +1104,7 @@ int lua_AnimationClip_release(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_removeBeginListener(lua_State* state)
+static int lua_AnimationClip_removeBeginListener(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1196,7 +1146,7 @@ int lua_AnimationClip_removeBeginListener(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_removeEndListener(lua_State* state)
+static int lua_AnimationClip_removeEndListener(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1238,7 +1188,7 @@ int lua_AnimationClip_removeEndListener(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_removeListener(lua_State* state)
+static int lua_AnimationClip_removeListener(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1284,7 +1234,7 @@ int lua_AnimationClip_removeListener(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_removeScript(lua_State* state)
+static int lua_AnimationClip_removeScript(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1323,7 +1273,7 @@ int lua_AnimationClip_removeScript(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_removeScriptCallback(lua_State* state)
+static int lua_AnimationClip_removeScriptCallback(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1369,7 +1319,7 @@ int lua_AnimationClip_removeScriptCallback(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_setActiveDuration(lua_State* state)
+static int lua_AnimationClip_setActiveDuration(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1405,7 +1355,7 @@ int lua_AnimationClip_setActiveDuration(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_setBlendWeight(lua_State* state)
+static int lua_AnimationClip_setBlendWeight(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1441,7 +1391,7 @@ int lua_AnimationClip_setBlendWeight(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_setLoopBlendTime(lua_State* state)
+static int lua_AnimationClip_setLoopBlendTime(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1477,7 +1427,7 @@ int lua_AnimationClip_setLoopBlendTime(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_setRepeatCount(lua_State* state)
+static int lua_AnimationClip_setRepeatCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1513,7 +1463,7 @@ int lua_AnimationClip_setRepeatCount(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_setSpeed(lua_State* state)
+static int lua_AnimationClip_setSpeed(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1549,7 +1499,7 @@ int lua_AnimationClip_setSpeed(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_static_REPEAT_INDEFINITE(lua_State* state)
+static int lua_AnimationClip_static_REPEAT_INDEFINITE(lua_State* state)
 {
     // Validate the number of parameters.
     if (lua_gettop(state) > 0)
@@ -1566,7 +1516,7 @@ int lua_AnimationClip_static_REPEAT_INDEFINITE(lua_State* state)
     return 1;
 }
 
-int lua_AnimationClip_stop(lua_State* state)
+static int lua_AnimationClip_stop(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1598,4 +1548,109 @@ int lua_AnimationClip_stop(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of AnimationClip
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    AnimationClip* ptrObject = reinterpret_cast<AnimationClip*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+    else if (strcmp(typeName, "ScriptTarget") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<ScriptTarget*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_AnimationClip_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_AnimationClip_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    AnimationClip* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_AnimationClip()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addBeginListener", lua_AnimationClip_addBeginListener},
+        {"addEndListener", lua_AnimationClip_addEndListener},
+        {"addListener", lua_AnimationClip_addListener},
+        {"addRef", lua_AnimationClip_addRef},
+        {"addScript", lua_AnimationClip_addScript},
+        {"addScriptCallback", lua_AnimationClip_addScriptCallback},
+        {"clearScripts", lua_AnimationClip_clearScripts},
+        {"crossFade", lua_AnimationClip_crossFade},
+        {"getActiveDuration", lua_AnimationClip_getActiveDuration},
+        {"getAnimation", lua_AnimationClip_getAnimation},
+        {"getBlendWeight", lua_AnimationClip_getBlendWeight},
+        {"getDuration", lua_AnimationClip_getDuration},
+        {"getElapsedTime", lua_AnimationClip_getElapsedTime},
+        {"getEndTime", lua_AnimationClip_getEndTime},
+        {"getId", lua_AnimationClip_getId},
+        {"getLoopBlendTime", lua_AnimationClip_getLoopBlendTime},
+        {"getRefCount", lua_AnimationClip_getRefCount},
+        {"getRepeatCount", lua_AnimationClip_getRepeatCount},
+        {"getScriptEvent", lua_AnimationClip_getScriptEvent},
+        {"getSpeed", lua_AnimationClip_getSpeed},
+        {"getStartTime", lua_AnimationClip_getStartTime},
+        {"getTypeName", lua_AnimationClip_getTypeName},
+        {"hasScriptListener", lua_AnimationClip_hasScriptListener},
+        {"isPlaying", lua_AnimationClip_isPlaying},
+        {"pause", lua_AnimationClip_pause},
+        {"play", lua_AnimationClip_play},
+        {"release", lua_AnimationClip_release},
+        {"removeBeginListener", lua_AnimationClip_removeBeginListener},
+        {"removeEndListener", lua_AnimationClip_removeEndListener},
+        {"removeListener", lua_AnimationClip_removeListener},
+        {"removeScript", lua_AnimationClip_removeScript},
+        {"removeScriptCallback", lua_AnimationClip_removeScriptCallback},
+        {"setActiveDuration", lua_AnimationClip_setActiveDuration},
+        {"setBlendWeight", lua_AnimationClip_setBlendWeight},
+        {"setLoopBlendTime", lua_AnimationClip_setLoopBlendTime},
+        {"setRepeatCount", lua_AnimationClip_setRepeatCount},
+        {"setSpeed", lua_AnimationClip_setSpeed},
+        {"stop", lua_AnimationClip_stop},
+        {"to", lua_AnimationClip_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"REPEAT_INDEFINITE", lua_AnimationClip_static_REPEAT_INDEFINITE},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AnimationClip", lua_members, NULL, lua_AnimationClip__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("AnimationClip", __convertTo);
+}
+
 }

+ 0 - 42
gameplay/src/lua/lua_AnimationClip.h

@@ -5,48 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AnimationClip.
-int lua_AnimationClip__gc(lua_State* state);
-int lua_AnimationClip_addBeginListener(lua_State* state);
-int lua_AnimationClip_addEndListener(lua_State* state);
-int lua_AnimationClip_addListener(lua_State* state);
-int lua_AnimationClip_addRef(lua_State* state);
-int lua_AnimationClip_addScript(lua_State* state);
-int lua_AnimationClip_addScriptCallback(lua_State* state);
-int lua_AnimationClip_clearScripts(lua_State* state);
-int lua_AnimationClip_crossFade(lua_State* state);
-int lua_AnimationClip_getActiveDuration(lua_State* state);
-int lua_AnimationClip_getAnimation(lua_State* state);
-int lua_AnimationClip_getBlendWeight(lua_State* state);
-int lua_AnimationClip_getDuration(lua_State* state);
-int lua_AnimationClip_getElapsedTime(lua_State* state);
-int lua_AnimationClip_getEndTime(lua_State* state);
-int lua_AnimationClip_getId(lua_State* state);
-int lua_AnimationClip_getLoopBlendTime(lua_State* state);
-int lua_AnimationClip_getRefCount(lua_State* state);
-int lua_AnimationClip_getRepeatCount(lua_State* state);
-int lua_AnimationClip_getScriptEvent(lua_State* state);
-int lua_AnimationClip_getSpeed(lua_State* state);
-int lua_AnimationClip_getStartTime(lua_State* state);
-int lua_AnimationClip_getTypeName(lua_State* state);
-int lua_AnimationClip_hasScriptListener(lua_State* state);
-int lua_AnimationClip_isPlaying(lua_State* state);
-int lua_AnimationClip_pause(lua_State* state);
-int lua_AnimationClip_play(lua_State* state);
-int lua_AnimationClip_release(lua_State* state);
-int lua_AnimationClip_removeBeginListener(lua_State* state);
-int lua_AnimationClip_removeEndListener(lua_State* state);
-int lua_AnimationClip_removeListener(lua_State* state);
-int lua_AnimationClip_removeScript(lua_State* state);
-int lua_AnimationClip_removeScriptCallback(lua_State* state);
-int lua_AnimationClip_setActiveDuration(lua_State* state);
-int lua_AnimationClip_setBlendWeight(lua_State* state);
-int lua_AnimationClip_setLoopBlendTime(lua_State* state);
-int lua_AnimationClip_setRepeatCount(lua_State* state);
-int lua_AnimationClip_setSpeed(lua_State* state);
-int lua_AnimationClip_static_REPEAT_INDEFINITE(lua_State* state);
-int lua_AnimationClip_stop(lua_State* state);
-
 void luaRegister_AnimationClip();
 
 }

+ 17 - 16
gameplay/src/lua/lua_AnimationClipListener.cpp

@@ -15,20 +15,6 @@
 namespace gameplay
 {
 
-void luaRegister_AnimationClipListener()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"animationEvent", lua_AnimationClipListener_animationEvent},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-    scopePath.push_back("AnimationClip");
-
-    gameplay::ScriptUtil::registerClass("AnimationClipListener", lua_members, NULL, lua_AnimationClipListener__gc, lua_statics, scopePath);
-}
-
 static AnimationClip::Listener* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "AnimationClipListener");
@@ -36,7 +22,7 @@ static AnimationClip::Listener* getInstance(lua_State* state)
     return (AnimationClip::Listener*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AnimationClipListener__gc(lua_State* state)
+static int lua_AnimationClipListener__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -74,7 +60,7 @@ int lua_AnimationClipListener__gc(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClipListener_animationEvent(lua_State* state)
+static int lua_AnimationClipListener_animationEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -120,4 +106,19 @@ int lua_AnimationClipListener_animationEvent(lua_State* state)
     return 0;
 }
 
+void luaRegister_AnimationClipListener()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"animationEvent", lua_AnimationClipListener_animationEvent},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+    scopePath.push_back("AnimationClip");
+
+    gameplay::ScriptUtil::registerClass("AnimationClipListener", lua_members, NULL, lua_AnimationClipListener__gc, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 4
gameplay/src/lua/lua_AnimationClipListener.h

@@ -5,10 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AnimationClip::Listener.
-int lua_AnimationClipListener__gc(lua_State* state);
-int lua_AnimationClipListener_animationEvent(lua_State* state);
-
 void luaRegister_AnimationClipListener();
 
 }

+ 15 - 14
gameplay/src/lua/lua_AnimationController.cpp

@@ -10,19 +10,6 @@
 namespace gameplay
 {
 
-void luaRegister_AnimationController()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"stopAllAnimations", lua_AnimationController_stopAllAnimations},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AnimationController", lua_members, NULL, NULL, lua_statics, scopePath);
-}
-
 static AnimationController* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "AnimationController");
@@ -30,7 +17,7 @@ static AnimationController* getInstance(lua_State* state)
     return (AnimationController*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AnimationController_stopAllAnimations(lua_State* state)
+static int lua_AnimationController_stopAllAnimations(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -62,4 +49,18 @@ int lua_AnimationController_stopAllAnimations(lua_State* state)
     return 0;
 }
 
+void luaRegister_AnimationController()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"stopAllAnimations", lua_AnimationController_stopAllAnimations},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AnimationController", lua_members, NULL, NULL, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 3
gameplay/src/lua/lua_AnimationController.h

@@ -5,9 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AnimationController.
-int lua_AnimationController_stopAllAnimations(lua_State* state);
-
 void luaRegister_AnimationController();
 
 }

+ 112 - 27
gameplay/src/lua/lua_AnimationTarget.cpp

@@ -5,32 +5,34 @@
 #include "Animation.h"
 #include "AnimationTarget.h"
 #include "Base.h"
+#include "Button.h"
+#include "CheckBox.h"
+#include "Container.h"
+#include "Control.h"
+#include "Form.h"
 #include "Game.h"
+#include "ImageControl.h"
+#include "Joint.h"
+#include "JoystickControl.h"
+#include "Label.h"
 #include "MaterialParameter.h"
 #include "Node.h"
+#include "RadioButton.h"
+#include "Slider.h"
+#include "Sprite.h"
+#include "Text.h"
+#include "TextBox.h"
+#include "Transform.h"
+#include "Control.h"
+#include "MaterialParameter.h"
+#include "Sprite.h"
+#include "Text.h"
+#include "Transform.h"
 
 namespace gameplay
 {
 
-void luaRegister_AnimationTarget()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"createAnimation", lua_AnimationTarget_createAnimation},
-        {"createAnimationFromBy", lua_AnimationTarget_createAnimationFromBy},
-        {"createAnimationFromTo", lua_AnimationTarget_createAnimationFromTo},
-        {"destroyAnimation", lua_AnimationTarget_destroyAnimation},
-        {"getAnimation", lua_AnimationTarget_getAnimation},
-        {"getAnimationPropertyComponentCount", lua_AnimationTarget_getAnimationPropertyComponentCount},
-        {"getAnimationPropertyValue", lua_AnimationTarget_getAnimationPropertyValue},
-        {"setAnimationPropertyValue", lua_AnimationTarget_setAnimationPropertyValue},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AnimationTarget", lua_members, NULL, NULL, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static AnimationTarget* getInstance(lua_State* state)
 {
@@ -39,7 +41,7 @@ static AnimationTarget* getInstance(lua_State* state)
     return (AnimationTarget*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AnimationTarget_createAnimation(lua_State* state)
+static int lua_AnimationTarget_createAnimation(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -242,7 +244,7 @@ int lua_AnimationTarget_createAnimation(lua_State* state)
     return 0;
 }
 
-int lua_AnimationTarget_createAnimationFromBy(lua_State* state)
+static int lua_AnimationTarget_createAnimationFromBy(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -310,7 +312,7 @@ int lua_AnimationTarget_createAnimationFromBy(lua_State* state)
     return 0;
 }
 
-int lua_AnimationTarget_createAnimationFromTo(lua_State* state)
+static int lua_AnimationTarget_createAnimationFromTo(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -378,7 +380,7 @@ int lua_AnimationTarget_createAnimationFromTo(lua_State* state)
     return 0;
 }
 
-int lua_AnimationTarget_destroyAnimation(lua_State* state)
+static int lua_AnimationTarget_destroyAnimation(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -428,7 +430,7 @@ int lua_AnimationTarget_destroyAnimation(lua_State* state)
     return 0;
 }
 
-int lua_AnimationTarget_getAnimation(lua_State* state)
+static int lua_AnimationTarget_getAnimation(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -502,7 +504,7 @@ int lua_AnimationTarget_getAnimation(lua_State* state)
     return 0;
 }
 
-int lua_AnimationTarget_getAnimationPropertyComponentCount(lua_State* state)
+static int lua_AnimationTarget_getAnimationPropertyComponentCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -541,7 +543,7 @@ int lua_AnimationTarget_getAnimationPropertyComponentCount(lua_State* state)
     return 0;
 }
 
-int lua_AnimationTarget_getAnimationPropertyValue(lua_State* state)
+static int lua_AnimationTarget_getAnimationPropertyValue(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -587,7 +589,7 @@ int lua_AnimationTarget_getAnimationPropertyValue(lua_State* state)
     return 0;
 }
 
-int lua_AnimationTarget_setAnimationPropertyValue(lua_State* state)
+static int lua_AnimationTarget_setAnimationPropertyValue(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -665,4 +667,87 @@ int lua_AnimationTarget_setAnimationPropertyValue(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of AnimationTarget
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    AnimationTarget* ptrObject = reinterpret_cast<AnimationTarget*>(ptr);
+
+    if (strcmp(typeName, "Control") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Control*>(ptrObject));
+    }
+    else if (strcmp(typeName, "MaterialParameter") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<MaterialParameter*>(ptrObject));
+    }
+    else if (strcmp(typeName, "Sprite") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Sprite*>(ptrObject));
+    }
+    else if (strcmp(typeName, "Text") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Text*>(ptrObject));
+    }
+    else if (strcmp(typeName, "Transform") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Transform*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_AnimationTarget_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_AnimationTarget_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    AnimationTarget* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_AnimationTarget()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"createAnimation", lua_AnimationTarget_createAnimation},
+        {"createAnimationFromBy", lua_AnimationTarget_createAnimationFromBy},
+        {"createAnimationFromTo", lua_AnimationTarget_createAnimationFromTo},
+        {"destroyAnimation", lua_AnimationTarget_destroyAnimation},
+        {"getAnimation", lua_AnimationTarget_getAnimation},
+        {"getAnimationPropertyComponentCount", lua_AnimationTarget_getAnimationPropertyComponentCount},
+        {"getAnimationPropertyValue", lua_AnimationTarget_getAnimationPropertyValue},
+        {"setAnimationPropertyValue", lua_AnimationTarget_setAnimationPropertyValue},
+        {"to", lua_AnimationTarget_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AnimationTarget", lua_members, NULL, NULL, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("AnimationTarget", __convertTo);
+}
+
 }

+ 0 - 10
gameplay/src/lua/lua_AnimationTarget.h

@@ -5,16 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AnimationTarget.
-int lua_AnimationTarget_createAnimation(lua_State* state);
-int lua_AnimationTarget_createAnimationFromBy(lua_State* state);
-int lua_AnimationTarget_createAnimationFromTo(lua_State* state);
-int lua_AnimationTarget_destroyAnimation(lua_State* state);
-int lua_AnimationTarget_getAnimation(lua_State* state);
-int lua_AnimationTarget_getAnimationPropertyComponentCount(lua_State* state);
-int lua_AnimationTarget_getAnimationPropertyValue(lua_State* state);
-int lua_AnimationTarget_setAnimationPropertyValue(lua_State* state);
-
 void luaRegister_AnimationTarget();
 
 }

+ 21 - 20
gameplay/src/lua/lua_AnimationValue.cpp

@@ -8,22 +8,6 @@
 namespace gameplay
 {
 
-void luaRegister_AnimationValue()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"getFloat", lua_AnimationValue_getFloat},
-        {"getFloats", lua_AnimationValue_getFloats},
-        {"setFloat", lua_AnimationValue_setFloat},
-        {"setFloats", lua_AnimationValue_setFloats},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AnimationValue", lua_members, NULL, NULL, lua_statics, scopePath);
-}
-
 static AnimationValue* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "AnimationValue");
@@ -31,7 +15,7 @@ static AnimationValue* getInstance(lua_State* state)
     return (AnimationValue*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AnimationValue_getFloat(lua_State* state)
+static int lua_AnimationValue_getFloat(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -70,7 +54,7 @@ int lua_AnimationValue_getFloat(lua_State* state)
     return 0;
 }
 
-int lua_AnimationValue_getFloats(lua_State* state)
+static int lua_AnimationValue_getFloats(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -114,7 +98,7 @@ int lua_AnimationValue_getFloats(lua_State* state)
     return 0;
 }
 
-int lua_AnimationValue_setFloat(lua_State* state)
+static int lua_AnimationValue_setFloat(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -154,7 +138,7 @@ int lua_AnimationValue_setFloat(lua_State* state)
     return 0;
 }
 
-int lua_AnimationValue_setFloats(lua_State* state)
+static int lua_AnimationValue_setFloats(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -198,4 +182,21 @@ int lua_AnimationValue_setFloats(lua_State* state)
     return 0;
 }
 
+void luaRegister_AnimationValue()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"getFloat", lua_AnimationValue_getFloat},
+        {"getFloats", lua_AnimationValue_getFloats},
+        {"setFloat", lua_AnimationValue_setFloat},
+        {"setFloats", lua_AnimationValue_setFloats},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AnimationValue", lua_members, NULL, NULL, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 6
gameplay/src/lua/lua_AnimationValue.h

@@ -5,12 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AnimationValue.
-int lua_AnimationValue_getFloat(lua_State* state);
-int lua_AnimationValue_getFloats(lua_State* state);
-int lua_AnimationValue_setFloat(lua_State* state);
-int lua_AnimationValue_setFloats(lua_State* state);
-
 void luaRegister_AnimationValue();
 
 }

+ 68 - 18
gameplay/src/lua/lua_AudioBuffer.cpp

@@ -7,24 +7,12 @@
 #include "FileSystem.h"
 #include "Game.h"
 #include "Ref.h"
+#include "Ref.h"
 
 namespace gameplay
 {
 
-void luaRegister_AudioBuffer()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_AudioBuffer_addRef},
-        {"getRefCount", lua_AudioBuffer_getRefCount},
-        {"release", lua_AudioBuffer_release},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AudioBuffer", lua_members, NULL, lua_AudioBuffer__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static AudioBuffer* getInstance(lua_State* state)
 {
@@ -33,7 +21,7 @@ static AudioBuffer* getInstance(lua_State* state)
     return (AudioBuffer*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AudioBuffer__gc(lua_State* state)
+static int lua_AudioBuffer__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -71,7 +59,7 @@ int lua_AudioBuffer__gc(lua_State* state)
     return 0;
 }
 
-int lua_AudioBuffer_addRef(lua_State* state)
+static int lua_AudioBuffer_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -103,7 +91,7 @@ int lua_AudioBuffer_addRef(lua_State* state)
     return 0;
 }
 
-int lua_AudioBuffer_getRefCount(lua_State* state)
+static int lua_AudioBuffer_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -138,7 +126,7 @@ int lua_AudioBuffer_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_AudioBuffer_release(lua_State* state)
+static int lua_AudioBuffer_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -170,4 +158,66 @@ int lua_AudioBuffer_release(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of AudioBuffer
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    AudioBuffer* ptrObject = reinterpret_cast<AudioBuffer*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_AudioBuffer_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_AudioBuffer_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    AudioBuffer* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_AudioBuffer()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_AudioBuffer_addRef},
+        {"getRefCount", lua_AudioBuffer_getRefCount},
+        {"release", lua_AudioBuffer_release},
+        {"to", lua_AudioBuffer_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AudioBuffer", lua_members, NULL, lua_AudioBuffer__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("AudioBuffer", __convertTo);
+}
+
 }

+ 0 - 6
gameplay/src/lua/lua_AudioBuffer.h

@@ -5,12 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AudioBuffer.
-int lua_AudioBuffer__gc(lua_State* state);
-int lua_AudioBuffer_addRef(lua_State* state);
-int lua_AudioBuffer_getRefCount(lua_State* state);
-int lua_AudioBuffer_release(lua_State* state);
-
 void luaRegister_AudioBuffer();
 
 }

+ 14 - 13
gameplay/src/lua/lua_AudioController.cpp

@@ -11,18 +11,6 @@
 namespace gameplay
 {
 
-void luaRegister_AudioController()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AudioController", lua_members, NULL, lua_AudioController__gc, lua_statics, scopePath);
-}
-
 static AudioController* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "AudioController");
@@ -30,7 +18,7 @@ static AudioController* getInstance(lua_State* state)
     return (AudioController*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AudioController__gc(lua_State* state)
+static int lua_AudioController__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -68,4 +56,17 @@ int lua_AudioController__gc(lua_State* state)
     return 0;
 }
 
+void luaRegister_AudioController()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AudioController", lua_members, NULL, lua_AudioController__gc, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 3
gameplay/src/lua/lua_AudioController.h

@@ -5,9 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AudioController.
-int lua_AudioController__gc(lua_State* state);
-
 void luaRegister_AudioController();
 
 }

+ 88 - 38
gameplay/src/lua/lua_AudioListener.cpp

@@ -8,36 +8,12 @@
 #include "Game.h"
 #include "Node.h"
 #include "PhysicsController.h"
+#include "Camera.h"
 
 namespace gameplay
 {
 
-void luaRegister_AudioListener()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"getCamera", lua_AudioListener_getCamera},
-        {"getGain", lua_AudioListener_getGain},
-        {"getOrientationForward", lua_AudioListener_getOrientationForward},
-        {"getOrientationUp", lua_AudioListener_getOrientationUp},
-        {"getPosition", lua_AudioListener_getPosition},
-        {"getVelocity", lua_AudioListener_getVelocity},
-        {"setCamera", lua_AudioListener_setCamera},
-        {"setGain", lua_AudioListener_setGain},
-        {"setOrientation", lua_AudioListener_setOrientation},
-        {"setPosition", lua_AudioListener_setPosition},
-        {"setVelocity", lua_AudioListener_setVelocity},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"getInstance", lua_AudioListener_static_getInstance},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AudioListener", lua_members, NULL, NULL, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static AudioListener* getInstance(lua_State* state)
 {
@@ -46,7 +22,7 @@ static AudioListener* getInstance(lua_State* state)
     return (AudioListener*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AudioListener_getCamera(lua_State* state)
+static int lua_AudioListener_getCamera(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -90,7 +66,7 @@ int lua_AudioListener_getCamera(lua_State* state)
     return 0;
 }
 
-int lua_AudioListener_getGain(lua_State* state)
+static int lua_AudioListener_getGain(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -125,7 +101,7 @@ int lua_AudioListener_getGain(lua_State* state)
     return 0;
 }
 
-int lua_AudioListener_getOrientationForward(lua_State* state)
+static int lua_AudioListener_getOrientationForward(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -169,7 +145,7 @@ int lua_AudioListener_getOrientationForward(lua_State* state)
     return 0;
 }
 
-int lua_AudioListener_getOrientationUp(lua_State* state)
+static int lua_AudioListener_getOrientationUp(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -213,7 +189,7 @@ int lua_AudioListener_getOrientationUp(lua_State* state)
     return 0;
 }
 
-int lua_AudioListener_getPosition(lua_State* state)
+static int lua_AudioListener_getPosition(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -257,7 +233,7 @@ int lua_AudioListener_getPosition(lua_State* state)
     return 0;
 }
 
-int lua_AudioListener_getVelocity(lua_State* state)
+static int lua_AudioListener_getVelocity(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -301,7 +277,7 @@ int lua_AudioListener_getVelocity(lua_State* state)
     return 0;
 }
 
-int lua_AudioListener_setCamera(lua_State* state)
+static int lua_AudioListener_setCamera(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -343,7 +319,7 @@ int lua_AudioListener_setCamera(lua_State* state)
     return 0;
 }
 
-int lua_AudioListener_setGain(lua_State* state)
+static int lua_AudioListener_setGain(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -379,7 +355,7 @@ int lua_AudioListener_setGain(lua_State* state)
     return 0;
 }
 
-int lua_AudioListener_setOrientation(lua_State* state)
+static int lua_AudioListener_setOrientation(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -469,7 +445,7 @@ int lua_AudioListener_setOrientation(lua_State* state)
     return 0;
 }
 
-int lua_AudioListener_setPosition(lua_State* state)
+static int lua_AudioListener_setPosition(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -540,7 +516,7 @@ int lua_AudioListener_setPosition(lua_State* state)
     return 0;
 }
 
-int lua_AudioListener_setVelocity(lua_State* state)
+static int lua_AudioListener_setVelocity(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -611,7 +587,7 @@ int lua_AudioListener_setVelocity(lua_State* state)
     return 0;
 }
 
-int lua_AudioListener_static_getInstance(lua_State* state)
+static int lua_AudioListener_static_getInstance(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -648,4 +624,78 @@ int lua_AudioListener_static_getInstance(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of AudioListener
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    AudioListener* ptrObject = reinterpret_cast<AudioListener*>(ptr);
+
+    if (strcmp(typeName, "Camera::Listener") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Camera::Listener*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_AudioListener_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_AudioListener_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    AudioListener* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_AudioListener()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"getCamera", lua_AudioListener_getCamera},
+        {"getGain", lua_AudioListener_getGain},
+        {"getOrientationForward", lua_AudioListener_getOrientationForward},
+        {"getOrientationUp", lua_AudioListener_getOrientationUp},
+        {"getPosition", lua_AudioListener_getPosition},
+        {"getVelocity", lua_AudioListener_getVelocity},
+        {"setCamera", lua_AudioListener_setCamera},
+        {"setGain", lua_AudioListener_setGain},
+        {"setOrientation", lua_AudioListener_setOrientation},
+        {"setPosition", lua_AudioListener_setPosition},
+        {"setVelocity", lua_AudioListener_setVelocity},
+        {"to", lua_AudioListener_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"getInstance", lua_AudioListener_static_getInstance},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AudioListener", lua_members, NULL, NULL, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("AudioListener", __convertTo);
+}
+
 }

+ 0 - 14
gameplay/src/lua/lua_AudioListener.h

@@ -5,20 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AudioListener.
-int lua_AudioListener_getCamera(lua_State* state);
-int lua_AudioListener_getGain(lua_State* state);
-int lua_AudioListener_getOrientationForward(lua_State* state);
-int lua_AudioListener_getOrientationUp(lua_State* state);
-int lua_AudioListener_getPosition(lua_State* state);
-int lua_AudioListener_getVelocity(lua_State* state);
-int lua_AudioListener_setCamera(lua_State* state);
-int lua_AudioListener_setGain(lua_State* state);
-int lua_AudioListener_setOrientation(lua_State* state);
-int lua_AudioListener_setPosition(lua_State* state);
-int lua_AudioListener_setVelocity(lua_State* state);
-int lua_AudioListener_static_getInstance(lua_State* state);
-
 void luaRegister_AudioListener();
 
 }

+ 110 - 55
gameplay/src/lua/lua_AudioSource.cpp

@@ -15,44 +15,13 @@
 #include "ScriptController.h"
 #include "ScriptTarget.h"
 #include "Transform.h"
+#include "Ref.h"
+#include "Transform.h"
 
 namespace gameplay
 {
 
-void luaRegister_AudioSource()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_AudioSource_addRef},
-        {"getGain", lua_AudioSource_getGain},
-        {"getNode", lua_AudioSource_getNode},
-        {"getPitch", lua_AudioSource_getPitch},
-        {"getRefCount", lua_AudioSource_getRefCount},
-        {"getState", lua_AudioSource_getState},
-        {"getVelocity", lua_AudioSource_getVelocity},
-        {"isLooped", lua_AudioSource_isLooped},
-        {"isStreamed", lua_AudioSource_isStreamed},
-        {"pause", lua_AudioSource_pause},
-        {"play", lua_AudioSource_play},
-        {"release", lua_AudioSource_release},
-        {"resume", lua_AudioSource_resume},
-        {"rewind", lua_AudioSource_rewind},
-        {"setGain", lua_AudioSource_setGain},
-        {"setLooped", lua_AudioSource_setLooped},
-        {"setPitch", lua_AudioSource_setPitch},
-        {"setVelocity", lua_AudioSource_setVelocity},
-        {"stop", lua_AudioSource_stop},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"create", lua_AudioSource_static_create},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("AudioSource", lua_members, NULL, lua_AudioSource__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static AudioSource* getInstance(lua_State* state)
 {
@@ -61,7 +30,7 @@ static AudioSource* getInstance(lua_State* state)
     return (AudioSource*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_AudioSource__gc(lua_State* state)
+static int lua_AudioSource__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -99,7 +68,7 @@ int lua_AudioSource__gc(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_addRef(lua_State* state)
+static int lua_AudioSource_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -131,7 +100,7 @@ int lua_AudioSource_addRef(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_getGain(lua_State* state)
+static int lua_AudioSource_getGain(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -166,7 +135,7 @@ int lua_AudioSource_getGain(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_getNode(lua_State* state)
+static int lua_AudioSource_getNode(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -210,7 +179,7 @@ int lua_AudioSource_getNode(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_getPitch(lua_State* state)
+static int lua_AudioSource_getPitch(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -245,7 +214,7 @@ int lua_AudioSource_getPitch(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_getRefCount(lua_State* state)
+static int lua_AudioSource_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -280,7 +249,7 @@ int lua_AudioSource_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_getState(lua_State* state)
+static int lua_AudioSource_getState(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -315,7 +284,7 @@ int lua_AudioSource_getState(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_getVelocity(lua_State* state)
+static int lua_AudioSource_getVelocity(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -359,7 +328,7 @@ int lua_AudioSource_getVelocity(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_isLooped(lua_State* state)
+static int lua_AudioSource_isLooped(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -394,7 +363,7 @@ int lua_AudioSource_isLooped(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_isStreamed(lua_State* state)
+static int lua_AudioSource_isStreamed(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -429,7 +398,7 @@ int lua_AudioSource_isStreamed(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_pause(lua_State* state)
+static int lua_AudioSource_pause(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -461,7 +430,7 @@ int lua_AudioSource_pause(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_play(lua_State* state)
+static int lua_AudioSource_play(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -493,7 +462,7 @@ int lua_AudioSource_play(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_release(lua_State* state)
+static int lua_AudioSource_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -525,7 +494,7 @@ int lua_AudioSource_release(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_resume(lua_State* state)
+static int lua_AudioSource_resume(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -557,7 +526,7 @@ int lua_AudioSource_resume(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_rewind(lua_State* state)
+static int lua_AudioSource_rewind(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -589,7 +558,7 @@ int lua_AudioSource_rewind(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_setGain(lua_State* state)
+static int lua_AudioSource_setGain(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -625,7 +594,7 @@ int lua_AudioSource_setGain(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_setLooped(lua_State* state)
+static int lua_AudioSource_setLooped(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -661,7 +630,7 @@ int lua_AudioSource_setLooped(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_setPitch(lua_State* state)
+static int lua_AudioSource_setPitch(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -697,7 +666,7 @@ int lua_AudioSource_setPitch(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_setVelocity(lua_State* state)
+static int lua_AudioSource_setVelocity(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -768,7 +737,7 @@ int lua_AudioSource_setVelocity(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_static_create(lua_State* state)
+static int lua_AudioSource_static_create(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -880,7 +849,7 @@ int lua_AudioSource_static_create(lua_State* state)
     return 0;
 }
 
-int lua_AudioSource_stop(lua_State* state)
+static int lua_AudioSource_stop(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -912,4 +881,90 @@ int lua_AudioSource_stop(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of AudioSource
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    AudioSource* ptrObject = reinterpret_cast<AudioSource*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+    else if (strcmp(typeName, "Transform::Listener") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Transform::Listener*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_AudioSource_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_AudioSource_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    AudioSource* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_AudioSource()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_AudioSource_addRef},
+        {"getGain", lua_AudioSource_getGain},
+        {"getNode", lua_AudioSource_getNode},
+        {"getPitch", lua_AudioSource_getPitch},
+        {"getRefCount", lua_AudioSource_getRefCount},
+        {"getState", lua_AudioSource_getState},
+        {"getVelocity", lua_AudioSource_getVelocity},
+        {"isLooped", lua_AudioSource_isLooped},
+        {"isStreamed", lua_AudioSource_isStreamed},
+        {"pause", lua_AudioSource_pause},
+        {"play", lua_AudioSource_play},
+        {"release", lua_AudioSource_release},
+        {"resume", lua_AudioSource_resume},
+        {"rewind", lua_AudioSource_rewind},
+        {"setGain", lua_AudioSource_setGain},
+        {"setLooped", lua_AudioSource_setLooped},
+        {"setPitch", lua_AudioSource_setPitch},
+        {"setVelocity", lua_AudioSource_setVelocity},
+        {"stop", lua_AudioSource_stop},
+        {"to", lua_AudioSource_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"create", lua_AudioSource_static_create},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("AudioSource", lua_members, NULL, lua_AudioSource__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("AudioSource", __convertTo);
+}
+
 }

+ 0 - 23
gameplay/src/lua/lua_AudioSource.h

@@ -5,29 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for AudioSource.
-int lua_AudioSource__gc(lua_State* state);
-int lua_AudioSource_addRef(lua_State* state);
-int lua_AudioSource_getGain(lua_State* state);
-int lua_AudioSource_getNode(lua_State* state);
-int lua_AudioSource_getPitch(lua_State* state);
-int lua_AudioSource_getRefCount(lua_State* state);
-int lua_AudioSource_getState(lua_State* state);
-int lua_AudioSource_getVelocity(lua_State* state);
-int lua_AudioSource_isLooped(lua_State* state);
-int lua_AudioSource_isStreamed(lua_State* state);
-int lua_AudioSource_pause(lua_State* state);
-int lua_AudioSource_play(lua_State* state);
-int lua_AudioSource_release(lua_State* state);
-int lua_AudioSource_resume(lua_State* state);
-int lua_AudioSource_rewind(lua_State* state);
-int lua_AudioSource_setGain(lua_State* state);
-int lua_AudioSource_setLooped(lua_State* state);
-int lua_AudioSource_setPitch(lua_State* state);
-int lua_AudioSource_setVelocity(lua_State* state);
-int lua_AudioSource_static_create(lua_State* state);
-int lua_AudioSource_stop(lua_State* state);
-
 void luaRegister_AudioSource();
 
 }

+ 38 - 37
gameplay/src/lua/lua_BoundingBox.cpp

@@ -10,31 +10,6 @@
 namespace gameplay
 {
 
-void luaRegister_BoundingBox()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"getCenter", lua_BoundingBox_getCenter},
-        {"getCorners", lua_BoundingBox_getCorners},
-        {"intersects", lua_BoundingBox_intersects},
-        {"isEmpty", lua_BoundingBox_isEmpty},
-        {"max", lua_BoundingBox_max},
-        {"merge", lua_BoundingBox_merge},
-        {"min", lua_BoundingBox_min},
-        {"set", lua_BoundingBox_set},
-        {"transform", lua_BoundingBox_transform},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"empty", lua_BoundingBox_static_empty},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("BoundingBox", lua_members, lua_BoundingBox__init, lua_BoundingBox__gc, lua_statics, scopePath);
-}
-
 static BoundingBox* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "BoundingBox");
@@ -42,7 +17,7 @@ static BoundingBox* getInstance(lua_State* state)
     return (BoundingBox*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_BoundingBox__gc(lua_State* state)
+static int lua_BoundingBox__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -80,7 +55,7 @@ int lua_BoundingBox__gc(lua_State* state)
     return 0;
 }
 
-int lua_BoundingBox__init(lua_State* state)
+static int lua_BoundingBox__init(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -243,7 +218,7 @@ int lua_BoundingBox__init(lua_State* state)
     return 0;
 }
 
-int lua_BoundingBox_getCenter(lua_State* state)
+static int lua_BoundingBox_getCenter(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -314,7 +289,7 @@ int lua_BoundingBox_getCenter(lua_State* state)
     return 0;
 }
 
-int lua_BoundingBox_getCorners(lua_State* state)
+static int lua_BoundingBox_getCorners(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -356,7 +331,7 @@ int lua_BoundingBox_getCorners(lua_State* state)
     return 0;
 }
 
-int lua_BoundingBox_intersects(lua_State* state)
+static int lua_BoundingBox_intersects(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -485,7 +460,7 @@ int lua_BoundingBox_intersects(lua_State* state)
     return 0;
 }
 
-int lua_BoundingBox_isEmpty(lua_State* state)
+static int lua_BoundingBox_isEmpty(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -520,7 +495,7 @@ int lua_BoundingBox_isEmpty(lua_State* state)
     return 0;
 }
 
-int lua_BoundingBox_max(lua_State* state)
+static int lua_BoundingBox_max(lua_State* state)
 {
     // Validate the number of parameters.
     if (lua_gettop(state) > 2)
@@ -564,7 +539,7 @@ int lua_BoundingBox_max(lua_State* state)
     }
 }
 
-int lua_BoundingBox_merge(lua_State* state)
+static int lua_BoundingBox_merge(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -624,7 +599,7 @@ int lua_BoundingBox_merge(lua_State* state)
     return 0;
 }
 
-int lua_BoundingBox_min(lua_State* state)
+static int lua_BoundingBox_min(lua_State* state)
 {
     // Validate the number of parameters.
     if (lua_gettop(state) > 2)
@@ -668,7 +643,7 @@ int lua_BoundingBox_min(lua_State* state)
     }
 }
 
-int lua_BoundingBox_set(lua_State* state)
+static int lua_BoundingBox_set(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -800,7 +775,7 @@ int lua_BoundingBox_set(lua_State* state)
     return 0;
 }
 
-int lua_BoundingBox_static_empty(lua_State* state)
+static int lua_BoundingBox_static_empty(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -837,7 +812,7 @@ int lua_BoundingBox_static_empty(lua_State* state)
     return 0;
 }
 
-int lua_BoundingBox_transform(lua_State* state)
+static int lua_BoundingBox_transform(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -879,4 +854,30 @@ int lua_BoundingBox_transform(lua_State* state)
     return 0;
 }
 
+void luaRegister_BoundingBox()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"getCenter", lua_BoundingBox_getCenter},
+        {"getCorners", lua_BoundingBox_getCorners},
+        {"intersects", lua_BoundingBox_intersects},
+        {"isEmpty", lua_BoundingBox_isEmpty},
+        {"max", lua_BoundingBox_max},
+        {"merge", lua_BoundingBox_merge},
+        {"min", lua_BoundingBox_min},
+        {"set", lua_BoundingBox_set},
+        {"transform", lua_BoundingBox_transform},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"empty", lua_BoundingBox_static_empty},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("BoundingBox", lua_members, lua_BoundingBox__init, lua_BoundingBox__gc, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 14
gameplay/src/lua/lua_BoundingBox.h

@@ -5,20 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for BoundingBox.
-int lua_BoundingBox__gc(lua_State* state);
-int lua_BoundingBox__init(lua_State* state);
-int lua_BoundingBox_getCenter(lua_State* state);
-int lua_BoundingBox_getCorners(lua_State* state);
-int lua_BoundingBox_intersects(lua_State* state);
-int lua_BoundingBox_isEmpty(lua_State* state);
-int lua_BoundingBox_max(lua_State* state);
-int lua_BoundingBox_merge(lua_State* state);
-int lua_BoundingBox_min(lua_State* state);
-int lua_BoundingBox_set(lua_State* state);
-int lua_BoundingBox_static_empty(lua_State* state);
-int lua_BoundingBox_transform(lua_State* state);
-
 void luaRegister_BoundingBox();
 
 }

+ 34 - 33
gameplay/src/lua/lua_BoundingSphere.cpp

@@ -9,29 +9,6 @@
 namespace gameplay
 {
 
-void luaRegister_BoundingSphere()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"center", lua_BoundingSphere_center},
-        {"intersects", lua_BoundingSphere_intersects},
-        {"isEmpty", lua_BoundingSphere_isEmpty},
-        {"merge", lua_BoundingSphere_merge},
-        {"radius", lua_BoundingSphere_radius},
-        {"set", lua_BoundingSphere_set},
-        {"transform", lua_BoundingSphere_transform},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"empty", lua_BoundingSphere_static_empty},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("BoundingSphere", lua_members, lua_BoundingSphere__init, lua_BoundingSphere__gc, lua_statics, scopePath);
-}
-
 static BoundingSphere* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "BoundingSphere");
@@ -39,7 +16,7 @@ static BoundingSphere* getInstance(lua_State* state)
     return (BoundingSphere*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_BoundingSphere__gc(lua_State* state)
+static int lua_BoundingSphere__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -77,7 +54,7 @@ int lua_BoundingSphere__gc(lua_State* state)
     return 0;
 }
 
-int lua_BoundingSphere__init(lua_State* state)
+static int lua_BoundingSphere__init(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -186,7 +163,7 @@ int lua_BoundingSphere__init(lua_State* state)
     return 0;
 }
 
-int lua_BoundingSphere_center(lua_State* state)
+static int lua_BoundingSphere_center(lua_State* state)
 {
     // Validate the number of parameters.
     if (lua_gettop(state) > 2)
@@ -230,7 +207,7 @@ int lua_BoundingSphere_center(lua_State* state)
     }
 }
 
-int lua_BoundingSphere_intersects(lua_State* state)
+static int lua_BoundingSphere_intersects(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -359,7 +336,7 @@ int lua_BoundingSphere_intersects(lua_State* state)
     return 0;
 }
 
-int lua_BoundingSphere_isEmpty(lua_State* state)
+static int lua_BoundingSphere_isEmpty(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -394,7 +371,7 @@ int lua_BoundingSphere_isEmpty(lua_State* state)
     return 0;
 }
 
-int lua_BoundingSphere_merge(lua_State* state)
+static int lua_BoundingSphere_merge(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -454,7 +431,7 @@ int lua_BoundingSphere_merge(lua_State* state)
     return 0;
 }
 
-int lua_BoundingSphere_radius(lua_State* state)
+static int lua_BoundingSphere_radius(lua_State* state)
 {
     // Validate the number of parameters.
     if (lua_gettop(state) > 2)
@@ -483,7 +460,7 @@ int lua_BoundingSphere_radius(lua_State* state)
     }
 }
 
-int lua_BoundingSphere_set(lua_State* state)
+static int lua_BoundingSphere_set(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -571,7 +548,7 @@ int lua_BoundingSphere_set(lua_State* state)
     return 0;
 }
 
-int lua_BoundingSphere_static_empty(lua_State* state)
+static int lua_BoundingSphere_static_empty(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -608,7 +585,7 @@ int lua_BoundingSphere_static_empty(lua_State* state)
     return 0;
 }
 
-int lua_BoundingSphere_transform(lua_State* state)
+static int lua_BoundingSphere_transform(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -650,4 +627,28 @@ int lua_BoundingSphere_transform(lua_State* state)
     return 0;
 }
 
+void luaRegister_BoundingSphere()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"center", lua_BoundingSphere_center},
+        {"intersects", lua_BoundingSphere_intersects},
+        {"isEmpty", lua_BoundingSphere_isEmpty},
+        {"merge", lua_BoundingSphere_merge},
+        {"radius", lua_BoundingSphere_radius},
+        {"set", lua_BoundingSphere_set},
+        {"transform", lua_BoundingSphere_transform},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"empty", lua_BoundingSphere_static_empty},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("BoundingSphere", lua_members, lua_BoundingSphere__init, lua_BoundingSphere__gc, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 12
gameplay/src/lua/lua_BoundingSphere.h

@@ -5,18 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for BoundingSphere.
-int lua_BoundingSphere__gc(lua_State* state);
-int lua_BoundingSphere__init(lua_State* state);
-int lua_BoundingSphere_center(lua_State* state);
-int lua_BoundingSphere_intersects(lua_State* state);
-int lua_BoundingSphere_isEmpty(lua_State* state);
-int lua_BoundingSphere_merge(lua_State* state);
-int lua_BoundingSphere_radius(lua_State* state);
-int lua_BoundingSphere_set(lua_State* state);
-int lua_BoundingSphere_static_empty(lua_State* state);
-int lua_BoundingSphere_transform(lua_State* state);
-
 void luaRegister_BoundingSphere();
 
 }

+ 91 - 41
gameplay/src/lua/lua_Bundle.cpp

@@ -10,37 +10,12 @@
 #include "MeshPart.h"
 #include "Ref.h"
 #include "Scene.h"
+#include "Ref.h"
 
 namespace gameplay
 {
 
-void luaRegister_Bundle()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_Bundle_addRef},
-        {"contains", lua_Bundle_contains},
-        {"getObjectCount", lua_Bundle_getObjectCount},
-        {"getObjectId", lua_Bundle_getObjectId},
-        {"getRefCount", lua_Bundle_getRefCount},
-        {"getVersionMajor", lua_Bundle_getVersionMajor},
-        {"getVersionMinor", lua_Bundle_getVersionMinor},
-        {"loadFont", lua_Bundle_loadFont},
-        {"loadMesh", lua_Bundle_loadMesh},
-        {"loadNode", lua_Bundle_loadNode},
-        {"loadScene", lua_Bundle_loadScene},
-        {"release", lua_Bundle_release},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"create", lua_Bundle_static_create},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("Bundle", lua_members, NULL, lua_Bundle__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static Bundle* getInstance(lua_State* state)
 {
@@ -49,7 +24,7 @@ static Bundle* getInstance(lua_State* state)
     return (Bundle*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_Bundle__gc(lua_State* state)
+static int lua_Bundle__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -87,7 +62,7 @@ int lua_Bundle__gc(lua_State* state)
     return 0;
 }
 
-int lua_Bundle_addRef(lua_State* state)
+static int lua_Bundle_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -119,7 +94,7 @@ int lua_Bundle_addRef(lua_State* state)
     return 0;
 }
 
-int lua_Bundle_contains(lua_State* state)
+static int lua_Bundle_contains(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -158,7 +133,7 @@ int lua_Bundle_contains(lua_State* state)
     return 0;
 }
 
-int lua_Bundle_getObjectCount(lua_State* state)
+static int lua_Bundle_getObjectCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -193,7 +168,7 @@ int lua_Bundle_getObjectCount(lua_State* state)
     return 0;
 }
 
-int lua_Bundle_getObjectId(lua_State* state)
+static int lua_Bundle_getObjectId(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -232,7 +207,7 @@ int lua_Bundle_getObjectId(lua_State* state)
     return 0;
 }
 
-int lua_Bundle_getRefCount(lua_State* state)
+static int lua_Bundle_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -267,7 +242,7 @@ int lua_Bundle_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_Bundle_getVersionMajor(lua_State* state)
+static int lua_Bundle_getVersionMajor(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -302,7 +277,7 @@ int lua_Bundle_getVersionMajor(lua_State* state)
     return 0;
 }
 
-int lua_Bundle_getVersionMinor(lua_State* state)
+static int lua_Bundle_getVersionMinor(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -337,7 +312,7 @@ int lua_Bundle_getVersionMinor(lua_State* state)
     return 0;
 }
 
-int lua_Bundle_loadFont(lua_State* state)
+static int lua_Bundle_loadFont(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -385,7 +360,7 @@ int lua_Bundle_loadFont(lua_State* state)
     return 0;
 }
 
-int lua_Bundle_loadMesh(lua_State* state)
+static int lua_Bundle_loadMesh(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -433,7 +408,7 @@ int lua_Bundle_loadMesh(lua_State* state)
     return 0;
 }
 
-int lua_Bundle_loadNode(lua_State* state)
+static int lua_Bundle_loadNode(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -481,7 +456,7 @@ int lua_Bundle_loadNode(lua_State* state)
     return 0;
 }
 
-int lua_Bundle_loadScene(lua_State* state)
+static int lua_Bundle_loadScene(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -555,7 +530,7 @@ int lua_Bundle_loadScene(lua_State* state)
     return 0;
 }
 
-int lua_Bundle_release(lua_State* state)
+static int lua_Bundle_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -587,7 +562,7 @@ int lua_Bundle_release(lua_State* state)
     return 0;
 }
 
-int lua_Bundle_static_create(lua_State* state)
+static int lua_Bundle_static_create(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -633,4 +608,79 @@ int lua_Bundle_static_create(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of Bundle
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    Bundle* ptrObject = reinterpret_cast<Bundle*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_Bundle_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_Bundle_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    Bundle* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_Bundle()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_Bundle_addRef},
+        {"contains", lua_Bundle_contains},
+        {"getObjectCount", lua_Bundle_getObjectCount},
+        {"getObjectId", lua_Bundle_getObjectId},
+        {"getRefCount", lua_Bundle_getRefCount},
+        {"getVersionMajor", lua_Bundle_getVersionMajor},
+        {"getVersionMinor", lua_Bundle_getVersionMinor},
+        {"loadFont", lua_Bundle_loadFont},
+        {"loadMesh", lua_Bundle_loadMesh},
+        {"loadNode", lua_Bundle_loadNode},
+        {"loadScene", lua_Bundle_loadScene},
+        {"release", lua_Bundle_release},
+        {"to", lua_Bundle_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"create", lua_Bundle_static_create},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("Bundle", lua_members, NULL, lua_Bundle__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("Bundle", __convertTo);
+}
+
 }

+ 0 - 16
gameplay/src/lua/lua_Bundle.h

@@ -5,22 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Bundle.
-int lua_Bundle__gc(lua_State* state);
-int lua_Bundle_addRef(lua_State* state);
-int lua_Bundle_contains(lua_State* state);
-int lua_Bundle_getObjectCount(lua_State* state);
-int lua_Bundle_getObjectId(lua_State* state);
-int lua_Bundle_getRefCount(lua_State* state);
-int lua_Bundle_getVersionMajor(lua_State* state);
-int lua_Bundle_getVersionMinor(lua_State* state);
-int lua_Bundle_loadFont(lua_State* state);
-int lua_Bundle_loadMesh(lua_State* state);
-int lua_Bundle_loadNode(lua_State* state);
-int lua_Bundle_loadScene(lua_State* state);
-int lua_Bundle_release(lua_State* state);
-int lua_Bundle_static_create(lua_State* state);
-
 void luaRegister_Bundle();
 
 }

File diff suppressed because it is too large
+ 101 - 220
gameplay/src/lua/lua_Button.cpp


+ 0 - 114
gameplay/src/lua/lua_Button.h

@@ -5,120 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Button.
-int lua_Button__gc(lua_State* state);
-int lua_Button_addListener(lua_State* state);
-int lua_Button_addRef(lua_State* state);
-int lua_Button_addScript(lua_State* state);
-int lua_Button_addScriptCallback(lua_State* state);
-int lua_Button_canFocus(lua_State* state);
-int lua_Button_clearScripts(lua_State* state);
-int lua_Button_createAnimation(lua_State* state);
-int lua_Button_createAnimationFromBy(lua_State* state);
-int lua_Button_createAnimationFromTo(lua_State* state);
-int lua_Button_destroyAnimation(lua_State* state);
-int lua_Button_getAbsoluteBounds(lua_State* state);
-int lua_Button_getAlignment(lua_State* state);
-int lua_Button_getAnimation(lua_State* state);
-int lua_Button_getAnimationPropertyComponentCount(lua_State* state);
-int lua_Button_getAnimationPropertyValue(lua_State* state);
-int lua_Button_getAutoSize(lua_State* state);
-int lua_Button_getBorder(lua_State* state);
-int lua_Button_getBounds(lua_State* state);
-int lua_Button_getClip(lua_State* state);
-int lua_Button_getClipBounds(lua_State* state);
-int lua_Button_getConsumeInputEvents(lua_State* state);
-int lua_Button_getCursorColor(lua_State* state);
-int lua_Button_getCursorRegion(lua_State* state);
-int lua_Button_getCursorUVs(lua_State* state);
-int lua_Button_getFocusIndex(lua_State* state);
-int lua_Button_getFont(lua_State* state);
-int lua_Button_getFontSize(lua_State* state);
-int lua_Button_getHeight(lua_State* state);
-int lua_Button_getId(lua_State* state);
-int lua_Button_getImageColor(lua_State* state);
-int lua_Button_getImageRegion(lua_State* state);
-int lua_Button_getImageUVs(lua_State* state);
-int lua_Button_getMargin(lua_State* state);
-int lua_Button_getOpacity(lua_State* state);
-int lua_Button_getPadding(lua_State* state);
-int lua_Button_getParent(lua_State* state);
-int lua_Button_getRefCount(lua_State* state);
-int lua_Button_getScriptEvent(lua_State* state);
-int lua_Button_getSkinColor(lua_State* state);
-int lua_Button_getSkinRegion(lua_State* state);
-int lua_Button_getState(lua_State* state);
-int lua_Button_getStyle(lua_State* state);
-int lua_Button_getText(lua_State* state);
-int lua_Button_getTextAlignment(lua_State* state);
-int lua_Button_getTextColor(lua_State* state);
-int lua_Button_getTextRightToLeft(lua_State* state);
-int lua_Button_getTheme(lua_State* state);
-int lua_Button_getTopLevelForm(lua_State* state);
-int lua_Button_getWidth(lua_State* state);
-int lua_Button_getX(lua_State* state);
-int lua_Button_getY(lua_State* state);
-int lua_Button_getZIndex(lua_State* state);
-int lua_Button_hasFocus(lua_State* state);
-int lua_Button_hasScriptListener(lua_State* state);
-int lua_Button_isChild(lua_State* state);
-int lua_Button_isContainer(lua_State* state);
-int lua_Button_isEnabled(lua_State* state);
-int lua_Button_isEnabledInHierarchy(lua_State* state);
-int lua_Button_isHeightPercentage(lua_State* state);
-int lua_Button_isVisible(lua_State* state);
-int lua_Button_isVisibleInHierarchy(lua_State* state);
-int lua_Button_isWidthPercentage(lua_State* state);
-int lua_Button_isXPercentage(lua_State* state);
-int lua_Button_isYPercentage(lua_State* state);
-int lua_Button_release(lua_State* state);
-int lua_Button_removeListener(lua_State* state);
-int lua_Button_removeScript(lua_State* state);
-int lua_Button_removeScriptCallback(lua_State* state);
-int lua_Button_setAlignment(lua_State* state);
-int lua_Button_setAnimationPropertyValue(lua_State* state);
-int lua_Button_setAutoSize(lua_State* state);
-int lua_Button_setBorder(lua_State* state);
-int lua_Button_setBounds(lua_State* state);
-int lua_Button_setCanFocus(lua_State* state);
-int lua_Button_setConsumeInputEvents(lua_State* state);
-int lua_Button_setCursorColor(lua_State* state);
-int lua_Button_setCursorRegion(lua_State* state);
-int lua_Button_setEnabled(lua_State* state);
-int lua_Button_setFocus(lua_State* state);
-int lua_Button_setFocusIndex(lua_State* state);
-int lua_Button_setFont(lua_State* state);
-int lua_Button_setFontSize(lua_State* state);
-int lua_Button_setHeight(lua_State* state);
-int lua_Button_setId(lua_State* state);
-int lua_Button_setImageColor(lua_State* state);
-int lua_Button_setImageRegion(lua_State* state);
-int lua_Button_setMargin(lua_State* state);
-int lua_Button_setOpacity(lua_State* state);
-int lua_Button_setPadding(lua_State* state);
-int lua_Button_setPosition(lua_State* state);
-int lua_Button_setSize(lua_State* state);
-int lua_Button_setSkinColor(lua_State* state);
-int lua_Button_setSkinRegion(lua_State* state);
-int lua_Button_setStyle(lua_State* state);
-int lua_Button_setText(lua_State* state);
-int lua_Button_setTextAlignment(lua_State* state);
-int lua_Button_setTextColor(lua_State* state);
-int lua_Button_setTextRightToLeft(lua_State* state);
-int lua_Button_setVisible(lua_State* state);
-int lua_Button_setWidth(lua_State* state);
-int lua_Button_setX(lua_State* state);
-int lua_Button_setY(lua_State* state);
-int lua_Button_setZIndex(lua_State* state);
-int lua_Button_static_ANIMATE_OPACITY(lua_State* state);
-int lua_Button_static_ANIMATE_POSITION(lua_State* state);
-int lua_Button_static_ANIMATE_POSITION_X(lua_State* state);
-int lua_Button_static_ANIMATE_POSITION_Y(lua_State* state);
-int lua_Button_static_ANIMATE_SIZE(lua_State* state);
-int lua_Button_static_ANIMATE_SIZE_HEIGHT(lua_State* state);
-int lua_Button_static_ANIMATE_SIZE_WIDTH(lua_State* state);
-int lua_Button_static_create(lua_State* state);
-
 void luaRegister_Button();
 
 }

+ 138 - 81
gameplay/src/lua/lua_Camera.cpp

@@ -4,6 +4,7 @@
 #include "lua_Camera.h"
 #include "Animation.h"
 #include "AnimationTarget.h"
+#include "AudioListener.h"
 #include "Base.h"
 #include "Camera.h"
 #include "Game.h"
@@ -13,58 +14,15 @@
 #include "Ref.h"
 #include "ScriptController.h"
 #include "ScriptTarget.h"
+#include "TerrainPatch.h"
+#include "Transform.h"
+#include "Ref.h"
 #include "Transform.h"
 
 namespace gameplay
 {
 
-void luaRegister_Camera()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addListener", lua_Camera_addListener},
-        {"addRef", lua_Camera_addRef},
-        {"getAspectRatio", lua_Camera_getAspectRatio},
-        {"getCameraType", lua_Camera_getCameraType},
-        {"getFarPlane", lua_Camera_getFarPlane},
-        {"getFieldOfView", lua_Camera_getFieldOfView},
-        {"getFrustum", lua_Camera_getFrustum},
-        {"getInverseViewMatrix", lua_Camera_getInverseViewMatrix},
-        {"getInverseViewProjectionMatrix", lua_Camera_getInverseViewProjectionMatrix},
-        {"getNearPlane", lua_Camera_getNearPlane},
-        {"getNode", lua_Camera_getNode},
-        {"getProjectionMatrix", lua_Camera_getProjectionMatrix},
-        {"getRefCount", lua_Camera_getRefCount},
-        {"getViewMatrix", lua_Camera_getViewMatrix},
-        {"getViewProjectionMatrix", lua_Camera_getViewProjectionMatrix},
-        {"getZoomX", lua_Camera_getZoomX},
-        {"getZoomY", lua_Camera_getZoomY},
-        {"pickRay", lua_Camera_pickRay},
-        {"project", lua_Camera_project},
-        {"release", lua_Camera_release},
-        {"removeListener", lua_Camera_removeListener},
-        {"resetProjectionMatrix", lua_Camera_resetProjectionMatrix},
-        {"setAspectRatio", lua_Camera_setAspectRatio},
-        {"setFarPlane", lua_Camera_setFarPlane},
-        {"setFieldOfView", lua_Camera_setFieldOfView},
-        {"setNearPlane", lua_Camera_setNearPlane},
-        {"setProjectionMatrix", lua_Camera_setProjectionMatrix},
-        {"setZoomX", lua_Camera_setZoomX},
-        {"setZoomY", lua_Camera_setZoomY},
-        {"unproject", lua_Camera_unproject},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"create", lua_Camera_static_create},
-        {"createOrthographic", lua_Camera_static_createOrthographic},
-        {"createPerspective", lua_Camera_static_createPerspective},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("Camera", lua_members, NULL, lua_Camera__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static Camera* getInstance(lua_State* state)
 {
@@ -73,7 +31,7 @@ static Camera* getInstance(lua_State* state)
     return (Camera*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_Camera__gc(lua_State* state)
+static int lua_Camera__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -111,7 +69,7 @@ int lua_Camera__gc(lua_State* state)
     return 0;
 }
 
-int lua_Camera_addListener(lua_State* state)
+static int lua_Camera_addListener(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -153,7 +111,7 @@ int lua_Camera_addListener(lua_State* state)
     return 0;
 }
 
-int lua_Camera_addRef(lua_State* state)
+static int lua_Camera_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -185,7 +143,7 @@ int lua_Camera_addRef(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getAspectRatio(lua_State* state)
+static int lua_Camera_getAspectRatio(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -220,7 +178,7 @@ int lua_Camera_getAspectRatio(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getCameraType(lua_State* state)
+static int lua_Camera_getCameraType(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -255,7 +213,7 @@ int lua_Camera_getCameraType(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getFarPlane(lua_State* state)
+static int lua_Camera_getFarPlane(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -290,7 +248,7 @@ int lua_Camera_getFarPlane(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getFieldOfView(lua_State* state)
+static int lua_Camera_getFieldOfView(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -325,7 +283,7 @@ int lua_Camera_getFieldOfView(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getFrustum(lua_State* state)
+static int lua_Camera_getFrustum(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -369,7 +327,7 @@ int lua_Camera_getFrustum(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getInverseViewMatrix(lua_State* state)
+static int lua_Camera_getInverseViewMatrix(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -413,7 +371,7 @@ int lua_Camera_getInverseViewMatrix(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getInverseViewProjectionMatrix(lua_State* state)
+static int lua_Camera_getInverseViewProjectionMatrix(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -457,7 +415,7 @@ int lua_Camera_getInverseViewProjectionMatrix(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getNearPlane(lua_State* state)
+static int lua_Camera_getNearPlane(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -492,7 +450,7 @@ int lua_Camera_getNearPlane(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getNode(lua_State* state)
+static int lua_Camera_getNode(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -536,7 +494,7 @@ int lua_Camera_getNode(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getProjectionMatrix(lua_State* state)
+static int lua_Camera_getProjectionMatrix(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -580,7 +538,7 @@ int lua_Camera_getProjectionMatrix(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getRefCount(lua_State* state)
+static int lua_Camera_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -615,7 +573,7 @@ int lua_Camera_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getViewMatrix(lua_State* state)
+static int lua_Camera_getViewMatrix(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -659,7 +617,7 @@ int lua_Camera_getViewMatrix(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getViewProjectionMatrix(lua_State* state)
+static int lua_Camera_getViewProjectionMatrix(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -703,7 +661,7 @@ int lua_Camera_getViewProjectionMatrix(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getZoomX(lua_State* state)
+static int lua_Camera_getZoomX(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -738,7 +696,7 @@ int lua_Camera_getZoomX(lua_State* state)
     return 0;
 }
 
-int lua_Camera_getZoomY(lua_State* state)
+static int lua_Camera_getZoomY(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -773,7 +731,7 @@ int lua_Camera_getZoomY(lua_State* state)
     return 0;
 }
 
-int lua_Camera_pickRay(lua_State* state)
+static int lua_Camera_pickRay(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -833,7 +791,7 @@ int lua_Camera_pickRay(lua_State* state)
     return 0;
 }
 
-int lua_Camera_project(lua_State* state)
+static int lua_Camera_project(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -921,7 +879,7 @@ int lua_Camera_project(lua_State* state)
     return 0;
 }
 
-int lua_Camera_release(lua_State* state)
+static int lua_Camera_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -953,7 +911,7 @@ int lua_Camera_release(lua_State* state)
     return 0;
 }
 
-int lua_Camera_removeListener(lua_State* state)
+static int lua_Camera_removeListener(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -995,7 +953,7 @@ int lua_Camera_removeListener(lua_State* state)
     return 0;
 }
 
-int lua_Camera_resetProjectionMatrix(lua_State* state)
+static int lua_Camera_resetProjectionMatrix(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1027,7 +985,7 @@ int lua_Camera_resetProjectionMatrix(lua_State* state)
     return 0;
 }
 
-int lua_Camera_setAspectRatio(lua_State* state)
+static int lua_Camera_setAspectRatio(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1063,7 +1021,7 @@ int lua_Camera_setAspectRatio(lua_State* state)
     return 0;
 }
 
-int lua_Camera_setFarPlane(lua_State* state)
+static int lua_Camera_setFarPlane(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1099,7 +1057,7 @@ int lua_Camera_setFarPlane(lua_State* state)
     return 0;
 }
 
-int lua_Camera_setFieldOfView(lua_State* state)
+static int lua_Camera_setFieldOfView(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1135,7 +1093,7 @@ int lua_Camera_setFieldOfView(lua_State* state)
     return 0;
 }
 
-int lua_Camera_setNearPlane(lua_State* state)
+static int lua_Camera_setNearPlane(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1171,7 +1129,7 @@ int lua_Camera_setNearPlane(lua_State* state)
     return 0;
 }
 
-int lua_Camera_setProjectionMatrix(lua_State* state)
+static int lua_Camera_setProjectionMatrix(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1213,7 +1171,7 @@ int lua_Camera_setProjectionMatrix(lua_State* state)
     return 0;
 }
 
-int lua_Camera_setZoomX(lua_State* state)
+static int lua_Camera_setZoomX(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1249,7 +1207,7 @@ int lua_Camera_setZoomX(lua_State* state)
     return 0;
 }
 
-int lua_Camera_setZoomY(lua_State* state)
+static int lua_Camera_setZoomY(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1285,7 +1243,7 @@ int lua_Camera_setZoomY(lua_State* state)
     return 0;
 }
 
-int lua_Camera_static_create(lua_State* state)
+static int lua_Camera_static_create(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1337,7 +1295,7 @@ int lua_Camera_static_create(lua_State* state)
     return 0;
 }
 
-int lua_Camera_static_createOrthographic(lua_State* state)
+static int lua_Camera_static_createOrthographic(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1399,7 +1357,7 @@ int lua_Camera_static_createOrthographic(lua_State* state)
     return 0;
 }
 
-int lua_Camera_static_createPerspective(lua_State* state)
+static int lua_Camera_static_createPerspective(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1457,7 +1415,7 @@ int lua_Camera_static_createPerspective(lua_State* state)
     return 0;
 }
 
-int lua_Camera_unproject(lua_State* state)
+static int lua_Camera_unproject(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1521,4 +1479,103 @@ int lua_Camera_unproject(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of Camera
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    Camera* ptrObject = reinterpret_cast<Camera*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+    else if (strcmp(typeName, "Transform::Listener") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Transform::Listener*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_Camera_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_Camera_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    Camera* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_Camera()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addListener", lua_Camera_addListener},
+        {"addRef", lua_Camera_addRef},
+        {"getAspectRatio", lua_Camera_getAspectRatio},
+        {"getCameraType", lua_Camera_getCameraType},
+        {"getFarPlane", lua_Camera_getFarPlane},
+        {"getFieldOfView", lua_Camera_getFieldOfView},
+        {"getFrustum", lua_Camera_getFrustum},
+        {"getInverseViewMatrix", lua_Camera_getInverseViewMatrix},
+        {"getInverseViewProjectionMatrix", lua_Camera_getInverseViewProjectionMatrix},
+        {"getNearPlane", lua_Camera_getNearPlane},
+        {"getNode", lua_Camera_getNode},
+        {"getProjectionMatrix", lua_Camera_getProjectionMatrix},
+        {"getRefCount", lua_Camera_getRefCount},
+        {"getViewMatrix", lua_Camera_getViewMatrix},
+        {"getViewProjectionMatrix", lua_Camera_getViewProjectionMatrix},
+        {"getZoomX", lua_Camera_getZoomX},
+        {"getZoomY", lua_Camera_getZoomY},
+        {"pickRay", lua_Camera_pickRay},
+        {"project", lua_Camera_project},
+        {"release", lua_Camera_release},
+        {"removeListener", lua_Camera_removeListener},
+        {"resetProjectionMatrix", lua_Camera_resetProjectionMatrix},
+        {"setAspectRatio", lua_Camera_setAspectRatio},
+        {"setFarPlane", lua_Camera_setFarPlane},
+        {"setFieldOfView", lua_Camera_setFieldOfView},
+        {"setNearPlane", lua_Camera_setNearPlane},
+        {"setProjectionMatrix", lua_Camera_setProjectionMatrix},
+        {"setZoomX", lua_Camera_setZoomX},
+        {"setZoomY", lua_Camera_setZoomY},
+        {"unproject", lua_Camera_unproject},
+        {"to", lua_Camera_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"create", lua_Camera_static_create},
+        {"createOrthographic", lua_Camera_static_createOrthographic},
+        {"createPerspective", lua_Camera_static_createPerspective},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("Camera", lua_members, NULL, lua_Camera__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("Camera", __convertTo);
+}
+
 }

+ 0 - 36
gameplay/src/lua/lua_Camera.h

@@ -5,42 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Camera.
-int lua_Camera__gc(lua_State* state);
-int lua_Camera_addListener(lua_State* state);
-int lua_Camera_addRef(lua_State* state);
-int lua_Camera_getAspectRatio(lua_State* state);
-int lua_Camera_getCameraType(lua_State* state);
-int lua_Camera_getFarPlane(lua_State* state);
-int lua_Camera_getFieldOfView(lua_State* state);
-int lua_Camera_getFrustum(lua_State* state);
-int lua_Camera_getInverseViewMatrix(lua_State* state);
-int lua_Camera_getInverseViewProjectionMatrix(lua_State* state);
-int lua_Camera_getNearPlane(lua_State* state);
-int lua_Camera_getNode(lua_State* state);
-int lua_Camera_getProjectionMatrix(lua_State* state);
-int lua_Camera_getRefCount(lua_State* state);
-int lua_Camera_getViewMatrix(lua_State* state);
-int lua_Camera_getViewProjectionMatrix(lua_State* state);
-int lua_Camera_getZoomX(lua_State* state);
-int lua_Camera_getZoomY(lua_State* state);
-int lua_Camera_pickRay(lua_State* state);
-int lua_Camera_project(lua_State* state);
-int lua_Camera_release(lua_State* state);
-int lua_Camera_removeListener(lua_State* state);
-int lua_Camera_resetProjectionMatrix(lua_State* state);
-int lua_Camera_setAspectRatio(lua_State* state);
-int lua_Camera_setFarPlane(lua_State* state);
-int lua_Camera_setFieldOfView(lua_State* state);
-int lua_Camera_setNearPlane(lua_State* state);
-int lua_Camera_setProjectionMatrix(lua_State* state);
-int lua_Camera_setZoomX(lua_State* state);
-int lua_Camera_setZoomY(lua_State* state);
-int lua_Camera_static_create(lua_State* state);
-int lua_Camera_static_createOrthographic(lua_State* state);
-int lua_Camera_static_createPerspective(lua_State* state);
-int lua_Camera_unproject(lua_State* state);
-
 void luaRegister_Camera();
 
 }

+ 72 - 15
gameplay/src/lua/lua_CameraListener.cpp

@@ -4,6 +4,7 @@
 #include "lua_CameraListener.h"
 #include "Animation.h"
 #include "AnimationTarget.h"
+#include "AudioListener.h"
 #include "Base.h"
 #include "Camera.h"
 #include "Game.h"
@@ -13,24 +14,15 @@
 #include "Ref.h"
 #include "ScriptController.h"
 #include "ScriptTarget.h"
+#include "TerrainPatch.h"
 #include "Transform.h"
+#include "AudioListener.h"
+#include "TerrainPatch.h"
 
 namespace gameplay
 {
 
-void luaRegister_CameraListener()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"cameraChanged", lua_CameraListener_cameraChanged},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-    scopePath.push_back("Camera");
-
-    gameplay::ScriptUtil::registerClass("CameraListener", lua_members, NULL, lua_CameraListener__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static Camera::Listener* getInstance(lua_State* state)
 {
@@ -39,7 +31,7 @@ static Camera::Listener* getInstance(lua_State* state)
     return (Camera::Listener*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_CameraListener__gc(lua_State* state)
+static int lua_CameraListener__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -77,7 +69,7 @@ int lua_CameraListener__gc(lua_State* state)
     return 0;
 }
 
-int lua_CameraListener_cameraChanged(lua_State* state)
+static int lua_CameraListener_cameraChanged(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -119,4 +111,69 @@ int lua_CameraListener_cameraChanged(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of Camera::Listener
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    Camera::Listener* ptrObject = reinterpret_cast<Camera::Listener*>(ptr);
+
+    if (strcmp(typeName, "AudioListener") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<AudioListener*>(ptrObject));
+    }
+    else if (strcmp(typeName, "TerrainPatch") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<TerrainPatch*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_CameraListener_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_CameraListener_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    Camera::Listener* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_CameraListener()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"cameraChanged", lua_CameraListener_cameraChanged},
+        {"to", lua_CameraListener_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+    scopePath.push_back("Camera");
+
+    gameplay::ScriptUtil::registerClass("CameraListener", lua_members, NULL, lua_CameraListener__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("CameraListener", __convertTo);
+}
+
 }

+ 0 - 4
gameplay/src/lua/lua_CameraListener.h

@@ -5,10 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Camera::Listener.
-int lua_CameraListener__gc(lua_State* state);
-int lua_CameraListener_cameraChanged(lua_State* state);
-
 void luaRegister_CameraListener();
 
 }

File diff suppressed because it is too large
+ 98 - 224
gameplay/src/lua/lua_CheckBox.cpp


+ 0 - 117
gameplay/src/lua/lua_CheckBox.h

@@ -5,123 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for CheckBox.
-int lua_CheckBox__gc(lua_State* state);
-int lua_CheckBox_addListener(lua_State* state);
-int lua_CheckBox_addRef(lua_State* state);
-int lua_CheckBox_addScript(lua_State* state);
-int lua_CheckBox_addScriptCallback(lua_State* state);
-int lua_CheckBox_canFocus(lua_State* state);
-int lua_CheckBox_clearScripts(lua_State* state);
-int lua_CheckBox_createAnimation(lua_State* state);
-int lua_CheckBox_createAnimationFromBy(lua_State* state);
-int lua_CheckBox_createAnimationFromTo(lua_State* state);
-int lua_CheckBox_destroyAnimation(lua_State* state);
-int lua_CheckBox_getAbsoluteBounds(lua_State* state);
-int lua_CheckBox_getAlignment(lua_State* state);
-int lua_CheckBox_getAnimation(lua_State* state);
-int lua_CheckBox_getAnimationPropertyComponentCount(lua_State* state);
-int lua_CheckBox_getAnimationPropertyValue(lua_State* state);
-int lua_CheckBox_getAutoSize(lua_State* state);
-int lua_CheckBox_getBorder(lua_State* state);
-int lua_CheckBox_getBounds(lua_State* state);
-int lua_CheckBox_getClip(lua_State* state);
-int lua_CheckBox_getClipBounds(lua_State* state);
-int lua_CheckBox_getConsumeInputEvents(lua_State* state);
-int lua_CheckBox_getCursorColor(lua_State* state);
-int lua_CheckBox_getCursorRegion(lua_State* state);
-int lua_CheckBox_getCursorUVs(lua_State* state);
-int lua_CheckBox_getFocusIndex(lua_State* state);
-int lua_CheckBox_getFont(lua_State* state);
-int lua_CheckBox_getFontSize(lua_State* state);
-int lua_CheckBox_getHeight(lua_State* state);
-int lua_CheckBox_getId(lua_State* state);
-int lua_CheckBox_getImageColor(lua_State* state);
-int lua_CheckBox_getImageRegion(lua_State* state);
-int lua_CheckBox_getImageUVs(lua_State* state);
-int lua_CheckBox_getMargin(lua_State* state);
-int lua_CheckBox_getOpacity(lua_State* state);
-int lua_CheckBox_getPadding(lua_State* state);
-int lua_CheckBox_getParent(lua_State* state);
-int lua_CheckBox_getRefCount(lua_State* state);
-int lua_CheckBox_getScriptEvent(lua_State* state);
-int lua_CheckBox_getSkinColor(lua_State* state);
-int lua_CheckBox_getSkinRegion(lua_State* state);
-int lua_CheckBox_getState(lua_State* state);
-int lua_CheckBox_getStyle(lua_State* state);
-int lua_CheckBox_getText(lua_State* state);
-int lua_CheckBox_getTextAlignment(lua_State* state);
-int lua_CheckBox_getTextColor(lua_State* state);
-int lua_CheckBox_getTextRightToLeft(lua_State* state);
-int lua_CheckBox_getTheme(lua_State* state);
-int lua_CheckBox_getTopLevelForm(lua_State* state);
-int lua_CheckBox_getTypeName(lua_State* state);
-int lua_CheckBox_getWidth(lua_State* state);
-int lua_CheckBox_getX(lua_State* state);
-int lua_CheckBox_getY(lua_State* state);
-int lua_CheckBox_getZIndex(lua_State* state);
-int lua_CheckBox_hasFocus(lua_State* state);
-int lua_CheckBox_hasScriptListener(lua_State* state);
-int lua_CheckBox_isChecked(lua_State* state);
-int lua_CheckBox_isChild(lua_State* state);
-int lua_CheckBox_isContainer(lua_State* state);
-int lua_CheckBox_isEnabled(lua_State* state);
-int lua_CheckBox_isEnabledInHierarchy(lua_State* state);
-int lua_CheckBox_isHeightPercentage(lua_State* state);
-int lua_CheckBox_isVisible(lua_State* state);
-int lua_CheckBox_isVisibleInHierarchy(lua_State* state);
-int lua_CheckBox_isWidthPercentage(lua_State* state);
-int lua_CheckBox_isXPercentage(lua_State* state);
-int lua_CheckBox_isYPercentage(lua_State* state);
-int lua_CheckBox_release(lua_State* state);
-int lua_CheckBox_removeListener(lua_State* state);
-int lua_CheckBox_removeScript(lua_State* state);
-int lua_CheckBox_removeScriptCallback(lua_State* state);
-int lua_CheckBox_setAlignment(lua_State* state);
-int lua_CheckBox_setAnimationPropertyValue(lua_State* state);
-int lua_CheckBox_setAutoSize(lua_State* state);
-int lua_CheckBox_setBorder(lua_State* state);
-int lua_CheckBox_setBounds(lua_State* state);
-int lua_CheckBox_setCanFocus(lua_State* state);
-int lua_CheckBox_setChecked(lua_State* state);
-int lua_CheckBox_setConsumeInputEvents(lua_State* state);
-int lua_CheckBox_setCursorColor(lua_State* state);
-int lua_CheckBox_setCursorRegion(lua_State* state);
-int lua_CheckBox_setEnabled(lua_State* state);
-int lua_CheckBox_setFocus(lua_State* state);
-int lua_CheckBox_setFocusIndex(lua_State* state);
-int lua_CheckBox_setFont(lua_State* state);
-int lua_CheckBox_setFontSize(lua_State* state);
-int lua_CheckBox_setHeight(lua_State* state);
-int lua_CheckBox_setId(lua_State* state);
-int lua_CheckBox_setImageColor(lua_State* state);
-int lua_CheckBox_setImageRegion(lua_State* state);
-int lua_CheckBox_setMargin(lua_State* state);
-int lua_CheckBox_setOpacity(lua_State* state);
-int lua_CheckBox_setPadding(lua_State* state);
-int lua_CheckBox_setPosition(lua_State* state);
-int lua_CheckBox_setSize(lua_State* state);
-int lua_CheckBox_setSkinColor(lua_State* state);
-int lua_CheckBox_setSkinRegion(lua_State* state);
-int lua_CheckBox_setStyle(lua_State* state);
-int lua_CheckBox_setText(lua_State* state);
-int lua_CheckBox_setTextAlignment(lua_State* state);
-int lua_CheckBox_setTextColor(lua_State* state);
-int lua_CheckBox_setTextRightToLeft(lua_State* state);
-int lua_CheckBox_setVisible(lua_State* state);
-int lua_CheckBox_setWidth(lua_State* state);
-int lua_CheckBox_setX(lua_State* state);
-int lua_CheckBox_setY(lua_State* state);
-int lua_CheckBox_setZIndex(lua_State* state);
-int lua_CheckBox_static_ANIMATE_OPACITY(lua_State* state);
-int lua_CheckBox_static_ANIMATE_POSITION(lua_State* state);
-int lua_CheckBox_static_ANIMATE_POSITION_X(lua_State* state);
-int lua_CheckBox_static_ANIMATE_POSITION_Y(lua_State* state);
-int lua_CheckBox_static_ANIMATE_SIZE(lua_State* state);
-int lua_CheckBox_static_ANIMATE_SIZE_HEIGHT(lua_State* state);
-int lua_CheckBox_static_ANIMATE_SIZE_WIDTH(lua_State* state);
-int lua_CheckBox_static_create(lua_State* state);
-
 void luaRegister_CheckBox();
 
 }

File diff suppressed because it is too large
+ 96 - 243
gameplay/src/lua/lua_Container.cpp


+ 0 - 139
gameplay/src/lua/lua_Container.h

@@ -5,145 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Container.
-int lua_Container__gc(lua_State* state);
-int lua_Container_addControl(lua_State* state);
-int lua_Container_addListener(lua_State* state);
-int lua_Container_addRef(lua_State* state);
-int lua_Container_addScript(lua_State* state);
-int lua_Container_addScriptCallback(lua_State* state);
-int lua_Container_canFocus(lua_State* state);
-int lua_Container_clearScripts(lua_State* state);
-int lua_Container_createAnimation(lua_State* state);
-int lua_Container_createAnimationFromBy(lua_State* state);
-int lua_Container_createAnimationFromTo(lua_State* state);
-int lua_Container_destroyAnimation(lua_State* state);
-int lua_Container_getAbsoluteBounds(lua_State* state);
-int lua_Container_getActiveControl(lua_State* state);
-int lua_Container_getAlignment(lua_State* state);
-int lua_Container_getAnimation(lua_State* state);
-int lua_Container_getAnimationPropertyComponentCount(lua_State* state);
-int lua_Container_getAnimationPropertyValue(lua_State* state);
-int lua_Container_getAutoSize(lua_State* state);
-int lua_Container_getBorder(lua_State* state);
-int lua_Container_getBounds(lua_State* state);
-int lua_Container_getClip(lua_State* state);
-int lua_Container_getClipBounds(lua_State* state);
-int lua_Container_getConsumeInputEvents(lua_State* state);
-int lua_Container_getControl(lua_State* state);
-int lua_Container_getControlCount(lua_State* state);
-int lua_Container_getCursorColor(lua_State* state);
-int lua_Container_getCursorRegion(lua_State* state);
-int lua_Container_getCursorUVs(lua_State* state);
-int lua_Container_getFocusIndex(lua_State* state);
-int lua_Container_getFont(lua_State* state);
-int lua_Container_getFontSize(lua_State* state);
-int lua_Container_getHeight(lua_State* state);
-int lua_Container_getId(lua_State* state);
-int lua_Container_getImageColor(lua_State* state);
-int lua_Container_getImageRegion(lua_State* state);
-int lua_Container_getImageUVs(lua_State* state);
-int lua_Container_getLayout(lua_State* state);
-int lua_Container_getMargin(lua_State* state);
-int lua_Container_getOpacity(lua_State* state);
-int lua_Container_getPadding(lua_State* state);
-int lua_Container_getParent(lua_State* state);
-int lua_Container_getRefCount(lua_State* state);
-int lua_Container_getScriptEvent(lua_State* state);
-int lua_Container_getScroll(lua_State* state);
-int lua_Container_getScrollPosition(lua_State* state);
-int lua_Container_getScrollWheelRequiresFocus(lua_State* state);
-int lua_Container_getScrollWheelSpeed(lua_State* state);
-int lua_Container_getScrollingFriction(lua_State* state);
-int lua_Container_getSkinColor(lua_State* state);
-int lua_Container_getSkinRegion(lua_State* state);
-int lua_Container_getState(lua_State* state);
-int lua_Container_getStyle(lua_State* state);
-int lua_Container_getTextAlignment(lua_State* state);
-int lua_Container_getTextColor(lua_State* state);
-int lua_Container_getTextRightToLeft(lua_State* state);
-int lua_Container_getTheme(lua_State* state);
-int lua_Container_getTopLevelForm(lua_State* state);
-int lua_Container_getTypeName(lua_State* state);
-int lua_Container_getWidth(lua_State* state);
-int lua_Container_getX(lua_State* state);
-int lua_Container_getY(lua_State* state);
-int lua_Container_getZIndex(lua_State* state);
-int lua_Container_hasFocus(lua_State* state);
-int lua_Container_hasScriptListener(lua_State* state);
-int lua_Container_insertControl(lua_State* state);
-int lua_Container_isChild(lua_State* state);
-int lua_Container_isContainer(lua_State* state);
-int lua_Container_isEnabled(lua_State* state);
-int lua_Container_isEnabledInHierarchy(lua_State* state);
-int lua_Container_isForm(lua_State* state);
-int lua_Container_isHeightPercentage(lua_State* state);
-int lua_Container_isScrollBarsAutoHide(lua_State* state);
-int lua_Container_isScrolling(lua_State* state);
-int lua_Container_isVisible(lua_State* state);
-int lua_Container_isVisibleInHierarchy(lua_State* state);
-int lua_Container_isWidthPercentage(lua_State* state);
-int lua_Container_isXPercentage(lua_State* state);
-int lua_Container_isYPercentage(lua_State* state);
-int lua_Container_moveFocus(lua_State* state);
-int lua_Container_release(lua_State* state);
-int lua_Container_removeControl(lua_State* state);
-int lua_Container_removeListener(lua_State* state);
-int lua_Container_removeScript(lua_State* state);
-int lua_Container_removeScriptCallback(lua_State* state);
-int lua_Container_setActiveControl(lua_State* state);
-int lua_Container_setAlignment(lua_State* state);
-int lua_Container_setAnimationPropertyValue(lua_State* state);
-int lua_Container_setAutoSize(lua_State* state);
-int lua_Container_setBorder(lua_State* state);
-int lua_Container_setBounds(lua_State* state);
-int lua_Container_setCanFocus(lua_State* state);
-int lua_Container_setConsumeInputEvents(lua_State* state);
-int lua_Container_setCursorColor(lua_State* state);
-int lua_Container_setCursorRegion(lua_State* state);
-int lua_Container_setEnabled(lua_State* state);
-int lua_Container_setFocus(lua_State* state);
-int lua_Container_setFocusIndex(lua_State* state);
-int lua_Container_setFont(lua_State* state);
-int lua_Container_setFontSize(lua_State* state);
-int lua_Container_setHeight(lua_State* state);
-int lua_Container_setId(lua_State* state);
-int lua_Container_setImageColor(lua_State* state);
-int lua_Container_setImageRegion(lua_State* state);
-int lua_Container_setLayout(lua_State* state);
-int lua_Container_setMargin(lua_State* state);
-int lua_Container_setOpacity(lua_State* state);
-int lua_Container_setPadding(lua_State* state);
-int lua_Container_setPosition(lua_State* state);
-int lua_Container_setScroll(lua_State* state);
-int lua_Container_setScrollBarsAutoHide(lua_State* state);
-int lua_Container_setScrollPosition(lua_State* state);
-int lua_Container_setScrollWheelRequiresFocus(lua_State* state);
-int lua_Container_setScrollWheelSpeed(lua_State* state);
-int lua_Container_setScrollingFriction(lua_State* state);
-int lua_Container_setSize(lua_State* state);
-int lua_Container_setSkinColor(lua_State* state);
-int lua_Container_setSkinRegion(lua_State* state);
-int lua_Container_setStyle(lua_State* state);
-int lua_Container_setTextAlignment(lua_State* state);
-int lua_Container_setTextColor(lua_State* state);
-int lua_Container_setTextRightToLeft(lua_State* state);
-int lua_Container_setVisible(lua_State* state);
-int lua_Container_setWidth(lua_State* state);
-int lua_Container_setX(lua_State* state);
-int lua_Container_setY(lua_State* state);
-int lua_Container_setZIndex(lua_State* state);
-int lua_Container_static_ANIMATE_OPACITY(lua_State* state);
-int lua_Container_static_ANIMATE_POSITION(lua_State* state);
-int lua_Container_static_ANIMATE_POSITION_X(lua_State* state);
-int lua_Container_static_ANIMATE_POSITION_Y(lua_State* state);
-int lua_Container_static_ANIMATE_SCROLLBAR_OPACITY(lua_State* state);
-int lua_Container_static_ANIMATE_SIZE(lua_State* state);
-int lua_Container_static_ANIMATE_SIZE_HEIGHT(lua_State* state);
-int lua_Container_static_ANIMATE_SIZE_WIDTH(lua_State* state);
-int lua_Container_static_create(lua_State* state);
-int lua_Container_stopScrolling(lua_State* state);
-
 void luaRegister_Container();
 
 }

File diff suppressed because it is too large
+ 111 - 217
gameplay/src/lua/lua_Control.cpp


+ 0 - 112
gameplay/src/lua/lua_Control.h

@@ -5,118 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Control.
-int lua_Control__gc(lua_State* state);
-int lua_Control_addListener(lua_State* state);
-int lua_Control_addRef(lua_State* state);
-int lua_Control_addScript(lua_State* state);
-int lua_Control_addScriptCallback(lua_State* state);
-int lua_Control_canFocus(lua_State* state);
-int lua_Control_clearScripts(lua_State* state);
-int lua_Control_createAnimation(lua_State* state);
-int lua_Control_createAnimationFromBy(lua_State* state);
-int lua_Control_createAnimationFromTo(lua_State* state);
-int lua_Control_destroyAnimation(lua_State* state);
-int lua_Control_getAbsoluteBounds(lua_State* state);
-int lua_Control_getAlignment(lua_State* state);
-int lua_Control_getAnimation(lua_State* state);
-int lua_Control_getAnimationPropertyComponentCount(lua_State* state);
-int lua_Control_getAnimationPropertyValue(lua_State* state);
-int lua_Control_getAutoSize(lua_State* state);
-int lua_Control_getBorder(lua_State* state);
-int lua_Control_getBounds(lua_State* state);
-int lua_Control_getClip(lua_State* state);
-int lua_Control_getClipBounds(lua_State* state);
-int lua_Control_getConsumeInputEvents(lua_State* state);
-int lua_Control_getCursorColor(lua_State* state);
-int lua_Control_getCursorRegion(lua_State* state);
-int lua_Control_getCursorUVs(lua_State* state);
-int lua_Control_getFocusIndex(lua_State* state);
-int lua_Control_getFont(lua_State* state);
-int lua_Control_getFontSize(lua_State* state);
-int lua_Control_getHeight(lua_State* state);
-int lua_Control_getId(lua_State* state);
-int lua_Control_getImageColor(lua_State* state);
-int lua_Control_getImageRegion(lua_State* state);
-int lua_Control_getImageUVs(lua_State* state);
-int lua_Control_getMargin(lua_State* state);
-int lua_Control_getOpacity(lua_State* state);
-int lua_Control_getPadding(lua_State* state);
-int lua_Control_getParent(lua_State* state);
-int lua_Control_getRefCount(lua_State* state);
-int lua_Control_getScriptEvent(lua_State* state);
-int lua_Control_getSkinColor(lua_State* state);
-int lua_Control_getSkinRegion(lua_State* state);
-int lua_Control_getState(lua_State* state);
-int lua_Control_getStyle(lua_State* state);
-int lua_Control_getTextAlignment(lua_State* state);
-int lua_Control_getTextColor(lua_State* state);
-int lua_Control_getTextRightToLeft(lua_State* state);
-int lua_Control_getTheme(lua_State* state);
-int lua_Control_getTopLevelForm(lua_State* state);
-int lua_Control_getTypeName(lua_State* state);
-int lua_Control_getWidth(lua_State* state);
-int lua_Control_getX(lua_State* state);
-int lua_Control_getY(lua_State* state);
-int lua_Control_getZIndex(lua_State* state);
-int lua_Control_hasFocus(lua_State* state);
-int lua_Control_hasScriptListener(lua_State* state);
-int lua_Control_isChild(lua_State* state);
-int lua_Control_isContainer(lua_State* state);
-int lua_Control_isEnabled(lua_State* state);
-int lua_Control_isEnabledInHierarchy(lua_State* state);
-int lua_Control_isHeightPercentage(lua_State* state);
-int lua_Control_isVisible(lua_State* state);
-int lua_Control_isVisibleInHierarchy(lua_State* state);
-int lua_Control_isWidthPercentage(lua_State* state);
-int lua_Control_isXPercentage(lua_State* state);
-int lua_Control_isYPercentage(lua_State* state);
-int lua_Control_release(lua_State* state);
-int lua_Control_removeListener(lua_State* state);
-int lua_Control_removeScript(lua_State* state);
-int lua_Control_removeScriptCallback(lua_State* state);
-int lua_Control_setAlignment(lua_State* state);
-int lua_Control_setAnimationPropertyValue(lua_State* state);
-int lua_Control_setAutoSize(lua_State* state);
-int lua_Control_setBorder(lua_State* state);
-int lua_Control_setBounds(lua_State* state);
-int lua_Control_setCanFocus(lua_State* state);
-int lua_Control_setConsumeInputEvents(lua_State* state);
-int lua_Control_setCursorColor(lua_State* state);
-int lua_Control_setCursorRegion(lua_State* state);
-int lua_Control_setEnabled(lua_State* state);
-int lua_Control_setFocus(lua_State* state);
-int lua_Control_setFocusIndex(lua_State* state);
-int lua_Control_setFont(lua_State* state);
-int lua_Control_setFontSize(lua_State* state);
-int lua_Control_setHeight(lua_State* state);
-int lua_Control_setId(lua_State* state);
-int lua_Control_setImageColor(lua_State* state);
-int lua_Control_setImageRegion(lua_State* state);
-int lua_Control_setMargin(lua_State* state);
-int lua_Control_setOpacity(lua_State* state);
-int lua_Control_setPadding(lua_State* state);
-int lua_Control_setPosition(lua_State* state);
-int lua_Control_setSize(lua_State* state);
-int lua_Control_setSkinColor(lua_State* state);
-int lua_Control_setSkinRegion(lua_State* state);
-int lua_Control_setStyle(lua_State* state);
-int lua_Control_setTextAlignment(lua_State* state);
-int lua_Control_setTextColor(lua_State* state);
-int lua_Control_setTextRightToLeft(lua_State* state);
-int lua_Control_setVisible(lua_State* state);
-int lua_Control_setWidth(lua_State* state);
-int lua_Control_setX(lua_State* state);
-int lua_Control_setY(lua_State* state);
-int lua_Control_setZIndex(lua_State* state);
-int lua_Control_static_ANIMATE_OPACITY(lua_State* state);
-int lua_Control_static_ANIMATE_POSITION(lua_State* state);
-int lua_Control_static_ANIMATE_POSITION_X(lua_State* state);
-int lua_Control_static_ANIMATE_POSITION_Y(lua_State* state);
-int lua_Control_static_ANIMATE_SIZE(lua_State* state);
-int lua_Control_static_ANIMATE_SIZE_HEIGHT(lua_State* state);
-int lua_Control_static_ANIMATE_SIZE_WIDTH(lua_State* state);
-
 void luaRegister_Control();
 
 }

+ 26 - 16
gameplay/src/lua/lua_ControlListener.cpp

@@ -5,33 +5,28 @@
 #include "Animation.h"
 #include "AnimationTarget.h"
 #include "Base.h"
+#include "Button.h"
+#include "CheckBox.h"
+#include "Container.h"
 #include "Control.h"
 #include "Form.h"
 #include "Game.h"
+#include "ImageControl.h"
+#include "JoystickControl.h"
+#include "Label.h"
 #include "MaterialParameter.h"
 #include "Node.h"
+#include "RadioButton.h"
 #include "Ref.h"
 #include "ScriptController.h"
 #include "ScriptTarget.h"
+#include "Slider.h"
+#include "TextBox.h"
 #include "Theme.h"
 
 namespace gameplay
 {
 
-void luaRegister_ControlListener()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"controlEvent", lua_ControlListener_controlEvent},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-    scopePath.push_back("Control");
-
-    gameplay::ScriptUtil::registerClass("ControlListener", lua_members, NULL, lua_ControlListener__gc, lua_statics, scopePath);
-}
-
 static Control::Listener* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "ControlListener");
@@ -39,7 +34,7 @@ static Control::Listener* getInstance(lua_State* state)
     return (Control::Listener*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_ControlListener__gc(lua_State* state)
+static int lua_ControlListener__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -77,7 +72,7 @@ int lua_ControlListener__gc(lua_State* state)
     return 0;
 }
 
-int lua_ControlListener_controlEvent(lua_State* state)
+static int lua_ControlListener_controlEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -123,4 +118,19 @@ int lua_ControlListener_controlEvent(lua_State* state)
     return 0;
 }
 
+void luaRegister_ControlListener()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"controlEvent", lua_ControlListener_controlEvent},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+    scopePath.push_back("Control");
+
+    gameplay::ScriptUtil::registerClass("ControlListener", lua_members, NULL, lua_ControlListener__gc, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 4
gameplay/src/lua/lua_ControlListener.h

@@ -5,10 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Control::Listener.
-int lua_ControlListener__gc(lua_State* state);
-int lua_ControlListener_controlEvent(lua_State* state);
-
 void luaRegister_ControlListener();
 
 }

+ 95 - 45
gameplay/src/lua/lua_Curve.cpp

@@ -7,39 +7,12 @@
 #include "Game.h"
 #include "Quaternion.h"
 #include "Ref.h"
+#include "Ref.h"
 
 namespace gameplay
 {
 
-void luaRegister_Curve()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_Curve_addRef},
-        {"evaluate", lua_Curve_evaluate},
-        {"getComponentCount", lua_Curve_getComponentCount},
-        {"getEndTime", lua_Curve_getEndTime},
-        {"getPointCount", lua_Curve_getPointCount},
-        {"getPointInterpolation", lua_Curve_getPointInterpolation},
-        {"getPointTime", lua_Curve_getPointTime},
-        {"getPointValues", lua_Curve_getPointValues},
-        {"getRefCount", lua_Curve_getRefCount},
-        {"getStartTime", lua_Curve_getStartTime},
-        {"release", lua_Curve_release},
-        {"setPoint", lua_Curve_setPoint},
-        {"setTangent", lua_Curve_setTangent},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"create", lua_Curve_static_create},
-        {"lerp", lua_Curve_static_lerp},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("Curve", lua_members, NULL, lua_Curve__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static Curve* getInstance(lua_State* state)
 {
@@ -48,7 +21,7 @@ static Curve* getInstance(lua_State* state)
     return (Curve*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_Curve__gc(lua_State* state)
+static int lua_Curve__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -86,7 +59,7 @@ int lua_Curve__gc(lua_State* state)
     return 0;
 }
 
-int lua_Curve_addRef(lua_State* state)
+static int lua_Curve_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -118,7 +91,7 @@ int lua_Curve_addRef(lua_State* state)
     return 0;
 }
 
-int lua_Curve_evaluate(lua_State* state)
+static int lua_Curve_evaluate(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -198,7 +171,7 @@ int lua_Curve_evaluate(lua_State* state)
     return 0;
 }
 
-int lua_Curve_getComponentCount(lua_State* state)
+static int lua_Curve_getComponentCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -233,7 +206,7 @@ int lua_Curve_getComponentCount(lua_State* state)
     return 0;
 }
 
-int lua_Curve_getEndTime(lua_State* state)
+static int lua_Curve_getEndTime(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -268,7 +241,7 @@ int lua_Curve_getEndTime(lua_State* state)
     return 0;
 }
 
-int lua_Curve_getPointCount(lua_State* state)
+static int lua_Curve_getPointCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -303,7 +276,7 @@ int lua_Curve_getPointCount(lua_State* state)
     return 0;
 }
 
-int lua_Curve_getPointInterpolation(lua_State* state)
+static int lua_Curve_getPointInterpolation(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -342,7 +315,7 @@ int lua_Curve_getPointInterpolation(lua_State* state)
     return 0;
 }
 
-int lua_Curve_getPointTime(lua_State* state)
+static int lua_Curve_getPointTime(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -381,7 +354,7 @@ int lua_Curve_getPointTime(lua_State* state)
     return 0;
 }
 
-int lua_Curve_getPointValues(lua_State* state)
+static int lua_Curve_getPointValues(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -429,7 +402,7 @@ int lua_Curve_getPointValues(lua_State* state)
     return 0;
 }
 
-int lua_Curve_getRefCount(lua_State* state)
+static int lua_Curve_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -464,7 +437,7 @@ int lua_Curve_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_Curve_getStartTime(lua_State* state)
+static int lua_Curve_getStartTime(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -499,7 +472,7 @@ int lua_Curve_getStartTime(lua_State* state)
     return 0;
 }
 
-int lua_Curve_release(lua_State* state)
+static int lua_Curve_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -531,7 +504,7 @@ int lua_Curve_release(lua_State* state)
     return 0;
 }
 
-int lua_Curve_setPoint(lua_State* state)
+static int lua_Curve_setPoint(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -623,7 +596,7 @@ int lua_Curve_setPoint(lua_State* state)
     return 0;
 }
 
-int lua_Curve_setTangent(lua_State* state)
+static int lua_Curve_setTangent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -671,7 +644,7 @@ int lua_Curve_setTangent(lua_State* state)
     return 0;
 }
 
-int lua_Curve_static_create(lua_State* state)
+static int lua_Curve_static_create(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -721,7 +694,7 @@ int lua_Curve_static_create(lua_State* state)
     return 0;
 }
 
-int lua_Curve_static_lerp(lua_State* state)
+static int lua_Curve_static_lerp(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -766,4 +739,81 @@ int lua_Curve_static_lerp(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of Curve
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    Curve* ptrObject = reinterpret_cast<Curve*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_Curve_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_Curve_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    Curve* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_Curve()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_Curve_addRef},
+        {"evaluate", lua_Curve_evaluate},
+        {"getComponentCount", lua_Curve_getComponentCount},
+        {"getEndTime", lua_Curve_getEndTime},
+        {"getPointCount", lua_Curve_getPointCount},
+        {"getPointInterpolation", lua_Curve_getPointInterpolation},
+        {"getPointTime", lua_Curve_getPointTime},
+        {"getPointValues", lua_Curve_getPointValues},
+        {"getRefCount", lua_Curve_getRefCount},
+        {"getStartTime", lua_Curve_getStartTime},
+        {"release", lua_Curve_release},
+        {"setPoint", lua_Curve_setPoint},
+        {"setTangent", lua_Curve_setTangent},
+        {"to", lua_Curve_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"create", lua_Curve_static_create},
+        {"lerp", lua_Curve_static_lerp},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("Curve", lua_members, NULL, lua_Curve__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("Curve", __convertTo);
+}
+
 }

+ 0 - 18
gameplay/src/lua/lua_Curve.h

@@ -5,24 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Curve.
-int lua_Curve__gc(lua_State* state);
-int lua_Curve_addRef(lua_State* state);
-int lua_Curve_evaluate(lua_State* state);
-int lua_Curve_getComponentCount(lua_State* state);
-int lua_Curve_getEndTime(lua_State* state);
-int lua_Curve_getPointCount(lua_State* state);
-int lua_Curve_getPointInterpolation(lua_State* state);
-int lua_Curve_getPointTime(lua_State* state);
-int lua_Curve_getPointValues(lua_State* state);
-int lua_Curve_getRefCount(lua_State* state);
-int lua_Curve_getStartTime(lua_State* state);
-int lua_Curve_release(lua_State* state);
-int lua_Curve_setPoint(lua_State* state);
-int lua_Curve_setTangent(lua_State* state);
-int lua_Curve_static_create(lua_State* state);
-int lua_Curve_static_lerp(lua_State* state);
-
 void luaRegister_Curve();
 
 }

+ 85 - 35
gameplay/src/lua/lua_DepthStencilTarget.cpp

@@ -6,34 +6,12 @@
 #include "DepthStencilTarget.h"
 #include "Game.h"
 #include "Ref.h"
+#include "Ref.h"
 
 namespace gameplay
 {
 
-void luaRegister_DepthStencilTarget()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_DepthStencilTarget_addRef},
-        {"getFormat", lua_DepthStencilTarget_getFormat},
-        {"getHeight", lua_DepthStencilTarget_getHeight},
-        {"getId", lua_DepthStencilTarget_getId},
-        {"getRefCount", lua_DepthStencilTarget_getRefCount},
-        {"getWidth", lua_DepthStencilTarget_getWidth},
-        {"isPacked", lua_DepthStencilTarget_isPacked},
-        {"release", lua_DepthStencilTarget_release},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"create", lua_DepthStencilTarget_static_create},
-        {"getDepthStencilTarget", lua_DepthStencilTarget_static_getDepthStencilTarget},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("DepthStencilTarget", lua_members, NULL, lua_DepthStencilTarget__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static DepthStencilTarget* getInstance(lua_State* state)
 {
@@ -42,7 +20,7 @@ static DepthStencilTarget* getInstance(lua_State* state)
     return (DepthStencilTarget*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_DepthStencilTarget__gc(lua_State* state)
+static int lua_DepthStencilTarget__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -80,7 +58,7 @@ int lua_DepthStencilTarget__gc(lua_State* state)
     return 0;
 }
 
-int lua_DepthStencilTarget_addRef(lua_State* state)
+static int lua_DepthStencilTarget_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -112,7 +90,7 @@ int lua_DepthStencilTarget_addRef(lua_State* state)
     return 0;
 }
 
-int lua_DepthStencilTarget_getFormat(lua_State* state)
+static int lua_DepthStencilTarget_getFormat(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -147,7 +125,7 @@ int lua_DepthStencilTarget_getFormat(lua_State* state)
     return 0;
 }
 
-int lua_DepthStencilTarget_getHeight(lua_State* state)
+static int lua_DepthStencilTarget_getHeight(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -182,7 +160,7 @@ int lua_DepthStencilTarget_getHeight(lua_State* state)
     return 0;
 }
 
-int lua_DepthStencilTarget_getId(lua_State* state)
+static int lua_DepthStencilTarget_getId(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -217,7 +195,7 @@ int lua_DepthStencilTarget_getId(lua_State* state)
     return 0;
 }
 
-int lua_DepthStencilTarget_getRefCount(lua_State* state)
+static int lua_DepthStencilTarget_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -252,7 +230,7 @@ int lua_DepthStencilTarget_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_DepthStencilTarget_getWidth(lua_State* state)
+static int lua_DepthStencilTarget_getWidth(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -287,7 +265,7 @@ int lua_DepthStencilTarget_getWidth(lua_State* state)
     return 0;
 }
 
-int lua_DepthStencilTarget_isPacked(lua_State* state)
+static int lua_DepthStencilTarget_isPacked(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -322,7 +300,7 @@ int lua_DepthStencilTarget_isPacked(lua_State* state)
     return 0;
 }
 
-int lua_DepthStencilTarget_release(lua_State* state)
+static int lua_DepthStencilTarget_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -354,7 +332,7 @@ int lua_DepthStencilTarget_release(lua_State* state)
     return 0;
 }
 
-int lua_DepthStencilTarget_static_create(lua_State* state)
+static int lua_DepthStencilTarget_static_create(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -412,7 +390,7 @@ int lua_DepthStencilTarget_static_create(lua_State* state)
     return 0;
 }
 
-int lua_DepthStencilTarget_static_getDepthStencilTarget(lua_State* state)
+static int lua_DepthStencilTarget_static_getDepthStencilTarget(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -458,4 +436,76 @@ int lua_DepthStencilTarget_static_getDepthStencilTarget(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of DepthStencilTarget
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    DepthStencilTarget* ptrObject = reinterpret_cast<DepthStencilTarget*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_DepthStencilTarget_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_DepthStencilTarget_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    DepthStencilTarget* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_DepthStencilTarget()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_DepthStencilTarget_addRef},
+        {"getFormat", lua_DepthStencilTarget_getFormat},
+        {"getHeight", lua_DepthStencilTarget_getHeight},
+        {"getId", lua_DepthStencilTarget_getId},
+        {"getRefCount", lua_DepthStencilTarget_getRefCount},
+        {"getWidth", lua_DepthStencilTarget_getWidth},
+        {"isPacked", lua_DepthStencilTarget_isPacked},
+        {"release", lua_DepthStencilTarget_release},
+        {"to", lua_DepthStencilTarget_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"create", lua_DepthStencilTarget_static_create},
+        {"getDepthStencilTarget", lua_DepthStencilTarget_static_getDepthStencilTarget},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("DepthStencilTarget", lua_members, NULL, lua_DepthStencilTarget__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("DepthStencilTarget", __convertTo);
+}
+
 }

+ 0 - 13
gameplay/src/lua/lua_DepthStencilTarget.h

@@ -5,19 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for DepthStencilTarget.
-int lua_DepthStencilTarget__gc(lua_State* state);
-int lua_DepthStencilTarget_addRef(lua_State* state);
-int lua_DepthStencilTarget_getFormat(lua_State* state);
-int lua_DepthStencilTarget_getHeight(lua_State* state);
-int lua_DepthStencilTarget_getId(lua_State* state);
-int lua_DepthStencilTarget_getRefCount(lua_State* state);
-int lua_DepthStencilTarget_getWidth(lua_State* state);
-int lua_DepthStencilTarget_isPacked(lua_State* state);
-int lua_DepthStencilTarget_release(lua_State* state);
-int lua_DepthStencilTarget_static_create(lua_State* state);
-int lua_DepthStencilTarget_static_getDepthStencilTarget(lua_State* state);
-
 void luaRegister_DepthStencilTarget();
 
 }

+ 103 - 16
gameplay/src/lua/lua_Drawable.cpp

@@ -4,24 +4,26 @@
 #include "lua_Drawable.h"
 #include "Base.h"
 #include "Drawable.h"
+#include "Form.h"
+#include "Model.h"
 #include "Node.h"
+#include "ParticleEmitter.h"
+#include "Sprite.h"
+#include "Terrain.h"
+#include "Text.h"
+#include "TileSet.h"
+#include "Form.h"
+#include "Model.h"
+#include "ParticleEmitter.h"
+#include "Sprite.h"
+#include "Terrain.h"
+#include "Text.h"
+#include "TileSet.h"
 
 namespace gameplay
 {
 
-void luaRegister_Drawable()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"draw", lua_Drawable_draw},
-        {"getNode", lua_Drawable_getNode},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("Drawable", lua_members, NULL, lua_Drawable__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static Drawable* getInstance(lua_State* state)
 {
@@ -30,7 +32,7 @@ static Drawable* getInstance(lua_State* state)
     return (Drawable*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_Drawable__gc(lua_State* state)
+static int lua_Drawable__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -68,7 +70,7 @@ int lua_Drawable__gc(lua_State* state)
     return 0;
 }
 
-int lua_Drawable_draw(lua_State* state)
+static int lua_Drawable_draw(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -124,7 +126,7 @@ int lua_Drawable_draw(lua_State* state)
     return 0;
 }
 
-int lua_Drawable_getNode(lua_State* state)
+static int lua_Drawable_getNode(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -168,4 +170,89 @@ int lua_Drawable_getNode(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of Drawable
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    Drawable* ptrObject = reinterpret_cast<Drawable*>(ptr);
+
+    if (strcmp(typeName, "Form") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Form*>(ptrObject));
+    }
+    else if (strcmp(typeName, "Model") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Model*>(ptrObject));
+    }
+    else if (strcmp(typeName, "ParticleEmitter") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<ParticleEmitter*>(ptrObject));
+    }
+    else if (strcmp(typeName, "Sprite") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Sprite*>(ptrObject));
+    }
+    else if (strcmp(typeName, "Terrain") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Terrain*>(ptrObject));
+    }
+    else if (strcmp(typeName, "Text") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Text*>(ptrObject));
+    }
+    else if (strcmp(typeName, "TileSet") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<TileSet*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_Drawable_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_Drawable_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    Drawable* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_Drawable()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"draw", lua_Drawable_draw},
+        {"getNode", lua_Drawable_getNode},
+        {"to", lua_Drawable_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("Drawable", lua_members, NULL, lua_Drawable__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("Drawable", __convertTo);
+}
+
 }

+ 0 - 5
gameplay/src/lua/lua_Drawable.h

@@ -5,11 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Drawable.
-int lua_Drawable__gc(lua_State* state);
-int lua_Drawable_draw(lua_State* state);
-int lua_Drawable_getNode(lua_State* state);
-
 void luaRegister_Drawable();
 
 }

+ 89 - 39
gameplay/src/lua/lua_Effect.cpp

@@ -7,36 +7,12 @@
 #include "FileSystem.h"
 #include "Game.h"
 #include "Ref.h"
+#include "Ref.h"
 
 namespace gameplay
 {
 
-void luaRegister_Effect()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_Effect_addRef},
-        {"bind", lua_Effect_bind},
-        {"getId", lua_Effect_getId},
-        {"getRefCount", lua_Effect_getRefCount},
-        {"getUniform", lua_Effect_getUniform},
-        {"getUniformCount", lua_Effect_getUniformCount},
-        {"getVertexAttribute", lua_Effect_getVertexAttribute},
-        {"release", lua_Effect_release},
-        {"setValue", lua_Effect_setValue},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"createFromFile", lua_Effect_static_createFromFile},
-        {"createFromSource", lua_Effect_static_createFromSource},
-        {"getCurrentEffect", lua_Effect_static_getCurrentEffect},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("Effect", lua_members, NULL, lua_Effect__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static Effect* getInstance(lua_State* state)
 {
@@ -45,7 +21,7 @@ static Effect* getInstance(lua_State* state)
     return (Effect*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_Effect__gc(lua_State* state)
+static int lua_Effect__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -83,7 +59,7 @@ int lua_Effect__gc(lua_State* state)
     return 0;
 }
 
-int lua_Effect_addRef(lua_State* state)
+static int lua_Effect_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -115,7 +91,7 @@ int lua_Effect_addRef(lua_State* state)
     return 0;
 }
 
-int lua_Effect_bind(lua_State* state)
+static int lua_Effect_bind(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -147,7 +123,7 @@ int lua_Effect_bind(lua_State* state)
     return 0;
 }
 
-int lua_Effect_getId(lua_State* state)
+static int lua_Effect_getId(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -182,7 +158,7 @@ int lua_Effect_getId(lua_State* state)
     return 0;
 }
 
-int lua_Effect_getRefCount(lua_State* state)
+static int lua_Effect_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -217,7 +193,7 @@ int lua_Effect_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_Effect_getUniform(lua_State* state)
+static int lua_Effect_getUniform(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -295,7 +271,7 @@ int lua_Effect_getUniform(lua_State* state)
     return 0;
 }
 
-int lua_Effect_getUniformCount(lua_State* state)
+static int lua_Effect_getUniformCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -330,7 +306,7 @@ int lua_Effect_getUniformCount(lua_State* state)
     return 0;
 }
 
-int lua_Effect_getVertexAttribute(lua_State* state)
+static int lua_Effect_getVertexAttribute(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -378,7 +354,7 @@ int lua_Effect_getVertexAttribute(lua_State* state)
     return 0;
 }
 
-int lua_Effect_release(lua_State* state)
+static int lua_Effect_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -410,7 +386,7 @@ int lua_Effect_release(lua_State* state)
     return 0;
 }
 
-int lua_Effect_setValue(lua_State* state)
+static int lua_Effect_setValue(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -921,7 +897,7 @@ int lua_Effect_setValue(lua_State* state)
     return 0;
 }
 
-int lua_Effect_static_createFromFile(lua_State* state)
+static int lua_Effect_static_createFromFile(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1007,7 +983,7 @@ int lua_Effect_static_createFromFile(lua_State* state)
     return 0;
 }
 
-int lua_Effect_static_createFromSource(lua_State* state)
+static int lua_Effect_static_createFromSource(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1093,7 +1069,7 @@ int lua_Effect_static_createFromSource(lua_State* state)
     return 0;
 }
 
-int lua_Effect_static_getCurrentEffect(lua_State* state)
+static int lua_Effect_static_getCurrentEffect(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1130,4 +1106,78 @@ int lua_Effect_static_getCurrentEffect(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of Effect
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    Effect* ptrObject = reinterpret_cast<Effect*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_Effect_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_Effect_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    Effect* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_Effect()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_Effect_addRef},
+        {"bind", lua_Effect_bind},
+        {"getId", lua_Effect_getId},
+        {"getRefCount", lua_Effect_getRefCount},
+        {"getUniform", lua_Effect_getUniform},
+        {"getUniformCount", lua_Effect_getUniformCount},
+        {"getVertexAttribute", lua_Effect_getVertexAttribute},
+        {"release", lua_Effect_release},
+        {"setValue", lua_Effect_setValue},
+        {"to", lua_Effect_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"createFromFile", lua_Effect_static_createFromFile},
+        {"createFromSource", lua_Effect_static_createFromSource},
+        {"getCurrentEffect", lua_Effect_static_getCurrentEffect},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("Effect", lua_members, NULL, lua_Effect__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("Effect", __convertTo);
+}
+
 }

+ 0 - 15
gameplay/src/lua/lua_Effect.h

@@ -5,21 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Effect.
-int lua_Effect__gc(lua_State* state);
-int lua_Effect_addRef(lua_State* state);
-int lua_Effect_bind(lua_State* state);
-int lua_Effect_getId(lua_State* state);
-int lua_Effect_getRefCount(lua_State* state);
-int lua_Effect_getUniform(lua_State* state);
-int lua_Effect_getUniformCount(lua_State* state);
-int lua_Effect_getVertexAttribute(lua_State* state);
-int lua_Effect_release(lua_State* state);
-int lua_Effect_setValue(lua_State* state);
-int lua_Effect_static_createFromFile(lua_State* state);
-int lua_Effect_static_createFromSource(lua_State* state);
-int lua_Effect_static_getCurrentEffect(lua_State* state);
-
 void luaRegister_Effect();
 
 }

+ 41 - 40
gameplay/src/lua/lua_FileSystem.cpp

@@ -11,33 +11,6 @@
 namespace gameplay
 {
 
-void luaRegister_FileSystem()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"createFileFromAsset", lua_FileSystem_static_createFileFromAsset},
-        {"fileExists", lua_FileSystem_static_fileExists},
-        {"getAssetPath", lua_FileSystem_static_getAssetPath},
-        {"getDirectoryName", lua_FileSystem_static_getDirectoryName},
-        {"getExtension", lua_FileSystem_static_getExtension},
-        {"getResourcePath", lua_FileSystem_static_getResourcePath},
-        {"isAbsolutePath", lua_FileSystem_static_isAbsolutePath},
-        {"loadResourceAliases", lua_FileSystem_static_loadResourceAliases},
-        {"readAll", lua_FileSystem_static_readAll},
-        {"resolvePath", lua_FileSystem_static_resolvePath},
-        {"setAssetPath", lua_FileSystem_static_setAssetPath},
-        {"setResourcePath", lua_FileSystem_static_setResourcePath},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("FileSystem", lua_members, NULL, lua_FileSystem__gc, lua_statics, scopePath);
-}
-
 static FileSystem* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "FileSystem");
@@ -45,7 +18,7 @@ static FileSystem* getInstance(lua_State* state)
     return (FileSystem*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_FileSystem__gc(lua_State* state)
+static int lua_FileSystem__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -83,7 +56,7 @@ int lua_FileSystem__gc(lua_State* state)
     return 0;
 }
 
-int lua_FileSystem_static_createFileFromAsset(lua_State* state)
+static int lua_FileSystem_static_createFileFromAsset(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -117,7 +90,7 @@ int lua_FileSystem_static_createFileFromAsset(lua_State* state)
     return 0;
 }
 
-int lua_FileSystem_static_fileExists(lua_State* state)
+static int lua_FileSystem_static_fileExists(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -154,7 +127,7 @@ int lua_FileSystem_static_fileExists(lua_State* state)
     return 0;
 }
 
-int lua_FileSystem_static_getAssetPath(lua_State* state)
+static int lua_FileSystem_static_getAssetPath(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -182,7 +155,7 @@ int lua_FileSystem_static_getAssetPath(lua_State* state)
     return 0;
 }
 
-int lua_FileSystem_static_getDirectoryName(lua_State* state)
+static int lua_FileSystem_static_getDirectoryName(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -219,7 +192,7 @@ int lua_FileSystem_static_getDirectoryName(lua_State* state)
     return 0;
 }
 
-int lua_FileSystem_static_getExtension(lua_State* state)
+static int lua_FileSystem_static_getExtension(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -256,7 +229,7 @@ int lua_FileSystem_static_getExtension(lua_State* state)
     return 0;
 }
 
-int lua_FileSystem_static_getResourcePath(lua_State* state)
+static int lua_FileSystem_static_getResourcePath(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -284,7 +257,7 @@ int lua_FileSystem_static_getResourcePath(lua_State* state)
     return 0;
 }
 
-int lua_FileSystem_static_isAbsolutePath(lua_State* state)
+static int lua_FileSystem_static_isAbsolutePath(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -321,7 +294,7 @@ int lua_FileSystem_static_isAbsolutePath(lua_State* state)
     return 0;
 }
 
-int lua_FileSystem_static_loadResourceAliases(lua_State* state)
+static int lua_FileSystem_static_loadResourceAliases(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -374,7 +347,7 @@ int lua_FileSystem_static_loadResourceAliases(lua_State* state)
     return 0;
 }
 
-int lua_FileSystem_static_readAll(lua_State* state)
+static int lua_FileSystem_static_readAll(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -434,7 +407,7 @@ int lua_FileSystem_static_readAll(lua_State* state)
     return 0;
 }
 
-int lua_FileSystem_static_resolvePath(lua_State* state)
+static int lua_FileSystem_static_resolvePath(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -471,7 +444,7 @@ int lua_FileSystem_static_resolvePath(lua_State* state)
     return 0;
 }
 
-int lua_FileSystem_static_setAssetPath(lua_State* state)
+static int lua_FileSystem_static_setAssetPath(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -505,7 +478,7 @@ int lua_FileSystem_static_setAssetPath(lua_State* state)
     return 0;
 }
 
-int lua_FileSystem_static_setResourcePath(lua_State* state)
+static int lua_FileSystem_static_setResourcePath(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -539,4 +512,32 @@ int lua_FileSystem_static_setResourcePath(lua_State* state)
     return 0;
 }
 
+void luaRegister_FileSystem()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"createFileFromAsset", lua_FileSystem_static_createFileFromAsset},
+        {"fileExists", lua_FileSystem_static_fileExists},
+        {"getAssetPath", lua_FileSystem_static_getAssetPath},
+        {"getDirectoryName", lua_FileSystem_static_getDirectoryName},
+        {"getExtension", lua_FileSystem_static_getExtension},
+        {"getResourcePath", lua_FileSystem_static_getResourcePath},
+        {"isAbsolutePath", lua_FileSystem_static_isAbsolutePath},
+        {"loadResourceAliases", lua_FileSystem_static_loadResourceAliases},
+        {"readAll", lua_FileSystem_static_readAll},
+        {"resolvePath", lua_FileSystem_static_resolvePath},
+        {"setAssetPath", lua_FileSystem_static_setAssetPath},
+        {"setResourcePath", lua_FileSystem_static_setResourcePath},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("FileSystem", lua_members, NULL, lua_FileSystem__gc, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 15
gameplay/src/lua/lua_FileSystem.h

@@ -5,21 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for FileSystem.
-int lua_FileSystem__gc(lua_State* state);
-int lua_FileSystem_static_createFileFromAsset(lua_State* state);
-int lua_FileSystem_static_fileExists(lua_State* state);
-int lua_FileSystem_static_getAssetPath(lua_State* state);
-int lua_FileSystem_static_getDirectoryName(lua_State* state);
-int lua_FileSystem_static_getExtension(lua_State* state);
-int lua_FileSystem_static_getResourcePath(lua_State* state);
-int lua_FileSystem_static_isAbsolutePath(lua_State* state);
-int lua_FileSystem_static_loadResourceAliases(lua_State* state);
-int lua_FileSystem_static_readAll(lua_State* state);
-int lua_FileSystem_static_resolvePath(lua_State* state);
-int lua_FileSystem_static_setAssetPath(lua_State* state);
-int lua_FileSystem_static_setResourcePath(lua_State* state);
-
 void luaRegister_FileSystem();
 
 }

+ 76 - 26
gameplay/src/lua/lua_FlowLayout.cpp

@@ -9,28 +9,12 @@
 #include "Game.h"
 #include "Layout.h"
 #include "Ref.h"
+#include "Layout.h"
 
 namespace gameplay
 {
 
-void luaRegister_FlowLayout()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_FlowLayout_addRef},
-        {"getHorizontalSpacing", lua_FlowLayout_getHorizontalSpacing},
-        {"getRefCount", lua_FlowLayout_getRefCount},
-        {"getType", lua_FlowLayout_getType},
-        {"getVerticalSpacing", lua_FlowLayout_getVerticalSpacing},
-        {"release", lua_FlowLayout_release},
-        {"setSpacing", lua_FlowLayout_setSpacing},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("FlowLayout", lua_members, NULL, lua_FlowLayout__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static FlowLayout* getInstance(lua_State* state)
 {
@@ -39,7 +23,7 @@ static FlowLayout* getInstance(lua_State* state)
     return (FlowLayout*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_FlowLayout__gc(lua_State* state)
+static int lua_FlowLayout__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -77,7 +61,7 @@ int lua_FlowLayout__gc(lua_State* state)
     return 0;
 }
 
-int lua_FlowLayout_addRef(lua_State* state)
+static int lua_FlowLayout_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -109,7 +93,7 @@ int lua_FlowLayout_addRef(lua_State* state)
     return 0;
 }
 
-int lua_FlowLayout_getHorizontalSpacing(lua_State* state)
+static int lua_FlowLayout_getHorizontalSpacing(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -144,7 +128,7 @@ int lua_FlowLayout_getHorizontalSpacing(lua_State* state)
     return 0;
 }
 
-int lua_FlowLayout_getRefCount(lua_State* state)
+static int lua_FlowLayout_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -179,7 +163,7 @@ int lua_FlowLayout_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_FlowLayout_getType(lua_State* state)
+static int lua_FlowLayout_getType(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -214,7 +198,7 @@ int lua_FlowLayout_getType(lua_State* state)
     return 0;
 }
 
-int lua_FlowLayout_getVerticalSpacing(lua_State* state)
+static int lua_FlowLayout_getVerticalSpacing(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -249,7 +233,7 @@ int lua_FlowLayout_getVerticalSpacing(lua_State* state)
     return 0;
 }
 
-int lua_FlowLayout_release(lua_State* state)
+static int lua_FlowLayout_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -281,7 +265,7 @@ int lua_FlowLayout_release(lua_State* state)
     return 0;
 }
 
-int lua_FlowLayout_setSpacing(lua_State* state)
+static int lua_FlowLayout_setSpacing(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -321,4 +305,70 @@ int lua_FlowLayout_setSpacing(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of FlowLayout
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    FlowLayout* ptrObject = reinterpret_cast<FlowLayout*>(ptr);
+
+    if (strcmp(typeName, "Layout") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Layout*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_FlowLayout_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_FlowLayout_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    FlowLayout* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_FlowLayout()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_FlowLayout_addRef},
+        {"getHorizontalSpacing", lua_FlowLayout_getHorizontalSpacing},
+        {"getRefCount", lua_FlowLayout_getRefCount},
+        {"getType", lua_FlowLayout_getType},
+        {"getVerticalSpacing", lua_FlowLayout_getVerticalSpacing},
+        {"release", lua_FlowLayout_release},
+        {"setSpacing", lua_FlowLayout_setSpacing},
+        {"to", lua_FlowLayout_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("FlowLayout", lua_members, NULL, lua_FlowLayout__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("FlowLayout", __convertTo);
+}
+
 }

+ 0 - 10
gameplay/src/lua/lua_FlowLayout.h

@@ -5,16 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for FlowLayout.
-int lua_FlowLayout__gc(lua_State* state);
-int lua_FlowLayout_addRef(lua_State* state);
-int lua_FlowLayout_getHorizontalSpacing(lua_State* state);
-int lua_FlowLayout_getRefCount(lua_State* state);
-int lua_FlowLayout_getType(lua_State* state);
-int lua_FlowLayout_getVerticalSpacing(lua_State* state);
-int lua_FlowLayout_release(lua_State* state);
-int lua_FlowLayout_setSpacing(lua_State* state);
-
 void luaRegister_FlowLayout();
 
 }

+ 101 - 51
gameplay/src/lua/lua_Font.cpp

@@ -10,42 +10,12 @@
 #include "Material.h"
 #include "Ref.h"
 #include "Text.h"
+#include "Ref.h"
 
 namespace gameplay
 {
 
-void luaRegister_Font()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_Font_addRef},
-        {"drawText", lua_Font_drawText},
-        {"finish", lua_Font_finish},
-        {"getCharacterSpacing", lua_Font_getCharacterSpacing},
-        {"getFormat", lua_Font_getFormat},
-        {"getIndexAtLocation", lua_Font_getIndexAtLocation},
-        {"getLocationAtIndex", lua_Font_getLocationAtIndex},
-        {"getRefCount", lua_Font_getRefCount},
-        {"getSize", lua_Font_getSize},
-        {"getSizeCount", lua_Font_getSizeCount},
-        {"getSpriteBatch", lua_Font_getSpriteBatch},
-        {"isCharacterSupported", lua_Font_isCharacterSupported},
-        {"measureText", lua_Font_measureText},
-        {"release", lua_Font_release},
-        {"setCharacterSpacing", lua_Font_setCharacterSpacing},
-        {"start", lua_Font_start},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"create", lua_Font_static_create},
-        {"getJustify", lua_Font_static_getJustify},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("Font", lua_members, NULL, lua_Font__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static Font* getInstance(lua_State* state)
 {
@@ -54,7 +24,7 @@ static Font* getInstance(lua_State* state)
     return (Font*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_Font__gc(lua_State* state)
+static int lua_Font__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -92,7 +62,7 @@ int lua_Font__gc(lua_State* state)
     return 0;
 }
 
-int lua_Font_addRef(lua_State* state)
+static int lua_Font_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -124,7 +94,7 @@ int lua_Font_addRef(lua_State* state)
     return 0;
 }
 
-int lua_Font_drawText(lua_State* state)
+static int lua_Font_drawText(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -652,7 +622,7 @@ int lua_Font_drawText(lua_State* state)
     return 0;
 }
 
-int lua_Font_finish(lua_State* state)
+static int lua_Font_finish(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -684,7 +654,7 @@ int lua_Font_finish(lua_State* state)
     return 0;
 }
 
-int lua_Font_getCharacterSpacing(lua_State* state)
+static int lua_Font_getCharacterSpacing(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -719,7 +689,7 @@ int lua_Font_getCharacterSpacing(lua_State* state)
     return 0;
 }
 
-int lua_Font_getFormat(lua_State* state)
+static int lua_Font_getFormat(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -754,7 +724,7 @@ int lua_Font_getFormat(lua_State* state)
     return 0;
 }
 
-int lua_Font_getIndexAtLocation(lua_State* state)
+static int lua_Font_getIndexAtLocation(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1016,7 +986,7 @@ int lua_Font_getIndexAtLocation(lua_State* state)
     return 0;
 }
 
-int lua_Font_getLocationAtIndex(lua_State* state)
+static int lua_Font_getLocationAtIndex(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1242,7 +1212,7 @@ int lua_Font_getLocationAtIndex(lua_State* state)
     return 0;
 }
 
-int lua_Font_getRefCount(lua_State* state)
+static int lua_Font_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1277,7 +1247,7 @@ int lua_Font_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_Font_getSize(lua_State* state)
+static int lua_Font_getSize(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1333,7 +1303,7 @@ int lua_Font_getSize(lua_State* state)
     return 0;
 }
 
-int lua_Font_getSizeCount(lua_State* state)
+static int lua_Font_getSizeCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1368,7 +1338,7 @@ int lua_Font_getSizeCount(lua_State* state)
     return 0;
 }
 
-int lua_Font_getSpriteBatch(lua_State* state)
+static int lua_Font_getSpriteBatch(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1416,7 +1386,7 @@ int lua_Font_getSpriteBatch(lua_State* state)
     return 0;
 }
 
-int lua_Font_isCharacterSupported(lua_State* state)
+static int lua_Font_isCharacterSupported(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1455,7 +1425,7 @@ int lua_Font_isCharacterSupported(lua_State* state)
     return 0;
 }
 
-int lua_Font_measureText(lua_State* state)
+static int lua_Font_measureText(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1680,7 +1650,7 @@ int lua_Font_measureText(lua_State* state)
     return 0;
 }
 
-int lua_Font_release(lua_State* state)
+static int lua_Font_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1712,7 +1682,7 @@ int lua_Font_release(lua_State* state)
     return 0;
 }
 
-int lua_Font_setCharacterSpacing(lua_State* state)
+static int lua_Font_setCharacterSpacing(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1748,7 +1718,7 @@ int lua_Font_setCharacterSpacing(lua_State* state)
     return 0;
 }
 
-int lua_Font_start(lua_State* state)
+static int lua_Font_start(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1780,7 +1750,7 @@ int lua_Font_start(lua_State* state)
     return 0;
 }
 
-int lua_Font_static_create(lua_State* state)
+static int lua_Font_static_create(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1858,7 +1828,7 @@ int lua_Font_static_create(lua_State* state)
     return 0;
 }
 
-int lua_Font_static_getJustify(lua_State* state)
+static int lua_Font_static_getJustify(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1895,4 +1865,84 @@ int lua_Font_static_getJustify(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of Font
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    Font* ptrObject = reinterpret_cast<Font*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_Font_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_Font_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    Font* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_Font()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_Font_addRef},
+        {"drawText", lua_Font_drawText},
+        {"finish", lua_Font_finish},
+        {"getCharacterSpacing", lua_Font_getCharacterSpacing},
+        {"getFormat", lua_Font_getFormat},
+        {"getIndexAtLocation", lua_Font_getIndexAtLocation},
+        {"getLocationAtIndex", lua_Font_getLocationAtIndex},
+        {"getRefCount", lua_Font_getRefCount},
+        {"getSize", lua_Font_getSize},
+        {"getSizeCount", lua_Font_getSizeCount},
+        {"getSpriteBatch", lua_Font_getSpriteBatch},
+        {"isCharacterSupported", lua_Font_isCharacterSupported},
+        {"measureText", lua_Font_measureText},
+        {"release", lua_Font_release},
+        {"setCharacterSpacing", lua_Font_setCharacterSpacing},
+        {"start", lua_Font_start},
+        {"to", lua_Font_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"create", lua_Font_static_create},
+        {"getJustify", lua_Font_static_getJustify},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("Font", lua_members, NULL, lua_Font__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("Font", __convertTo);
+}
+
 }

+ 0 - 21
gameplay/src/lua/lua_Font.h

@@ -5,27 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Font.
-int lua_Font__gc(lua_State* state);
-int lua_Font_addRef(lua_State* state);
-int lua_Font_drawText(lua_State* state);
-int lua_Font_finish(lua_State* state);
-int lua_Font_getCharacterSpacing(lua_State* state);
-int lua_Font_getFormat(lua_State* state);
-int lua_Font_getIndexAtLocation(lua_State* state);
-int lua_Font_getLocationAtIndex(lua_State* state);
-int lua_Font_getRefCount(lua_State* state);
-int lua_Font_getSize(lua_State* state);
-int lua_Font_getSizeCount(lua_State* state);
-int lua_Font_getSpriteBatch(lua_State* state);
-int lua_Font_isCharacterSupported(lua_State* state);
-int lua_Font_measureText(lua_State* state);
-int lua_Font_release(lua_State* state);
-int lua_Font_setCharacterSpacing(lua_State* state);
-int lua_Font_start(lua_State* state);
-int lua_Font_static_create(lua_State* state);
-int lua_Font_static_getJustify(lua_State* state);
-
 void luaRegister_Font();
 
 }

File diff suppressed because it is too large
+ 95 - 251
gameplay/src/lua/lua_Form.cpp


+ 0 - 148
gameplay/src/lua/lua_Form.h

@@ -5,154 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Form.
-int lua_Form__gc(lua_State* state);
-int lua_Form_addControl(lua_State* state);
-int lua_Form_addListener(lua_State* state);
-int lua_Form_addRef(lua_State* state);
-int lua_Form_addScript(lua_State* state);
-int lua_Form_addScriptCallback(lua_State* state);
-int lua_Form_canFocus(lua_State* state);
-int lua_Form_clearScripts(lua_State* state);
-int lua_Form_createAnimation(lua_State* state);
-int lua_Form_createAnimationFromBy(lua_State* state);
-int lua_Form_createAnimationFromTo(lua_State* state);
-int lua_Form_destroyAnimation(lua_State* state);
-int lua_Form_draw(lua_State* state);
-int lua_Form_getAbsoluteBounds(lua_State* state);
-int lua_Form_getActiveControl(lua_State* state);
-int lua_Form_getAlignment(lua_State* state);
-int lua_Form_getAnimation(lua_State* state);
-int lua_Form_getAnimationPropertyComponentCount(lua_State* state);
-int lua_Form_getAnimationPropertyValue(lua_State* state);
-int lua_Form_getAutoSize(lua_State* state);
-int lua_Form_getBorder(lua_State* state);
-int lua_Form_getBounds(lua_State* state);
-int lua_Form_getClip(lua_State* state);
-int lua_Form_getClipBounds(lua_State* state);
-int lua_Form_getConsumeInputEvents(lua_State* state);
-int lua_Form_getControl(lua_State* state);
-int lua_Form_getControlCount(lua_State* state);
-int lua_Form_getCursorColor(lua_State* state);
-int lua_Form_getCursorRegion(lua_State* state);
-int lua_Form_getCursorUVs(lua_State* state);
-int lua_Form_getFocusIndex(lua_State* state);
-int lua_Form_getFont(lua_State* state);
-int lua_Form_getFontSize(lua_State* state);
-int lua_Form_getHeight(lua_State* state);
-int lua_Form_getId(lua_State* state);
-int lua_Form_getImageColor(lua_State* state);
-int lua_Form_getImageRegion(lua_State* state);
-int lua_Form_getImageUVs(lua_State* state);
-int lua_Form_getLayout(lua_State* state);
-int lua_Form_getMargin(lua_State* state);
-int lua_Form_getNode(lua_State* state);
-int lua_Form_getOpacity(lua_State* state);
-int lua_Form_getPadding(lua_State* state);
-int lua_Form_getParent(lua_State* state);
-int lua_Form_getRefCount(lua_State* state);
-int lua_Form_getScriptEvent(lua_State* state);
-int lua_Form_getScroll(lua_State* state);
-int lua_Form_getScrollPosition(lua_State* state);
-int lua_Form_getScrollWheelRequiresFocus(lua_State* state);
-int lua_Form_getScrollWheelSpeed(lua_State* state);
-int lua_Form_getScrollingFriction(lua_State* state);
-int lua_Form_getSkinColor(lua_State* state);
-int lua_Form_getSkinRegion(lua_State* state);
-int lua_Form_getState(lua_State* state);
-int lua_Form_getStyle(lua_State* state);
-int lua_Form_getTextAlignment(lua_State* state);
-int lua_Form_getTextColor(lua_State* state);
-int lua_Form_getTextRightToLeft(lua_State* state);
-int lua_Form_getTheme(lua_State* state);
-int lua_Form_getTopLevelForm(lua_State* state);
-int lua_Form_getTypeName(lua_State* state);
-int lua_Form_getWidth(lua_State* state);
-int lua_Form_getX(lua_State* state);
-int lua_Form_getY(lua_State* state);
-int lua_Form_getZIndex(lua_State* state);
-int lua_Form_hasFocus(lua_State* state);
-int lua_Form_hasScriptListener(lua_State* state);
-int lua_Form_insertControl(lua_State* state);
-int lua_Form_isBatchingEnabled(lua_State* state);
-int lua_Form_isChild(lua_State* state);
-int lua_Form_isContainer(lua_State* state);
-int lua_Form_isEnabled(lua_State* state);
-int lua_Form_isEnabledInHierarchy(lua_State* state);
-int lua_Form_isForm(lua_State* state);
-int lua_Form_isHeightPercentage(lua_State* state);
-int lua_Form_isScrollBarsAutoHide(lua_State* state);
-int lua_Form_isScrolling(lua_State* state);
-int lua_Form_isVisible(lua_State* state);
-int lua_Form_isVisibleInHierarchy(lua_State* state);
-int lua_Form_isWidthPercentage(lua_State* state);
-int lua_Form_isXPercentage(lua_State* state);
-int lua_Form_isYPercentage(lua_State* state);
-int lua_Form_moveFocus(lua_State* state);
-int lua_Form_release(lua_State* state);
-int lua_Form_removeControl(lua_State* state);
-int lua_Form_removeListener(lua_State* state);
-int lua_Form_removeScript(lua_State* state);
-int lua_Form_removeScriptCallback(lua_State* state);
-int lua_Form_setActiveControl(lua_State* state);
-int lua_Form_setAlignment(lua_State* state);
-int lua_Form_setAnimationPropertyValue(lua_State* state);
-int lua_Form_setAutoSize(lua_State* state);
-int lua_Form_setBatchingEnabled(lua_State* state);
-int lua_Form_setBorder(lua_State* state);
-int lua_Form_setBounds(lua_State* state);
-int lua_Form_setCanFocus(lua_State* state);
-int lua_Form_setConsumeInputEvents(lua_State* state);
-int lua_Form_setCursorColor(lua_State* state);
-int lua_Form_setCursorRegion(lua_State* state);
-int lua_Form_setEnabled(lua_State* state);
-int lua_Form_setFocus(lua_State* state);
-int lua_Form_setFocusIndex(lua_State* state);
-int lua_Form_setFont(lua_State* state);
-int lua_Form_setFontSize(lua_State* state);
-int lua_Form_setHeight(lua_State* state);
-int lua_Form_setId(lua_State* state);
-int lua_Form_setImageColor(lua_State* state);
-int lua_Form_setImageRegion(lua_State* state);
-int lua_Form_setLayout(lua_State* state);
-int lua_Form_setMargin(lua_State* state);
-int lua_Form_setOpacity(lua_State* state);
-int lua_Form_setPadding(lua_State* state);
-int lua_Form_setPosition(lua_State* state);
-int lua_Form_setScroll(lua_State* state);
-int lua_Form_setScrollBarsAutoHide(lua_State* state);
-int lua_Form_setScrollPosition(lua_State* state);
-int lua_Form_setScrollWheelRequiresFocus(lua_State* state);
-int lua_Form_setScrollWheelSpeed(lua_State* state);
-int lua_Form_setScrollingFriction(lua_State* state);
-int lua_Form_setSize(lua_State* state);
-int lua_Form_setSkinColor(lua_State* state);
-int lua_Form_setSkinRegion(lua_State* state);
-int lua_Form_setStyle(lua_State* state);
-int lua_Form_setTextAlignment(lua_State* state);
-int lua_Form_setTextColor(lua_State* state);
-int lua_Form_setTextRightToLeft(lua_State* state);
-int lua_Form_setVisible(lua_State* state);
-int lua_Form_setWidth(lua_State* state);
-int lua_Form_setX(lua_State* state);
-int lua_Form_setY(lua_State* state);
-int lua_Form_setZIndex(lua_State* state);
-int lua_Form_static_ANIMATE_OPACITY(lua_State* state);
-int lua_Form_static_ANIMATE_POSITION(lua_State* state);
-int lua_Form_static_ANIMATE_POSITION_X(lua_State* state);
-int lua_Form_static_ANIMATE_POSITION_Y(lua_State* state);
-int lua_Form_static_ANIMATE_SCROLLBAR_OPACITY(lua_State* state);
-int lua_Form_static_ANIMATE_SIZE(lua_State* state);
-int lua_Form_static_ANIMATE_SIZE_HEIGHT(lua_State* state);
-int lua_Form_static_ANIMATE_SIZE_WIDTH(lua_State* state);
-int lua_Form_static_clearFocus(lua_State* state);
-int lua_Form_static_create(lua_State* state);
-int lua_Form_static_getActiveControl(lua_State* state);
-int lua_Form_static_getFocusControl(lua_State* state);
-int lua_Form_static_getForm(lua_State* state);
-int lua_Form_stopScrolling(lua_State* state);
-int lua_Form_update(lua_State* state);
-
 void luaRegister_Form();
 
 }

+ 211 - 58
gameplay/src/lua/lua_FrameBuffer.cpp

@@ -6,44 +6,12 @@
 #include "FrameBuffer.h"
 #include "Game.h"
 #include "Ref.h"
+#include "Ref.h"
 
 namespace gameplay
 {
 
-void luaRegister_FrameBuffer()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_FrameBuffer_addRef},
-        {"bind", lua_FrameBuffer_bind},
-        {"getDepthStencilTarget", lua_FrameBuffer_getDepthStencilTarget},
-        {"getHeight", lua_FrameBuffer_getHeight},
-        {"getId", lua_FrameBuffer_getId},
-        {"getRefCount", lua_FrameBuffer_getRefCount},
-        {"getRenderTarget", lua_FrameBuffer_getRenderTarget},
-        {"getRenderTargetCount", lua_FrameBuffer_getRenderTargetCount},
-        {"getWidth", lua_FrameBuffer_getWidth},
-        {"isDefault", lua_FrameBuffer_isDefault},
-        {"release", lua_FrameBuffer_release},
-        {"setDepthStencilTarget", lua_FrameBuffer_setDepthStencilTarget},
-        {"setRenderTarget", lua_FrameBuffer_setRenderTarget},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"bindDefault", lua_FrameBuffer_static_bindDefault},
-        {"create", lua_FrameBuffer_static_create},
-        {"createScreenshot", lua_FrameBuffer_static_createScreenshot},
-        {"getCurrent", lua_FrameBuffer_static_getCurrent},
-        {"getFrameBuffer", lua_FrameBuffer_static_getFrameBuffer},
-        {"getMaxRenderTargets", lua_FrameBuffer_static_getMaxRenderTargets},
-        {"getScreenshot", lua_FrameBuffer_static_getScreenshot},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("FrameBuffer", lua_members, NULL, lua_FrameBuffer__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static FrameBuffer* getInstance(lua_State* state)
 {
@@ -52,7 +20,7 @@ static FrameBuffer* getInstance(lua_State* state)
     return (FrameBuffer*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_FrameBuffer__gc(lua_State* state)
+static int lua_FrameBuffer__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -90,7 +58,7 @@ int lua_FrameBuffer__gc(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_addRef(lua_State* state)
+static int lua_FrameBuffer_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -122,7 +90,7 @@ int lua_FrameBuffer_addRef(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_bind(lua_State* state)
+static int lua_FrameBuffer_bind(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -156,9 +124,40 @@ int lua_FrameBuffer_bind(lua_State* state)
             lua_error(state);
             break;
         }
+        case 2:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
+                lua_type(state, 2) == LUA_TNONE)
+            {
+                // Get parameter 1 off the stack.
+                GP_WARN("Attempting to get parameter 1 with unrecognized type GLenum as an unsigned integer.");
+                GLenum param1 = (GLenum)luaL_checkunsigned(state, 2);
+
+                FrameBuffer* instance = getInstance(state);
+                void* returnPtr = ((void*)instance->bind(param1));
+                if (returnPtr)
+                {
+                    gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "FrameBuffer");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
+            }
+
+            lua_pushstring(state, "lua_FrameBuffer_bind - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
         default:
         {
-            lua_pushstring(state, "Invalid number of parameters (expected 1).");
+            lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
             lua_error(state);
             break;
         }
@@ -166,7 +165,7 @@ int lua_FrameBuffer_bind(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_getDepthStencilTarget(lua_State* state)
+static int lua_FrameBuffer_getDepthStencilTarget(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -210,7 +209,7 @@ int lua_FrameBuffer_getDepthStencilTarget(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_getHeight(lua_State* state)
+static int lua_FrameBuffer_getHeight(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -245,7 +244,7 @@ int lua_FrameBuffer_getHeight(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_getId(lua_State* state)
+static int lua_FrameBuffer_getId(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -280,7 +279,7 @@ int lua_FrameBuffer_getId(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_getRefCount(lua_State* state)
+static int lua_FrameBuffer_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -315,7 +314,7 @@ int lua_FrameBuffer_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_getRenderTarget(lua_State* state)
+static int lua_FrameBuffer_getRenderTarget(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -389,7 +388,7 @@ int lua_FrameBuffer_getRenderTarget(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_getRenderTargetCount(lua_State* state)
+static int lua_FrameBuffer_getRenderTargetCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -424,7 +423,7 @@ int lua_FrameBuffer_getRenderTargetCount(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_getWidth(lua_State* state)
+static int lua_FrameBuffer_getWidth(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -459,7 +458,7 @@ int lua_FrameBuffer_getWidth(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_isDefault(lua_State* state)
+static int lua_FrameBuffer_isDefault(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -494,7 +493,7 @@ int lua_FrameBuffer_isDefault(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_release(lua_State* state)
+static int lua_FrameBuffer_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -526,7 +525,7 @@ int lua_FrameBuffer_release(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_setDepthStencilTarget(lua_State* state)
+static int lua_FrameBuffer_setDepthStencilTarget(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -568,7 +567,7 @@ int lua_FrameBuffer_setDepthStencilTarget(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_setRenderTarget(lua_State* state)
+static int lua_FrameBuffer_setRenderTarget(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -692,7 +691,7 @@ int lua_FrameBuffer_setRenderTarget(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_static_bindDefault(lua_State* state)
+static int lua_FrameBuffer_static_bindDefault(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -719,9 +718,38 @@ int lua_FrameBuffer_static_bindDefault(lua_State* state)
             return 1;
             break;
         }
+        case 1:
+        {
+            if (lua_type(state, 1) == LUA_TNONE)
+            {
+                // Get parameter 1 off the stack.
+                GP_WARN("Attempting to get parameter 1 with unrecognized type GLenum as an unsigned integer.");
+                GLenum param1 = (GLenum)luaL_checkunsigned(state, 1);
+
+                void* returnPtr = ((void*)FrameBuffer::bindDefault(param1));
+                if (returnPtr)
+                {
+                    gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "FrameBuffer");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
+            }
+
+            lua_pushstring(state, "lua_FrameBuffer_static_bindDefault - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
         default:
         {
-            lua_pushstring(state, "Invalid number of parameters (expected 0).");
+            lua_pushstring(state, "Invalid number of parameters (expected 0 or 1).");
             lua_error(state);
             break;
         }
@@ -729,7 +757,7 @@ int lua_FrameBuffer_static_bindDefault(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_static_create(lua_State* state)
+static int lua_FrameBuffer_static_create(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -807,9 +835,52 @@ int lua_FrameBuffer_static_create(lua_State* state)
             lua_error(state);
             break;
         }
+        case 4:
+        {
+            do
+            {
+                if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
+                    lua_type(state, 2) == LUA_TNUMBER &&
+                    lua_type(state, 3) == LUA_TNUMBER &&
+                    lua_type(state, 4) == LUA_TNUMBER)
+                {
+                    // Get parameter 1 off the stack.
+                    const char* param1 = gameplay::ScriptUtil::getString(1, false);
+
+                    // Get parameter 2 off the stack.
+                    unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
+
+                    // Get parameter 3 off the stack.
+                    unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 3);
+
+                    // Get parameter 4 off the stack.
+                    Texture::Format param4 = (Texture::Format)luaL_checkint(state, 4);
+
+                    void* returnPtr = ((void*)FrameBuffer::create(param1, param2, param3, param4));
+                    if (returnPtr)
+                    {
+                        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+                        object->instance = returnPtr;
+                        object->owns = true;
+                        luaL_getmetatable(state, "FrameBuffer");
+                        lua_setmetatable(state, -2);
+                    }
+                    else
+                    {
+                        lua_pushnil(state);
+                    }
+
+                    return 1;
+                }
+            } while (0);
+
+            lua_pushstring(state, "lua_FrameBuffer_static_create - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
         default:
         {
-            lua_pushstring(state, "Invalid number of parameters (expected 1 or 3).");
+            lua_pushstring(state, "Invalid number of parameters (expected 1, 3 or 4).");
             lua_error(state);
             break;
         }
@@ -817,7 +888,7 @@ int lua_FrameBuffer_static_create(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_static_createScreenshot(lua_State* state)
+static int lua_FrameBuffer_static_createScreenshot(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -882,7 +953,7 @@ int lua_FrameBuffer_static_createScreenshot(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_static_getCurrent(lua_State* state)
+static int lua_FrameBuffer_static_getCurrent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -919,7 +990,7 @@ int lua_FrameBuffer_static_getCurrent(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_static_getFrameBuffer(lua_State* state)
+static int lua_FrameBuffer_static_getFrameBuffer(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -965,7 +1036,7 @@ int lua_FrameBuffer_static_getFrameBuffer(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_static_getMaxRenderTargets(lua_State* state)
+static int lua_FrameBuffer_static_getMaxRenderTargets(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -993,7 +1064,7 @@ int lua_FrameBuffer_static_getMaxRenderTargets(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_static_getScreenshot(lua_State* state)
+static int lua_FrameBuffer_static_getScreenshot(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1033,4 +1104,86 @@ int lua_FrameBuffer_static_getScreenshot(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of FrameBuffer
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    FrameBuffer* ptrObject = reinterpret_cast<FrameBuffer*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_FrameBuffer_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_FrameBuffer_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    FrameBuffer* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_FrameBuffer()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_FrameBuffer_addRef},
+        {"bind", lua_FrameBuffer_bind},
+        {"getDepthStencilTarget", lua_FrameBuffer_getDepthStencilTarget},
+        {"getHeight", lua_FrameBuffer_getHeight},
+        {"getId", lua_FrameBuffer_getId},
+        {"getRefCount", lua_FrameBuffer_getRefCount},
+        {"getRenderTarget", lua_FrameBuffer_getRenderTarget},
+        {"getRenderTargetCount", lua_FrameBuffer_getRenderTargetCount},
+        {"getWidth", lua_FrameBuffer_getWidth},
+        {"isDefault", lua_FrameBuffer_isDefault},
+        {"release", lua_FrameBuffer_release},
+        {"setDepthStencilTarget", lua_FrameBuffer_setDepthStencilTarget},
+        {"setRenderTarget", lua_FrameBuffer_setRenderTarget},
+        {"to", lua_FrameBuffer_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"bindDefault", lua_FrameBuffer_static_bindDefault},
+        {"create", lua_FrameBuffer_static_create},
+        {"createScreenshot", lua_FrameBuffer_static_createScreenshot},
+        {"getCurrent", lua_FrameBuffer_static_getCurrent},
+        {"getFrameBuffer", lua_FrameBuffer_static_getFrameBuffer},
+        {"getMaxRenderTargets", lua_FrameBuffer_static_getMaxRenderTargets},
+        {"getScreenshot", lua_FrameBuffer_static_getScreenshot},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("FrameBuffer", lua_members, NULL, lua_FrameBuffer__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("FrameBuffer", __convertTo);
+}
+
 }

+ 0 - 23
gameplay/src/lua/lua_FrameBuffer.h

@@ -5,29 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for FrameBuffer.
-int lua_FrameBuffer__gc(lua_State* state);
-int lua_FrameBuffer_addRef(lua_State* state);
-int lua_FrameBuffer_bind(lua_State* state);
-int lua_FrameBuffer_getDepthStencilTarget(lua_State* state);
-int lua_FrameBuffer_getHeight(lua_State* state);
-int lua_FrameBuffer_getId(lua_State* state);
-int lua_FrameBuffer_getRefCount(lua_State* state);
-int lua_FrameBuffer_getRenderTarget(lua_State* state);
-int lua_FrameBuffer_getRenderTargetCount(lua_State* state);
-int lua_FrameBuffer_getWidth(lua_State* state);
-int lua_FrameBuffer_isDefault(lua_State* state);
-int lua_FrameBuffer_release(lua_State* state);
-int lua_FrameBuffer_setDepthStencilTarget(lua_State* state);
-int lua_FrameBuffer_setRenderTarget(lua_State* state);
-int lua_FrameBuffer_static_bindDefault(lua_State* state);
-int lua_FrameBuffer_static_create(lua_State* state);
-int lua_FrameBuffer_static_createScreenshot(lua_State* state);
-int lua_FrameBuffer_static_getCurrent(lua_State* state);
-int lua_FrameBuffer_static_getFrameBuffer(lua_State* state);
-int lua_FrameBuffer_static_getMaxRenderTargets(lua_State* state);
-int lua_FrameBuffer_static_getScreenshot(lua_State* state);
-
 void luaRegister_FrameBuffer();
 
 }

+ 39 - 38
gameplay/src/lua/lua_Frustum.cpp

@@ -10,30 +10,6 @@
 namespace gameplay
 {
 
-void luaRegister_Frustum()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"getBottom", lua_Frustum_getBottom},
-        {"getCorners", lua_Frustum_getCorners},
-        {"getFar", lua_Frustum_getFar},
-        {"getFarCorners", lua_Frustum_getFarCorners},
-        {"getLeft", lua_Frustum_getLeft},
-        {"getMatrix", lua_Frustum_getMatrix},
-        {"getNear", lua_Frustum_getNear},
-        {"getNearCorners", lua_Frustum_getNearCorners},
-        {"getRight", lua_Frustum_getRight},
-        {"getTop", lua_Frustum_getTop},
-        {"intersects", lua_Frustum_intersects},
-        {"set", lua_Frustum_set},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("Frustum", lua_members, lua_Frustum__init, lua_Frustum__gc, lua_statics, scopePath);
-}
-
 static Frustum* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "Frustum");
@@ -41,7 +17,7 @@ static Frustum* getInstance(lua_State* state)
     return (Frustum*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_Frustum__gc(lua_State* state)
+static int lua_Frustum__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -79,7 +55,7 @@ int lua_Frustum__gc(lua_State* state)
     return 0;
 }
 
-int lua_Frustum__init(lua_State* state)
+static int lua_Frustum__init(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -178,7 +154,7 @@ int lua_Frustum__init(lua_State* state)
     return 0;
 }
 
-int lua_Frustum_getBottom(lua_State* state)
+static int lua_Frustum_getBottom(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -222,7 +198,7 @@ int lua_Frustum_getBottom(lua_State* state)
     return 0;
 }
 
-int lua_Frustum_getCorners(lua_State* state)
+static int lua_Frustum_getCorners(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -264,7 +240,7 @@ int lua_Frustum_getCorners(lua_State* state)
     return 0;
 }
 
-int lua_Frustum_getFar(lua_State* state)
+static int lua_Frustum_getFar(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -308,7 +284,7 @@ int lua_Frustum_getFar(lua_State* state)
     return 0;
 }
 
-int lua_Frustum_getFarCorners(lua_State* state)
+static int lua_Frustum_getFarCorners(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -350,7 +326,7 @@ int lua_Frustum_getFarCorners(lua_State* state)
     return 0;
 }
 
-int lua_Frustum_getLeft(lua_State* state)
+static int lua_Frustum_getLeft(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -394,7 +370,7 @@ int lua_Frustum_getLeft(lua_State* state)
     return 0;
 }
 
-int lua_Frustum_getMatrix(lua_State* state)
+static int lua_Frustum_getMatrix(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -436,7 +412,7 @@ int lua_Frustum_getMatrix(lua_State* state)
     return 0;
 }
 
-int lua_Frustum_getNear(lua_State* state)
+static int lua_Frustum_getNear(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -480,7 +456,7 @@ int lua_Frustum_getNear(lua_State* state)
     return 0;
 }
 
-int lua_Frustum_getNearCorners(lua_State* state)
+static int lua_Frustum_getNearCorners(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -522,7 +498,7 @@ int lua_Frustum_getNearCorners(lua_State* state)
     return 0;
 }
 
-int lua_Frustum_getRight(lua_State* state)
+static int lua_Frustum_getRight(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -566,7 +542,7 @@ int lua_Frustum_getRight(lua_State* state)
     return 0;
 }
 
-int lua_Frustum_getTop(lua_State* state)
+static int lua_Frustum_getTop(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -610,7 +586,7 @@ int lua_Frustum_getTop(lua_State* state)
     return 0;
 }
 
-int lua_Frustum_intersects(lua_State* state)
+static int lua_Frustum_intersects(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -771,7 +747,7 @@ int lua_Frustum_intersects(lua_State* state)
     return 0;
 }
 
-int lua_Frustum_set(lua_State* state)
+static int lua_Frustum_set(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -831,4 +807,29 @@ int lua_Frustum_set(lua_State* state)
     return 0;
 }
 
+void luaRegister_Frustum()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"getBottom", lua_Frustum_getBottom},
+        {"getCorners", lua_Frustum_getCorners},
+        {"getFar", lua_Frustum_getFar},
+        {"getFarCorners", lua_Frustum_getFarCorners},
+        {"getLeft", lua_Frustum_getLeft},
+        {"getMatrix", lua_Frustum_getMatrix},
+        {"getNear", lua_Frustum_getNear},
+        {"getNearCorners", lua_Frustum_getNearCorners},
+        {"getRight", lua_Frustum_getRight},
+        {"getTop", lua_Frustum_getTop},
+        {"intersects", lua_Frustum_intersects},
+        {"set", lua_Frustum_set},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("Frustum", lua_members, lua_Frustum__init, lua_Frustum__gc, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 16
gameplay/src/lua/lua_Frustum.h

@@ -5,22 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Frustum.
-int lua_Frustum__gc(lua_State* state);
-int lua_Frustum__init(lua_State* state);
-int lua_Frustum_getBottom(lua_State* state);
-int lua_Frustum_getCorners(lua_State* state);
-int lua_Frustum_getFar(lua_State* state);
-int lua_Frustum_getFarCorners(lua_State* state);
-int lua_Frustum_getLeft(lua_State* state);
-int lua_Frustum_getMatrix(lua_State* state);
-int lua_Frustum_getNear(lua_State* state);
-int lua_Frustum_getNearCorners(lua_State* state);
-int lua_Frustum_getRight(lua_State* state);
-int lua_Frustum_getTop(lua_State* state);
-int lua_Frustum_intersects(lua_State* state);
-int lua_Frustum_set(lua_State* state);
-
 void luaRegister_Frustum();
 
 }

+ 138 - 137
gameplay/src/lua/lua_Game.cpp

@@ -16,81 +16,6 @@
 namespace gameplay
 {
 
-void luaRegister_Game()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"canExit", lua_Game_canExit},
-        {"clear", lua_Game_clear},
-        {"clearSchedule", lua_Game_clearSchedule},
-        {"displayKeyboard", lua_Game_displayKeyboard},
-        {"exit", lua_Game_exit},
-        {"frame", lua_Game_frame},
-        {"gamepadEvent", lua_Game_gamepadEvent},
-        {"gestureDragEvent", lua_Game_gestureDragEvent},
-        {"gestureDropEvent", lua_Game_gestureDropEvent},
-        {"gestureLongTapEvent", lua_Game_gestureLongTapEvent},
-        {"gesturePinchEvent", lua_Game_gesturePinchEvent},
-        {"gestureSwipeEvent", lua_Game_gestureSwipeEvent},
-        {"gestureTapEvent", lua_Game_gestureTapEvent},
-        {"getAIController", lua_Game_getAIController},
-        {"getAccelerometerValues", lua_Game_getAccelerometerValues},
-        {"getAnimationController", lua_Game_getAnimationController},
-        {"getAspectRatio", lua_Game_getAspectRatio},
-        {"getAudioController", lua_Game_getAudioController},
-        {"getAudioListener", lua_Game_getAudioListener},
-        {"getConfig", lua_Game_getConfig},
-        {"getFrameRate", lua_Game_getFrameRate},
-        {"getGamepad", lua_Game_getGamepad},
-        {"getGamepadCount", lua_Game_getGamepadCount},
-        {"getHeight", lua_Game_getHeight},
-        {"getPhysicsController", lua_Game_getPhysicsController},
-        {"getScriptController", lua_Game_getScriptController},
-        {"getSensorValues", lua_Game_getSensorValues},
-        {"getState", lua_Game_getState},
-        {"getViewport", lua_Game_getViewport},
-        {"getWidth", lua_Game_getWidth},
-        {"hasAccelerometer", lua_Game_hasAccelerometer},
-        {"hasMouse", lua_Game_hasMouse},
-        {"isCursorVisible", lua_Game_isCursorVisible},
-        {"isGestureRegistered", lua_Game_isGestureRegistered},
-        {"isGestureSupported", lua_Game_isGestureSupported},
-        {"isInitialized", lua_Game_isInitialized},
-        {"isMouseCaptured", lua_Game_isMouseCaptured},
-        {"isMultiSampling", lua_Game_isMultiSampling},
-        {"isMultiTouch", lua_Game_isMultiTouch},
-        {"keyEvent", lua_Game_keyEvent},
-        {"launchURL", lua_Game_launchURL},
-        {"mouseEvent", lua_Game_mouseEvent},
-        {"pause", lua_Game_pause},
-        {"registerGesture", lua_Game_registerGesture},
-        {"resizeEvent", lua_Game_resizeEvent},
-        {"resume", lua_Game_resume},
-        {"run", lua_Game_run},
-        {"schedule", lua_Game_schedule},
-        {"setCursorVisible", lua_Game_setCursorVisible},
-        {"setMouseCaptured", lua_Game_setMouseCaptured},
-        {"setMultiSampling", lua_Game_setMultiSampling},
-        {"setMultiTouch", lua_Game_setMultiTouch},
-        {"setViewport", lua_Game_setViewport},
-        {"touchEvent", lua_Game_touchEvent},
-        {"unregisterGesture", lua_Game_unregisterGesture},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"getAbsoluteTime", lua_Game_static_getAbsoluteTime},
-        {"getGameTime", lua_Game_static_getGameTime},
-        {"getInstance", lua_Game_static_getInstance},
-        {"isVsync", lua_Game_static_isVsync},
-        {"setVsync", lua_Game_static_setVsync},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("Game", lua_members, lua_Game__init, lua_Game__gc, lua_statics, scopePath);
-}
-
 static Game* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "Game");
@@ -98,7 +23,7 @@ static Game* getInstance(lua_State* state)
     return (Game*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_Game__gc(lua_State* state)
+static int lua_Game__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -136,7 +61,7 @@ int lua_Game__gc(lua_State* state)
     return 0;
 }
 
-int lua_Game__init(lua_State* state)
+static int lua_Game__init(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -173,7 +98,7 @@ int lua_Game__init(lua_State* state)
     return 0;
 }
 
-int lua_Game_canExit(lua_State* state)
+static int lua_Game_canExit(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -208,7 +133,7 @@ int lua_Game_canExit(lua_State* state)
     return 0;
 }
 
-int lua_Game_clear(lua_State* state)
+static int lua_Game_clear(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -307,7 +232,7 @@ int lua_Game_clear(lua_State* state)
     return 0;
 }
 
-int lua_Game_clearSchedule(lua_State* state)
+static int lua_Game_clearSchedule(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -339,7 +264,7 @@ int lua_Game_clearSchedule(lua_State* state)
     return 0;
 }
 
-int lua_Game_displayKeyboard(lua_State* state)
+static int lua_Game_displayKeyboard(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -375,7 +300,7 @@ int lua_Game_displayKeyboard(lua_State* state)
     return 0;
 }
 
-int lua_Game_exit(lua_State* state)
+static int lua_Game_exit(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -407,7 +332,7 @@ int lua_Game_exit(lua_State* state)
     return 0;
 }
 
-int lua_Game_frame(lua_State* state)
+static int lua_Game_frame(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -439,7 +364,7 @@ int lua_Game_frame(lua_State* state)
     return 0;
 }
 
-int lua_Game_gamepadEvent(lua_State* state)
+static int lua_Game_gamepadEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -485,7 +410,7 @@ int lua_Game_gamepadEvent(lua_State* state)
     return 0;
 }
 
-int lua_Game_gestureDragEvent(lua_State* state)
+static int lua_Game_gestureDragEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -525,7 +450,7 @@ int lua_Game_gestureDragEvent(lua_State* state)
     return 0;
 }
 
-int lua_Game_gestureDropEvent(lua_State* state)
+static int lua_Game_gestureDropEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -565,7 +490,7 @@ int lua_Game_gestureDropEvent(lua_State* state)
     return 0;
 }
 
-int lua_Game_gestureLongTapEvent(lua_State* state)
+static int lua_Game_gestureLongTapEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -609,7 +534,7 @@ int lua_Game_gestureLongTapEvent(lua_State* state)
     return 0;
 }
 
-int lua_Game_gesturePinchEvent(lua_State* state)
+static int lua_Game_gesturePinchEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -653,7 +578,7 @@ int lua_Game_gesturePinchEvent(lua_State* state)
     return 0;
 }
 
-int lua_Game_gestureSwipeEvent(lua_State* state)
+static int lua_Game_gestureSwipeEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -697,7 +622,7 @@ int lua_Game_gestureSwipeEvent(lua_State* state)
     return 0;
 }
 
-int lua_Game_gestureTapEvent(lua_State* state)
+static int lua_Game_gestureTapEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -737,7 +662,7 @@ int lua_Game_gestureTapEvent(lua_State* state)
     return 0;
 }
 
-int lua_Game_getAIController(lua_State* state)
+static int lua_Game_getAIController(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -781,7 +706,7 @@ int lua_Game_getAIController(lua_State* state)
     return 0;
 }
 
-int lua_Game_getAccelerometerValues(lua_State* state)
+static int lua_Game_getAccelerometerValues(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -821,7 +746,7 @@ int lua_Game_getAccelerometerValues(lua_State* state)
     return 0;
 }
 
-int lua_Game_getAnimationController(lua_State* state)
+static int lua_Game_getAnimationController(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -865,7 +790,7 @@ int lua_Game_getAnimationController(lua_State* state)
     return 0;
 }
 
-int lua_Game_getAspectRatio(lua_State* state)
+static int lua_Game_getAspectRatio(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -900,7 +825,7 @@ int lua_Game_getAspectRatio(lua_State* state)
     return 0;
 }
 
-int lua_Game_getAudioController(lua_State* state)
+static int lua_Game_getAudioController(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -944,7 +869,7 @@ int lua_Game_getAudioController(lua_State* state)
     return 0;
 }
 
-int lua_Game_getAudioListener(lua_State* state)
+static int lua_Game_getAudioListener(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -988,7 +913,7 @@ int lua_Game_getAudioListener(lua_State* state)
     return 0;
 }
 
-int lua_Game_getConfig(lua_State* state)
+static int lua_Game_getConfig(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1032,7 +957,7 @@ int lua_Game_getConfig(lua_State* state)
     return 0;
 }
 
-int lua_Game_getFrameRate(lua_State* state)
+static int lua_Game_getFrameRate(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1067,7 +992,7 @@ int lua_Game_getFrameRate(lua_State* state)
     return 0;
 }
 
-int lua_Game_getGamepad(lua_State* state)
+static int lua_Game_getGamepad(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1149,7 +1074,7 @@ int lua_Game_getGamepad(lua_State* state)
     return 0;
 }
 
-int lua_Game_getGamepadCount(lua_State* state)
+static int lua_Game_getGamepadCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1184,7 +1109,7 @@ int lua_Game_getGamepadCount(lua_State* state)
     return 0;
 }
 
-int lua_Game_getHeight(lua_State* state)
+static int lua_Game_getHeight(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1219,7 +1144,7 @@ int lua_Game_getHeight(lua_State* state)
     return 0;
 }
 
-int lua_Game_getPhysicsController(lua_State* state)
+static int lua_Game_getPhysicsController(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1263,7 +1188,7 @@ int lua_Game_getPhysicsController(lua_State* state)
     return 0;
 }
 
-int lua_Game_getScriptController(lua_State* state)
+static int lua_Game_getScriptController(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1307,7 +1232,7 @@ int lua_Game_getScriptController(lua_State* state)
     return 0;
 }
 
-int lua_Game_getSensorValues(lua_State* state)
+static int lua_Game_getSensorValues(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1363,7 +1288,7 @@ int lua_Game_getSensorValues(lua_State* state)
     return 0;
 }
 
-int lua_Game_getState(lua_State* state)
+static int lua_Game_getState(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1398,7 +1323,7 @@ int lua_Game_getState(lua_State* state)
     return 0;
 }
 
-int lua_Game_getViewport(lua_State* state)
+static int lua_Game_getViewport(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1442,7 +1367,7 @@ int lua_Game_getViewport(lua_State* state)
     return 0;
 }
 
-int lua_Game_getWidth(lua_State* state)
+static int lua_Game_getWidth(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1477,7 +1402,7 @@ int lua_Game_getWidth(lua_State* state)
     return 0;
 }
 
-int lua_Game_hasAccelerometer(lua_State* state)
+static int lua_Game_hasAccelerometer(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1512,7 +1437,7 @@ int lua_Game_hasAccelerometer(lua_State* state)
     return 0;
 }
 
-int lua_Game_hasMouse(lua_State* state)
+static int lua_Game_hasMouse(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1547,7 +1472,7 @@ int lua_Game_hasMouse(lua_State* state)
     return 0;
 }
 
-int lua_Game_isCursorVisible(lua_State* state)
+static int lua_Game_isCursorVisible(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1582,7 +1507,7 @@ int lua_Game_isCursorVisible(lua_State* state)
     return 0;
 }
 
-int lua_Game_isGestureRegistered(lua_State* state)
+static int lua_Game_isGestureRegistered(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1621,7 +1546,7 @@ int lua_Game_isGestureRegistered(lua_State* state)
     return 0;
 }
 
-int lua_Game_isGestureSupported(lua_State* state)
+static int lua_Game_isGestureSupported(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1660,7 +1585,7 @@ int lua_Game_isGestureSupported(lua_State* state)
     return 0;
 }
 
-int lua_Game_isInitialized(lua_State* state)
+static int lua_Game_isInitialized(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1695,7 +1620,7 @@ int lua_Game_isInitialized(lua_State* state)
     return 0;
 }
 
-int lua_Game_isMouseCaptured(lua_State* state)
+static int lua_Game_isMouseCaptured(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1730,7 +1655,7 @@ int lua_Game_isMouseCaptured(lua_State* state)
     return 0;
 }
 
-int lua_Game_isMultiSampling(lua_State* state)
+static int lua_Game_isMultiSampling(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1765,7 +1690,7 @@ int lua_Game_isMultiSampling(lua_State* state)
     return 0;
 }
 
-int lua_Game_isMultiTouch(lua_State* state)
+static int lua_Game_isMultiTouch(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1800,7 +1725,7 @@ int lua_Game_isMultiTouch(lua_State* state)
     return 0;
 }
 
-int lua_Game_keyEvent(lua_State* state)
+static int lua_Game_keyEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1840,7 +1765,7 @@ int lua_Game_keyEvent(lua_State* state)
     return 0;
 }
 
-int lua_Game_launchURL(lua_State* state)
+static int lua_Game_launchURL(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1879,7 +1804,7 @@ int lua_Game_launchURL(lua_State* state)
     return 0;
 }
 
-int lua_Game_mouseEvent(lua_State* state)
+static int lua_Game_mouseEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1930,7 +1855,7 @@ int lua_Game_mouseEvent(lua_State* state)
     return 0;
 }
 
-int lua_Game_pause(lua_State* state)
+static int lua_Game_pause(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1962,7 +1887,7 @@ int lua_Game_pause(lua_State* state)
     return 0;
 }
 
-int lua_Game_registerGesture(lua_State* state)
+static int lua_Game_registerGesture(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -1998,7 +1923,7 @@ int lua_Game_registerGesture(lua_State* state)
     return 0;
 }
 
-int lua_Game_resizeEvent(lua_State* state)
+static int lua_Game_resizeEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2038,7 +1963,7 @@ int lua_Game_resizeEvent(lua_State* state)
     return 0;
 }
 
-int lua_Game_resume(lua_State* state)
+static int lua_Game_resume(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2070,7 +1995,7 @@ int lua_Game_resume(lua_State* state)
     return 0;
 }
 
-int lua_Game_run(lua_State* state)
+static int lua_Game_run(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2105,7 +2030,7 @@ int lua_Game_run(lua_State* state)
     return 0;
 }
 
-int lua_Game_schedule(lua_State* state)
+static int lua_Game_schedule(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2145,7 +2070,7 @@ int lua_Game_schedule(lua_State* state)
     return 0;
 }
 
-int lua_Game_setCursorVisible(lua_State* state)
+static int lua_Game_setCursorVisible(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2181,7 +2106,7 @@ int lua_Game_setCursorVisible(lua_State* state)
     return 0;
 }
 
-int lua_Game_setMouseCaptured(lua_State* state)
+static int lua_Game_setMouseCaptured(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2217,7 +2142,7 @@ int lua_Game_setMouseCaptured(lua_State* state)
     return 0;
 }
 
-int lua_Game_setMultiSampling(lua_State* state)
+static int lua_Game_setMultiSampling(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2253,7 +2178,7 @@ int lua_Game_setMultiSampling(lua_State* state)
     return 0;
 }
 
-int lua_Game_setMultiTouch(lua_State* state)
+static int lua_Game_setMultiTouch(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2289,7 +2214,7 @@ int lua_Game_setMultiTouch(lua_State* state)
     return 0;
 }
 
-int lua_Game_setViewport(lua_State* state)
+static int lua_Game_setViewport(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2331,7 +2256,7 @@ int lua_Game_setViewport(lua_State* state)
     return 0;
 }
 
-int lua_Game_static_getAbsoluteTime(lua_State* state)
+static int lua_Game_static_getAbsoluteTime(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2359,7 +2284,7 @@ int lua_Game_static_getAbsoluteTime(lua_State* state)
     return 0;
 }
 
-int lua_Game_static_getGameTime(lua_State* state)
+static int lua_Game_static_getGameTime(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2387,7 +2312,7 @@ int lua_Game_static_getGameTime(lua_State* state)
     return 0;
 }
 
-int lua_Game_static_getInstance(lua_State* state)
+static int lua_Game_static_getInstance(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2424,7 +2349,7 @@ int lua_Game_static_getInstance(lua_State* state)
     return 0;
 }
 
-int lua_Game_static_isVsync(lua_State* state)
+static int lua_Game_static_isVsync(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2452,7 +2377,7 @@ int lua_Game_static_isVsync(lua_State* state)
     return 0;
 }
 
-int lua_Game_static_setVsync(lua_State* state)
+static int lua_Game_static_setVsync(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2486,7 +2411,7 @@ int lua_Game_static_setVsync(lua_State* state)
     return 0;
 }
 
-int lua_Game_touchEvent(lua_State* state)
+static int lua_Game_touchEvent(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2534,7 +2459,7 @@ int lua_Game_touchEvent(lua_State* state)
     return 0;
 }
 
-int lua_Game_unregisterGesture(lua_State* state)
+static int lua_Game_unregisterGesture(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -2570,4 +2495,80 @@ int lua_Game_unregisterGesture(lua_State* state)
     return 0;
 }
 
+void luaRegister_Game()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"canExit", lua_Game_canExit},
+        {"clear", lua_Game_clear},
+        {"clearSchedule", lua_Game_clearSchedule},
+        {"displayKeyboard", lua_Game_displayKeyboard},
+        {"exit", lua_Game_exit},
+        {"frame", lua_Game_frame},
+        {"gamepadEvent", lua_Game_gamepadEvent},
+        {"gestureDragEvent", lua_Game_gestureDragEvent},
+        {"gestureDropEvent", lua_Game_gestureDropEvent},
+        {"gestureLongTapEvent", lua_Game_gestureLongTapEvent},
+        {"gesturePinchEvent", lua_Game_gesturePinchEvent},
+        {"gestureSwipeEvent", lua_Game_gestureSwipeEvent},
+        {"gestureTapEvent", lua_Game_gestureTapEvent},
+        {"getAIController", lua_Game_getAIController},
+        {"getAccelerometerValues", lua_Game_getAccelerometerValues},
+        {"getAnimationController", lua_Game_getAnimationController},
+        {"getAspectRatio", lua_Game_getAspectRatio},
+        {"getAudioController", lua_Game_getAudioController},
+        {"getAudioListener", lua_Game_getAudioListener},
+        {"getConfig", lua_Game_getConfig},
+        {"getFrameRate", lua_Game_getFrameRate},
+        {"getGamepad", lua_Game_getGamepad},
+        {"getGamepadCount", lua_Game_getGamepadCount},
+        {"getHeight", lua_Game_getHeight},
+        {"getPhysicsController", lua_Game_getPhysicsController},
+        {"getScriptController", lua_Game_getScriptController},
+        {"getSensorValues", lua_Game_getSensorValues},
+        {"getState", lua_Game_getState},
+        {"getViewport", lua_Game_getViewport},
+        {"getWidth", lua_Game_getWidth},
+        {"hasAccelerometer", lua_Game_hasAccelerometer},
+        {"hasMouse", lua_Game_hasMouse},
+        {"isCursorVisible", lua_Game_isCursorVisible},
+        {"isGestureRegistered", lua_Game_isGestureRegistered},
+        {"isGestureSupported", lua_Game_isGestureSupported},
+        {"isInitialized", lua_Game_isInitialized},
+        {"isMouseCaptured", lua_Game_isMouseCaptured},
+        {"isMultiSampling", lua_Game_isMultiSampling},
+        {"isMultiTouch", lua_Game_isMultiTouch},
+        {"keyEvent", lua_Game_keyEvent},
+        {"launchURL", lua_Game_launchURL},
+        {"mouseEvent", lua_Game_mouseEvent},
+        {"pause", lua_Game_pause},
+        {"registerGesture", lua_Game_registerGesture},
+        {"resizeEvent", lua_Game_resizeEvent},
+        {"resume", lua_Game_resume},
+        {"run", lua_Game_run},
+        {"schedule", lua_Game_schedule},
+        {"setCursorVisible", lua_Game_setCursorVisible},
+        {"setMouseCaptured", lua_Game_setMouseCaptured},
+        {"setMultiSampling", lua_Game_setMultiSampling},
+        {"setMultiTouch", lua_Game_setMultiTouch},
+        {"setViewport", lua_Game_setViewport},
+        {"touchEvent", lua_Game_touchEvent},
+        {"unregisterGesture", lua_Game_unregisterGesture},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"getAbsoluteTime", lua_Game_static_getAbsoluteTime},
+        {"getGameTime", lua_Game_static_getGameTime},
+        {"getInstance", lua_Game_static_getInstance},
+        {"isVsync", lua_Game_static_isVsync},
+        {"setVsync", lua_Game_static_setVsync},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("Game", lua_members, lua_Game__init, lua_Game__gc, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 64
gameplay/src/lua/lua_Game.h

@@ -5,70 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Game.
-int lua_Game__gc(lua_State* state);
-int lua_Game__init(lua_State* state);
-int lua_Game_canExit(lua_State* state);
-int lua_Game_clear(lua_State* state);
-int lua_Game_clearSchedule(lua_State* state);
-int lua_Game_displayKeyboard(lua_State* state);
-int lua_Game_exit(lua_State* state);
-int lua_Game_frame(lua_State* state);
-int lua_Game_gamepadEvent(lua_State* state);
-int lua_Game_gestureDragEvent(lua_State* state);
-int lua_Game_gestureDropEvent(lua_State* state);
-int lua_Game_gestureLongTapEvent(lua_State* state);
-int lua_Game_gesturePinchEvent(lua_State* state);
-int lua_Game_gestureSwipeEvent(lua_State* state);
-int lua_Game_gestureTapEvent(lua_State* state);
-int lua_Game_getAIController(lua_State* state);
-int lua_Game_getAccelerometerValues(lua_State* state);
-int lua_Game_getAnimationController(lua_State* state);
-int lua_Game_getAspectRatio(lua_State* state);
-int lua_Game_getAudioController(lua_State* state);
-int lua_Game_getAudioListener(lua_State* state);
-int lua_Game_getConfig(lua_State* state);
-int lua_Game_getFrameRate(lua_State* state);
-int lua_Game_getGamepad(lua_State* state);
-int lua_Game_getGamepadCount(lua_State* state);
-int lua_Game_getHeight(lua_State* state);
-int lua_Game_getPhysicsController(lua_State* state);
-int lua_Game_getScriptController(lua_State* state);
-int lua_Game_getSensorValues(lua_State* state);
-int lua_Game_getState(lua_State* state);
-int lua_Game_getViewport(lua_State* state);
-int lua_Game_getWidth(lua_State* state);
-int lua_Game_hasAccelerometer(lua_State* state);
-int lua_Game_hasMouse(lua_State* state);
-int lua_Game_isCursorVisible(lua_State* state);
-int lua_Game_isGestureRegistered(lua_State* state);
-int lua_Game_isGestureSupported(lua_State* state);
-int lua_Game_isInitialized(lua_State* state);
-int lua_Game_isMouseCaptured(lua_State* state);
-int lua_Game_isMultiSampling(lua_State* state);
-int lua_Game_isMultiTouch(lua_State* state);
-int lua_Game_keyEvent(lua_State* state);
-int lua_Game_launchURL(lua_State* state);
-int lua_Game_mouseEvent(lua_State* state);
-int lua_Game_pause(lua_State* state);
-int lua_Game_registerGesture(lua_State* state);
-int lua_Game_resizeEvent(lua_State* state);
-int lua_Game_resume(lua_State* state);
-int lua_Game_run(lua_State* state);
-int lua_Game_schedule(lua_State* state);
-int lua_Game_setCursorVisible(lua_State* state);
-int lua_Game_setMouseCaptured(lua_State* state);
-int lua_Game_setMultiSampling(lua_State* state);
-int lua_Game_setMultiTouch(lua_State* state);
-int lua_Game_setViewport(lua_State* state);
-int lua_Game_static_getAbsoluteTime(lua_State* state);
-int lua_Game_static_getGameTime(lua_State* state);
-int lua_Game_static_getInstance(lua_State* state);
-int lua_Game_static_isVsync(lua_State* state);
-int lua_Game_static_setVsync(lua_State* state);
-int lua_Game_touchEvent(lua_State* state);
-int lua_Game_unregisterGesture(lua_State* state);
-
 void luaRegister_Game();
 
 }

+ 35 - 34
gameplay/src/lua/lua_Gamepad.cpp

@@ -13,29 +13,6 @@
 namespace gameplay
 {
 
-void luaRegister_Gamepad()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"draw", lua_Gamepad_draw},
-        {"getButtonCount", lua_Gamepad_getButtonCount},
-        {"getForm", lua_Gamepad_getForm},
-        {"getJoystickCount", lua_Gamepad_getJoystickCount},
-        {"getJoystickValues", lua_Gamepad_getJoystickValues},
-        {"getName", lua_Gamepad_getName},
-        {"getTriggerCount", lua_Gamepad_getTriggerCount},
-        {"getTriggerValue", lua_Gamepad_getTriggerValue},
-        {"isButtonDown", lua_Gamepad_isButtonDown},
-        {"isVirtual", lua_Gamepad_isVirtual},
-        {"update", lua_Gamepad_update},
-        {NULL, NULL}
-    };
-    const luaL_Reg* lua_statics = NULL;
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("Gamepad", lua_members, NULL, NULL, lua_statics, scopePath);
-}
-
 static Gamepad* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "Gamepad");
@@ -43,7 +20,7 @@ static Gamepad* getInstance(lua_State* state)
     return (Gamepad*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_Gamepad_draw(lua_State* state)
+static int lua_Gamepad_draw(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -75,7 +52,7 @@ int lua_Gamepad_draw(lua_State* state)
     return 0;
 }
 
-int lua_Gamepad_getButtonCount(lua_State* state)
+static int lua_Gamepad_getButtonCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -110,7 +87,7 @@ int lua_Gamepad_getButtonCount(lua_State* state)
     return 0;
 }
 
-int lua_Gamepad_getForm(lua_State* state)
+static int lua_Gamepad_getForm(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -154,7 +131,7 @@ int lua_Gamepad_getForm(lua_State* state)
     return 0;
 }
 
-int lua_Gamepad_getJoystickCount(lua_State* state)
+static int lua_Gamepad_getJoystickCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -189,7 +166,7 @@ int lua_Gamepad_getJoystickCount(lua_State* state)
     return 0;
 }
 
-int lua_Gamepad_getJoystickValues(lua_State* state)
+static int lua_Gamepad_getJoystickValues(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -235,7 +212,7 @@ int lua_Gamepad_getJoystickValues(lua_State* state)
     return 0;
 }
 
-int lua_Gamepad_getName(lua_State* state)
+static int lua_Gamepad_getName(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -270,7 +247,7 @@ int lua_Gamepad_getName(lua_State* state)
     return 0;
 }
 
-int lua_Gamepad_getTriggerCount(lua_State* state)
+static int lua_Gamepad_getTriggerCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -305,7 +282,7 @@ int lua_Gamepad_getTriggerCount(lua_State* state)
     return 0;
 }
 
-int lua_Gamepad_getTriggerValue(lua_State* state)
+static int lua_Gamepad_getTriggerValue(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -344,7 +321,7 @@ int lua_Gamepad_getTriggerValue(lua_State* state)
     return 0;
 }
 
-int lua_Gamepad_isButtonDown(lua_State* state)
+static int lua_Gamepad_isButtonDown(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -383,7 +360,7 @@ int lua_Gamepad_isButtonDown(lua_State* state)
     return 0;
 }
 
-int lua_Gamepad_isVirtual(lua_State* state)
+static int lua_Gamepad_isVirtual(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -418,7 +395,7 @@ int lua_Gamepad_isVirtual(lua_State* state)
     return 0;
 }
 
-int lua_Gamepad_update(lua_State* state)
+static int lua_Gamepad_update(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -454,4 +431,28 @@ int lua_Gamepad_update(lua_State* state)
     return 0;
 }
 
+void luaRegister_Gamepad()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"draw", lua_Gamepad_draw},
+        {"getButtonCount", lua_Gamepad_getButtonCount},
+        {"getForm", lua_Gamepad_getForm},
+        {"getJoystickCount", lua_Gamepad_getJoystickCount},
+        {"getJoystickValues", lua_Gamepad_getJoystickValues},
+        {"getName", lua_Gamepad_getName},
+        {"getTriggerCount", lua_Gamepad_getTriggerCount},
+        {"getTriggerValue", lua_Gamepad_getTriggerValue},
+        {"isButtonDown", lua_Gamepad_isButtonDown},
+        {"isVirtual", lua_Gamepad_isVirtual},
+        {"update", lua_Gamepad_update},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("Gamepad", lua_members, NULL, NULL, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 13
gameplay/src/lua/lua_Gamepad.h

@@ -5,19 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Gamepad.
-int lua_Gamepad_draw(lua_State* state);
-int lua_Gamepad_getButtonCount(lua_State* state);
-int lua_Gamepad_getForm(lua_State* state);
-int lua_Gamepad_getJoystickCount(lua_State* state);
-int lua_Gamepad_getJoystickValues(lua_State* state);
-int lua_Gamepad_getName(lua_State* state);
-int lua_Gamepad_getTriggerCount(lua_State* state);
-int lua_Gamepad_getTriggerValue(lua_State* state);
-int lua_Gamepad_isButtonDown(lua_State* state);
-int lua_Gamepad_isVirtual(lua_State* state);
-int lua_Gamepad_update(lua_State* state);
-
 void luaRegister_Gamepad();
 
 }

+ 25 - 24
gameplay/src/lua/lua_Gesture.cpp

@@ -7,25 +7,6 @@
 namespace gameplay
 {
 
-void luaRegister_Gesture()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"SWIPE_DIRECTION_DOWN", lua_Gesture_static_SWIPE_DIRECTION_DOWN},
-        {"SWIPE_DIRECTION_LEFT", lua_Gesture_static_SWIPE_DIRECTION_LEFT},
-        {"SWIPE_DIRECTION_RIGHT", lua_Gesture_static_SWIPE_DIRECTION_RIGHT},
-        {"SWIPE_DIRECTION_UP", lua_Gesture_static_SWIPE_DIRECTION_UP},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("Gesture", lua_members, NULL, lua_Gesture__gc, lua_statics, scopePath);
-}
-
 static Gesture* getInstance(lua_State* state)
 {
     void* userdata = luaL_checkudata(state, 1, "Gesture");
@@ -33,7 +14,7 @@ static Gesture* getInstance(lua_State* state)
     return (Gesture*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_Gesture__gc(lua_State* state)
+static int lua_Gesture__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -71,7 +52,7 @@ int lua_Gesture__gc(lua_State* state)
     return 0;
 }
 
-int lua_Gesture_static_SWIPE_DIRECTION_DOWN(lua_State* state)
+static int lua_Gesture_static_SWIPE_DIRECTION_DOWN(lua_State* state)
 {
     // Validate the number of parameters.
     if (lua_gettop(state) > 0)
@@ -88,7 +69,7 @@ int lua_Gesture_static_SWIPE_DIRECTION_DOWN(lua_State* state)
     return 1;
 }
 
-int lua_Gesture_static_SWIPE_DIRECTION_LEFT(lua_State* state)
+static int lua_Gesture_static_SWIPE_DIRECTION_LEFT(lua_State* state)
 {
     // Validate the number of parameters.
     if (lua_gettop(state) > 0)
@@ -105,7 +86,7 @@ int lua_Gesture_static_SWIPE_DIRECTION_LEFT(lua_State* state)
     return 1;
 }
 
-int lua_Gesture_static_SWIPE_DIRECTION_RIGHT(lua_State* state)
+static int lua_Gesture_static_SWIPE_DIRECTION_RIGHT(lua_State* state)
 {
     // Validate the number of parameters.
     if (lua_gettop(state) > 0)
@@ -122,7 +103,7 @@ int lua_Gesture_static_SWIPE_DIRECTION_RIGHT(lua_State* state)
     return 1;
 }
 
-int lua_Gesture_static_SWIPE_DIRECTION_UP(lua_State* state)
+static int lua_Gesture_static_SWIPE_DIRECTION_UP(lua_State* state)
 {
     // Validate the number of parameters.
     if (lua_gettop(state) > 0)
@@ -139,4 +120,24 @@ int lua_Gesture_static_SWIPE_DIRECTION_UP(lua_State* state)
     return 1;
 }
 
+void luaRegister_Gesture()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"SWIPE_DIRECTION_DOWN", lua_Gesture_static_SWIPE_DIRECTION_DOWN},
+        {"SWIPE_DIRECTION_LEFT", lua_Gesture_static_SWIPE_DIRECTION_LEFT},
+        {"SWIPE_DIRECTION_RIGHT", lua_Gesture_static_SWIPE_DIRECTION_RIGHT},
+        {"SWIPE_DIRECTION_UP", lua_Gesture_static_SWIPE_DIRECTION_UP},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("Gesture", lua_members, NULL, lua_Gesture__gc, lua_statics, scopePath);
+
+}
+
 }

+ 0 - 7
gameplay/src/lua/lua_Gesture.h

@@ -5,13 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Gesture.
-int lua_Gesture__gc(lua_State* state);
-int lua_Gesture_static_SWIPE_DIRECTION_DOWN(lua_State* state);
-int lua_Gesture_static_SWIPE_DIRECTION_LEFT(lua_State* state);
-int lua_Gesture_static_SWIPE_DIRECTION_RIGHT(lua_State* state);
-int lua_Gesture_static_SWIPE_DIRECTION_UP(lua_State* state);
-
 void luaRegister_Gesture();
 
 }

+ 224 - 146
gameplay/src/lua/lua_Global.cpp

@@ -1,4 +1,5 @@
 // Autogenerated by gameplay-luagen
+#include "Base.h"
 #include "ScriptController.h"
 #include "lua_Global.h"
 #include "AIMessage.h"
@@ -38,154 +39,204 @@
 namespace gameplay
 {
 
+static std::unordered_map<std::string, void*(*)(void*, const char*)> __conversionFunctions;
+
+void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*))
+{
+    __conversionFunctions[className] = func;
+}
+
+static std::map<std::string, std::vector<std::string> > __hierarchyPairs;
+
+static void setHierarchyPair(const std::string& type1, const std::string& type2)
+{
+    __hierarchyPairs[type1].push_back(type2);
+}
+
 void luaRegister_lua_Global()
 {
     gameplay::ScriptUtil::registerFunction("strcmpnocase", lua__strcmpnocase);
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "Button");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "CheckBox");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "Container");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "Control");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "Form");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "ImageControl");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "Joint");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "JoystickControl");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "Label");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "MaterialParameter");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "Node");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "RadioButton");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "Slider");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "Sprite");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "Text");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "TextBox");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "Transform");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Button", "CheckBox");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Button", "RadioButton");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Camera::Listener", "AudioListener");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Camera::Listener", "TerrainPatch");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Container", "Form");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Control", "Button");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Control", "CheckBox");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Control", "Container");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Control", "Form");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Control", "ImageControl");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Control", "JoystickControl");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Control", "Label");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Control", "RadioButton");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Control", "Slider");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Control", "TextBox");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Drawable", "Form");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Drawable", "Model");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Drawable", "ParticleEmitter");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Drawable", "Sprite");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Drawable", "Terrain");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Drawable", "Text");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Drawable", "TileSet");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Label", "Button");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Label", "CheckBox");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Label", "RadioButton");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Label", "Slider");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Label", "TextBox");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Layout", "AbsoluteLayout");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Layout", "FlowLayout");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Layout", "VerticalLayout");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Node", "Joint");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("PhysicsCollisionObject", "PhysicsCharacter");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("PhysicsCollisionObject", "PhysicsGhostObject");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("PhysicsCollisionObject", "PhysicsRigidBody");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("PhysicsCollisionObject", "PhysicsVehicle");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("PhysicsCollisionObject", "PhysicsVehicleWheel");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("PhysicsConstraint", "PhysicsFixedConstraint");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("PhysicsConstraint", "PhysicsGenericConstraint");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("PhysicsConstraint", "PhysicsHingeConstraint");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("PhysicsConstraint", "PhysicsSocketConstraint");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("PhysicsConstraint", "PhysicsSpringConstraint");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("PhysicsGenericConstraint", "PhysicsFixedConstraint");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("PhysicsGenericConstraint", "PhysicsSpringConstraint");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("PhysicsGhostObject", "PhysicsCharacter");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "AIAgent");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "AIState");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "AbsoluteLayout");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Animation");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "AnimationClip");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "AudioBuffer");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "AudioSource");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Bundle");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Button");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Camera");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "CheckBox");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Container");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Control");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Curve");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "DepthStencilTarget");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Effect");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "FlowLayout");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Font");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Form");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "FrameBuffer");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "HeightField");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Image");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "ImageControl");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Joint");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "JoystickControl");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Label");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Layout");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Light");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Material");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "MaterialParameter");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Mesh");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Model");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Node");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "ParticleEmitter");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Pass");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "PhysicsCollisionShape");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "RadioButton");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "RenderState");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "RenderState::StateBlock");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "RenderTarget");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Scene");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Script");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Slider");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Sprite");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Technique");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Terrain");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Text");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "TextBox");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Texture");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Texture::Sampler");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Theme");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "Theme::ThemeImage");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "TileSet");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "VertexAttributeBinding");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Ref", "VerticalLayout");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("RenderState", "Material");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("RenderState", "Pass");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("RenderState", "Technique");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "AnimationClip");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "Button");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "CheckBox");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "Container");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "Control");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "Form");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "GameScriptTarget");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "ImageControl");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "Joint");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "JoystickControl");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "Label");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "Node");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "PhysicsController");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "RadioButton");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "Slider");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "TextBox");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("ScriptTarget", "Transform");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Transform", "Joint");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Transform", "Node");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Transform::Listener", "AudioSource");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Transform::Listener", "Camera");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Transform::Listener", "MeshSkin");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Transform::Listener", "PhysicsCharacter");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Transform::Listener", "PhysicsGhostObject");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Transform::Listener", "PhysicsRigidBody");
-    gameplay::ScriptUtil::setGlobalHierarchyPair("Transform::Listener", "Terrain");
+
+    setHierarchyPair("AIAgent", "Ref");
+    setHierarchyPair("AIState", "Ref");
+    setHierarchyPair("AbsoluteLayout", "Layout");
+    setHierarchyPair("Animation", "Ref");
+    setHierarchyPair("AnimationClip", "Ref");
+    setHierarchyPair("AnimationClip", "ScriptTarget");
+    setHierarchyPair("AnimationTarget", "Control");
+    setHierarchyPair("AnimationTarget", "MaterialParameter");
+    setHierarchyPair("AnimationTarget", "Sprite");
+    setHierarchyPair("AnimationTarget", "Text");
+    setHierarchyPair("AnimationTarget", "Transform");
+    setHierarchyPair("AudioBuffer", "Ref");
+    setHierarchyPair("AudioListener", "Camera::Listener");
+    setHierarchyPair("AudioSource", "Ref");
+    setHierarchyPair("AudioSource", "Transform::Listener");
+    setHierarchyPair("Bundle", "Ref");
+    setHierarchyPair("Button", "CheckBox");
+    setHierarchyPair("Button", "Label");
+    setHierarchyPair("Button", "RadioButton");
+    setHierarchyPair("Camera", "Ref");
+    setHierarchyPair("Camera", "Transform::Listener");
+    setHierarchyPair("Camera::Listener", "AudioListener");
+    setHierarchyPair("Camera::Listener", "TerrainPatch");
+    setHierarchyPair("CheckBox", "Button");
+    setHierarchyPair("Container", "Control");
+    setHierarchyPair("Container", "Form");
+    setHierarchyPair("Control", "AnimationTarget");
+    setHierarchyPair("Control", "Container");
+    setHierarchyPair("Control", "ImageControl");
+    setHierarchyPair("Control", "JoystickControl");
+    setHierarchyPair("Control", "Label");
+    setHierarchyPair("Control", "Ref");
+    setHierarchyPair("Control", "ScriptTarget");
+    setHierarchyPair("Curve", "Ref");
+    setHierarchyPair("DepthStencilTarget", "Ref");
+    setHierarchyPair("Drawable", "Form");
+    setHierarchyPair("Drawable", "Model");
+    setHierarchyPair("Drawable", "ParticleEmitter");
+    setHierarchyPair("Drawable", "Sprite");
+    setHierarchyPair("Drawable", "Terrain");
+    setHierarchyPair("Drawable", "Text");
+    setHierarchyPair("Drawable", "TileSet");
+    setHierarchyPair("Effect", "Ref");
+    setHierarchyPair("FlowLayout", "Layout");
+    setHierarchyPair("Font", "Ref");
+    setHierarchyPair("Form", "Container");
+    setHierarchyPair("Form", "Drawable");
+    setHierarchyPair("FrameBuffer", "Ref");
+    setHierarchyPair("HeightField", "Ref");
+    setHierarchyPair("Image", "Ref");
+    setHierarchyPair("ImageControl", "Control");
+    setHierarchyPair("Joint", "Node");
+    setHierarchyPair("JoystickControl", "Control");
+    setHierarchyPair("Label", "Button");
+    setHierarchyPair("Label", "Control");
+    setHierarchyPair("Label", "Slider");
+    setHierarchyPair("Label", "TextBox");
+    setHierarchyPair("Layout", "AbsoluteLayout");
+    setHierarchyPair("Layout", "FlowLayout");
+    setHierarchyPair("Layout", "Ref");
+    setHierarchyPair("Layout", "VerticalLayout");
+    setHierarchyPair("Light", "Ref");
+    setHierarchyPair("Material", "RenderState");
+    setHierarchyPair("MaterialParameter", "AnimationTarget");
+    setHierarchyPair("MaterialParameter", "Ref");
+    setHierarchyPair("Mesh", "Ref");
+    setHierarchyPair("MeshSkin", "Transform::Listener");
+    setHierarchyPair("Model", "Drawable");
+    setHierarchyPair("Model", "Ref");
+    setHierarchyPair("Node", "Joint");
+    setHierarchyPair("Node", "Ref");
+    setHierarchyPair("Node", "Transform");
+    setHierarchyPair("ParticleEmitter", "Drawable");
+    setHierarchyPair("ParticleEmitter", "Ref");
+    setHierarchyPair("Pass", "RenderState");
+    setHierarchyPair("PhysicsCharacter", "PhysicsGhostObject");
+    setHierarchyPair("PhysicsCollisionObject", "PhysicsGhostObject");
+    setHierarchyPair("PhysicsCollisionObject", "PhysicsRigidBody");
+    setHierarchyPair("PhysicsCollisionObject", "PhysicsVehicle");
+    setHierarchyPair("PhysicsCollisionObject", "PhysicsVehicleWheel");
+    setHierarchyPair("PhysicsCollisionShape", "Ref");
+    setHierarchyPair("PhysicsConstraint", "PhysicsGenericConstraint");
+    setHierarchyPair("PhysicsConstraint", "PhysicsHingeConstraint");
+    setHierarchyPair("PhysicsConstraint", "PhysicsSocketConstraint");
+    setHierarchyPair("PhysicsController", "ScriptTarget");
+    setHierarchyPair("PhysicsFixedConstraint", "PhysicsGenericConstraint");
+    setHierarchyPair("PhysicsGenericConstraint", "PhysicsConstraint");
+    setHierarchyPair("PhysicsGenericConstraint", "PhysicsFixedConstraint");
+    setHierarchyPair("PhysicsGenericConstraint", "PhysicsSpringConstraint");
+    setHierarchyPair("PhysicsGhostObject", "PhysicsCharacter");
+    setHierarchyPair("PhysicsGhostObject", "PhysicsCollisionObject");
+    setHierarchyPair("PhysicsGhostObject", "Transform::Listener");
+    setHierarchyPair("PhysicsHingeConstraint", "PhysicsConstraint");
+    setHierarchyPair("PhysicsRigidBody", "PhysicsCollisionObject");
+    setHierarchyPair("PhysicsRigidBody", "Transform::Listener");
+    setHierarchyPair("PhysicsSocketConstraint", "PhysicsConstraint");
+    setHierarchyPair("PhysicsSpringConstraint", "PhysicsGenericConstraint");
+    setHierarchyPair("PhysicsVehicle", "PhysicsCollisionObject");
+    setHierarchyPair("PhysicsVehicleWheel", "PhysicsCollisionObject");
+    setHierarchyPair("RadioButton", "Button");
+    setHierarchyPair("Ref", "AIAgent");
+    setHierarchyPair("Ref", "AIState");
+    setHierarchyPair("Ref", "Animation");
+    setHierarchyPair("Ref", "AnimationClip");
+    setHierarchyPair("Ref", "AudioBuffer");
+    setHierarchyPair("Ref", "AudioSource");
+    setHierarchyPair("Ref", "Bundle");
+    setHierarchyPair("Ref", "Camera");
+    setHierarchyPair("Ref", "Control");
+    setHierarchyPair("Ref", "Curve");
+    setHierarchyPair("Ref", "DepthStencilTarget");
+    setHierarchyPair("Ref", "Effect");
+    setHierarchyPair("Ref", "Font");
+    setHierarchyPair("Ref", "FrameBuffer");
+    setHierarchyPair("Ref", "HeightField");
+    setHierarchyPair("Ref", "Image");
+    setHierarchyPair("Ref", "Layout");
+    setHierarchyPair("Ref", "Light");
+    setHierarchyPair("Ref", "MaterialParameter");
+    setHierarchyPair("Ref", "Mesh");
+    setHierarchyPair("Ref", "Model");
+    setHierarchyPair("Ref", "Node");
+    setHierarchyPair("Ref", "ParticleEmitter");
+    setHierarchyPair("Ref", "PhysicsCollisionShape");
+    setHierarchyPair("Ref", "RenderState");
+    setHierarchyPair("Ref", "RenderState::StateBlock");
+    setHierarchyPair("Ref", "RenderTarget");
+    setHierarchyPair("Ref", "Scene");
+    setHierarchyPair("Ref", "Script");
+    setHierarchyPair("Ref", "Sprite");
+    setHierarchyPair("Ref", "Terrain");
+    setHierarchyPair("Ref", "Text");
+    setHierarchyPair("Ref", "Texture");
+    setHierarchyPair("Ref", "Texture::Sampler");
+    setHierarchyPair("Ref", "Theme");
+    setHierarchyPair("Ref", "Theme::ThemeImage");
+    setHierarchyPair("Ref", "TileSet");
+    setHierarchyPair("Ref", "VertexAttributeBinding");
+    setHierarchyPair("RenderState", "Material");
+    setHierarchyPair("RenderState", "Pass");
+    setHierarchyPair("RenderState", "Ref");
+    setHierarchyPair("RenderState", "Technique");
+    setHierarchyPair("RenderState::StateBlock", "Ref");
+    setHierarchyPair("RenderTarget", "Ref");
+    setHierarchyPair("Scene", "Ref");
+    setHierarchyPair("Script", "Ref");
+    setHierarchyPair("ScriptTarget", "AnimationClip");
+    setHierarchyPair("ScriptTarget", "Control");
+    setHierarchyPair("ScriptTarget", "PhysicsController");
+    setHierarchyPair("ScriptTarget", "Transform");
+    setHierarchyPair("Slider", "Label");
+    setHierarchyPair("Sprite", "AnimationTarget");
+    setHierarchyPair("Sprite", "Drawable");
+    setHierarchyPair("Sprite", "Ref");
+    setHierarchyPair("Technique", "RenderState");
+    setHierarchyPair("Terrain", "Drawable");
+    setHierarchyPair("Terrain", "Ref");
+    setHierarchyPair("Terrain", "Transform::Listener");
+    setHierarchyPair("TerrainPatch", "Camera::Listener");
+    setHierarchyPair("Text", "AnimationTarget");
+    setHierarchyPair("Text", "Drawable");
+    setHierarchyPair("Text", "Ref");
+    setHierarchyPair("TextBox", "Label");
+    setHierarchyPair("Texture", "Ref");
+    setHierarchyPair("Texture::Sampler", "Ref");
+    setHierarchyPair("Theme", "Ref");
+    setHierarchyPair("Theme::ThemeImage", "Ref");
+    setHierarchyPair("TileSet", "Drawable");
+    setHierarchyPair("TileSet", "Ref");
+    setHierarchyPair("Transform", "AnimationTarget");
+    setHierarchyPair("Transform", "Node");
+    setHierarchyPair("Transform", "ScriptTarget");
+    setHierarchyPair("Transform::Listener", "AudioSource");
+    setHierarchyPair("Transform::Listener", "Camera");
+    setHierarchyPair("Transform::Listener", "MeshSkin");
+    setHierarchyPair("Transform::Listener", "PhysicsGhostObject");
+    setHierarchyPair("Transform::Listener", "PhysicsRigidBody");
+    setHierarchyPair("Transform::Listener", "Terrain");
+    setHierarchyPair("VertexAttributeBinding", "Ref");
+    setHierarchyPair("VerticalLayout", "Layout");
 
     // Register enumeration AIMessage::ParameterType.
     {
@@ -293,6 +344,7 @@ void luaRegister_lua_Global()
         gameplay::ScriptUtil::registerEnumValue(Control::Listener::TEXT_CHANGED, "TEXT_CHANGED", scopePath);
         gameplay::ScriptUtil::registerEnumValue(Control::Listener::MIDDLE_CLICK, "MIDDLE_CLICK", scopePath);
         gameplay::ScriptUtil::registerEnumValue(Control::Listener::RIGHT_CLICK, "RIGHT_CLICK", scopePath);
+        gameplay::ScriptUtil::registerEnumValue(Control::Listener::ACTIVATED, "ACTIVATED", scopePath);
         gameplay::ScriptUtil::registerEnumValue(Control::Listener::FOCUS_GAINED, "FOCUS_GAINED", scopePath);
         gameplay::ScriptUtil::registerEnumValue(Control::Listener::FOCUS_LOST, "FOCUS_LOST", scopePath);
     }
@@ -980,8 +1032,14 @@ void luaRegister_lua_Global()
         scopePath.push_back("Texture");
         gameplay::ScriptUtil::registerEnumValue(Texture::UNKNOWN, "UNKNOWN", scopePath);
         gameplay::ScriptUtil::registerEnumValue(Texture::RGB, "RGB", scopePath);
+        gameplay::ScriptUtil::registerEnumValue(Texture::RGB888, "RGB888", scopePath);
+        gameplay::ScriptUtil::registerEnumValue(Texture::RGB565, "RGB565", scopePath);
         gameplay::ScriptUtil::registerEnumValue(Texture::RGBA, "RGBA", scopePath);
+        gameplay::ScriptUtil::registerEnumValue(Texture::RGBA8888, "RGBA8888", scopePath);
+        gameplay::ScriptUtil::registerEnumValue(Texture::RGBA4444, "RGBA4444", scopePath);
+        gameplay::ScriptUtil::registerEnumValue(Texture::RGBA5551, "RGBA5551", scopePath);
         gameplay::ScriptUtil::registerEnumValue(Texture::ALPHA, "ALPHA", scopePath);
+        gameplay::ScriptUtil::registerEnumValue(Texture::DEPTH, "DEPTH", scopePath);
     }
 
     // Register enumeration Texture::Type.
@@ -1031,7 +1089,27 @@ void luaRegister_lua_Global()
     }
 }
 
-int lua__strcmpnocase(lua_State* state)
+const std::vector<std::string>& luaGetClassRelatives(const char* type)
+{
+    return __hierarchyPairs[type];
+}
+
+void* luaConvertObjectPointer(void* ptr, const char* fromType, const char* toType)
+{
+    // Need to convert object pointers as follows:
+    //  1) First, cast from void* to the pre-determined type
+    //  2) Next, static_cast to the requested relative type
+    //  3) Finally, cast back to void* so the resulting pointer can be safely cast to the requested type by the caller
+
+    // Try to find a conversion function registered for fromType
+    std::unordered_map<std::string, void*(*)(void*, const char*)>::iterator itr = __conversionFunctions.find(fromType);
+    if (itr == __conversionFunctions.end())
+        return NULL; // no known conversion
+
+    return itr->second(ptr, toType);
+}
+
+static int lua__strcmpnocase(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);

+ 4 - 0
gameplay/src/lua/lua_Global.h

@@ -10,6 +10,10 @@ int lua__strcmpnocase(lua_State* state);
 
 void luaRegister_lua_Global();
 
+const std::vector<std::string>& luaGetClassRelatives(const char* type);
+
+void* luaConvertObjectPointer(void* ptr, const char* fromType, const char* toType);
+
 }
 
 #endif

+ 85 - 35
gameplay/src/lua/lua_HeightField.cpp

@@ -8,34 +8,12 @@
 #include "HeightField.h"
 #include "Image.h"
 #include "Ref.h"
+#include "Ref.h"
 
 namespace gameplay
 {
 
-void luaRegister_HeightField()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_HeightField_addRef},
-        {"getArray", lua_HeightField_getArray},
-        {"getColumnCount", lua_HeightField_getColumnCount},
-        {"getHeight", lua_HeightField_getHeight},
-        {"getRefCount", lua_HeightField_getRefCount},
-        {"getRowCount", lua_HeightField_getRowCount},
-        {"release", lua_HeightField_release},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"create", lua_HeightField_static_create},
-        {"createFromImage", lua_HeightField_static_createFromImage},
-        {"createFromRAW", lua_HeightField_static_createFromRAW},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("HeightField", lua_members, NULL, lua_HeightField__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static HeightField* getInstance(lua_State* state)
 {
@@ -44,7 +22,7 @@ static HeightField* getInstance(lua_State* state)
     return (HeightField*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_HeightField__gc(lua_State* state)
+static int lua_HeightField__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -82,7 +60,7 @@ int lua_HeightField__gc(lua_State* state)
     return 0;
 }
 
-int lua_HeightField_addRef(lua_State* state)
+static int lua_HeightField_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -114,7 +92,7 @@ int lua_HeightField_addRef(lua_State* state)
     return 0;
 }
 
-int lua_HeightField_getArray(lua_State* state)
+static int lua_HeightField_getArray(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -148,7 +126,7 @@ int lua_HeightField_getArray(lua_State* state)
     return 0;
 }
 
-int lua_HeightField_getColumnCount(lua_State* state)
+static int lua_HeightField_getColumnCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -183,7 +161,7 @@ int lua_HeightField_getColumnCount(lua_State* state)
     return 0;
 }
 
-int lua_HeightField_getHeight(lua_State* state)
+static int lua_HeightField_getHeight(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -226,7 +204,7 @@ int lua_HeightField_getHeight(lua_State* state)
     return 0;
 }
 
-int lua_HeightField_getRefCount(lua_State* state)
+static int lua_HeightField_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -261,7 +239,7 @@ int lua_HeightField_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_HeightField_getRowCount(lua_State* state)
+static int lua_HeightField_getRowCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -296,7 +274,7 @@ int lua_HeightField_getRowCount(lua_State* state)
     return 0;
 }
 
-int lua_HeightField_release(lua_State* state)
+static int lua_HeightField_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -328,7 +306,7 @@ int lua_HeightField_release(lua_State* state)
     return 0;
 }
 
-int lua_HeightField_static_create(lua_State* state)
+static int lua_HeightField_static_create(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -378,7 +356,7 @@ int lua_HeightField_static_create(lua_State* state)
     return 0;
 }
 
-int lua_HeightField_static_createFromImage(lua_State* state)
+static int lua_HeightField_static_createFromImage(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -492,7 +470,7 @@ int lua_HeightField_static_createFromImage(lua_State* state)
     return 0;
 }
 
-int lua_HeightField_static_createFromRAW(lua_State* state)
+static int lua_HeightField_static_createFromRAW(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -630,4 +608,76 @@ int lua_HeightField_static_createFromRAW(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of HeightField
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    HeightField* ptrObject = reinterpret_cast<HeightField*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_HeightField_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_HeightField_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    HeightField* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_HeightField()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_HeightField_addRef},
+        {"getArray", lua_HeightField_getArray},
+        {"getColumnCount", lua_HeightField_getColumnCount},
+        {"getHeight", lua_HeightField_getHeight},
+        {"getRefCount", lua_HeightField_getRefCount},
+        {"getRowCount", lua_HeightField_getRowCount},
+        {"release", lua_HeightField_release},
+        {"to", lua_HeightField_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"create", lua_HeightField_static_create},
+        {"createFromImage", lua_HeightField_static_createFromImage},
+        {"createFromRAW", lua_HeightField_static_createFromRAW},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("HeightField", lua_members, NULL, lua_HeightField__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("HeightField", __convertTo);
+}
+
 }

+ 0 - 13
gameplay/src/lua/lua_HeightField.h

@@ -5,19 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for HeightField.
-int lua_HeightField__gc(lua_State* state);
-int lua_HeightField_addRef(lua_State* state);
-int lua_HeightField_getArray(lua_State* state);
-int lua_HeightField_getColumnCount(lua_State* state);
-int lua_HeightField_getHeight(lua_State* state);
-int lua_HeightField_getRefCount(lua_State* state);
-int lua_HeightField_getRowCount(lua_State* state);
-int lua_HeightField_release(lua_State* state);
-int lua_HeightField_static_create(lua_State* state);
-int lua_HeightField_static_createFromImage(lua_State* state);
-int lua_HeightField_static_createFromRAW(lua_State* state);
-
 void luaRegister_HeightField();
 
 }

+ 79 - 29
gameplay/src/lua/lua_Image.cpp

@@ -7,31 +7,12 @@
 #include "Game.h"
 #include "Image.h"
 #include "Ref.h"
+#include "Ref.h"
 
 namespace gameplay
 {
 
-void luaRegister_Image()
-{
-    const luaL_Reg lua_members[] = 
-    {
-        {"addRef", lua_Image_addRef},
-        {"getFormat", lua_Image_getFormat},
-        {"getHeight", lua_Image_getHeight},
-        {"getRefCount", lua_Image_getRefCount},
-        {"getWidth", lua_Image_getWidth},
-        {"release", lua_Image_release},
-        {NULL, NULL}
-    };
-    const luaL_Reg lua_statics[] = 
-    {
-        {"create", lua_Image_static_create},
-        {NULL, NULL}
-    };
-    std::vector<std::string> scopePath;
-
-    gameplay::ScriptUtil::registerClass("Image", lua_members, NULL, lua_Image__gc, lua_statics, scopePath);
-}
+extern void luaGlobal_Register_Conversion_Function(const char* className, void*(*func)(void*, const char*));
 
 static Image* getInstance(lua_State* state)
 {
@@ -40,7 +21,7 @@ static Image* getInstance(lua_State* state)
     return (Image*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
 }
 
-int lua_Image__gc(lua_State* state)
+static int lua_Image__gc(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -78,7 +59,7 @@ int lua_Image__gc(lua_State* state)
     return 0;
 }
 
-int lua_Image_addRef(lua_State* state)
+static int lua_Image_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -110,7 +91,7 @@ int lua_Image_addRef(lua_State* state)
     return 0;
 }
 
-int lua_Image_getFormat(lua_State* state)
+static int lua_Image_getFormat(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -145,7 +126,7 @@ int lua_Image_getFormat(lua_State* state)
     return 0;
 }
 
-int lua_Image_getHeight(lua_State* state)
+static int lua_Image_getHeight(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -180,7 +161,7 @@ int lua_Image_getHeight(lua_State* state)
     return 0;
 }
 
-int lua_Image_getRefCount(lua_State* state)
+static int lua_Image_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -215,7 +196,7 @@ int lua_Image_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_Image_getWidth(lua_State* state)
+static int lua_Image_getWidth(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -250,7 +231,7 @@ int lua_Image_getWidth(lua_State* state)
     return 0;
 }
 
-int lua_Image_release(lua_State* state)
+static int lua_Image_release(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -282,7 +263,7 @@ int lua_Image_release(lua_State* state)
     return 0;
 }
 
-int lua_Image_static_create(lua_State* state)
+static int lua_Image_static_create(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -413,4 +394,73 @@ int lua_Image_static_create(lua_State* state)
     return 0;
 }
 
+// Provides support for conversion to all known relative types of Image
+static void* __convertTo(void* ptr, const char* typeName)
+{
+    Image* ptrObject = reinterpret_cast<Image*>(ptr);
+
+    if (strcmp(typeName, "Ref") == 0)
+    {
+        return reinterpret_cast<void*>(static_cast<Ref*>(ptrObject));
+    }
+
+    // No conversion available for 'typeName'
+    return NULL;
+}
+
+static int lua_Image_to(lua_State* state)
+{
+    // There should be only a single parameter (this instance)
+    if (lua_gettop(state) != 2 || lua_type(state, 1) != LUA_TUSERDATA || lua_type(state, 2) != LUA_TSTRING)
+    {
+        lua_pushstring(state, "lua_Image_to - Invalid number of parameters (expected 2).");
+        lua_error(state);
+        return 0;
+    }
+
+    Image* instance = getInstance(state);
+    const char* typeName = gameplay::ScriptUtil::getString(2, false);
+    void* result = __convertTo((void*)instance, typeName);
+
+    if (result)
+    {
+        gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+        object->instance = (void*)result;
+        object->owns = false;
+        luaL_getmetatable(state, typeName);
+        lua_setmetatable(state, -2);
+    }
+    else
+    {
+        lua_pushnil(state);
+    }
+
+    return 1;
+}
+
+void luaRegister_Image()
+{
+    const luaL_Reg lua_members[] = 
+    {
+        {"addRef", lua_Image_addRef},
+        {"getFormat", lua_Image_getFormat},
+        {"getHeight", lua_Image_getHeight},
+        {"getRefCount", lua_Image_getRefCount},
+        {"getWidth", lua_Image_getWidth},
+        {"release", lua_Image_release},
+        {"to", lua_Image_to},
+        {NULL, NULL}
+    };
+    const luaL_Reg lua_statics[] = 
+    {
+        {"create", lua_Image_static_create},
+        {NULL, NULL}
+    };
+    std::vector<std::string> scopePath;
+
+    gameplay::ScriptUtil::registerClass("Image", lua_members, NULL, lua_Image__gc, lua_statics, scopePath);
+
+    luaGlobal_Register_Conversion_Function("Image", __convertTo);
+}
+
 }

+ 0 - 10
gameplay/src/lua/lua_Image.h

@@ -5,16 +5,6 @@
 namespace gameplay
 {
 
-// Lua bindings for Image.
-int lua_Image__gc(lua_State* state);
-int lua_Image_addRef(lua_State* state);
-int lua_Image_getFormat(lua_State* state);
-int lua_Image_getHeight(lua_State* state);
-int lua_Image_getRefCount(lua_State* state);
-int lua_Image_getWidth(lua_State* state);
-int lua_Image_release(lua_State* state);
-int lua_Image_static_create(lua_State* state);
-
 void luaRegister_Image();
 
 }

File diff suppressed because it is too large
+ 98 - 225
gameplay/src/lua/lua_ImageControl.cpp


Some files were not shown because too many files changed in this diff