浏览代码

Adds support for detecting name clashes between Lua bindings and Lua keywords.
Renamed end() functions to finish() (Font, MeshBatch, SpriteBatch).
Adds support for using nil/NULL values for strings and object pointers with Lua bindings.
Began adding support for using Lua functions as callbacks and function pointer parameters (currently just Scene::visit).
Fixed a bug with retrieving boolean values from the Lua stack.

Chris Culy 13 年之前
父节点
当前提交
8167dc4e88
共有 100 个文件被更改,包括 8844 次插入6531 次删除
  1. 4 1
      gameplay-luagen/TODO.txt
  2. 72 58
      gameplay-luagen/src/FunctionBinding.cpp
  3. 135 55
      gameplay-luagen/src/Generator.cpp
  4. 2 0
      gameplay/gameplay.vcxproj
  5. 69 60
      gameplay/gameplay.vcxproj.filters
  6. 2 2
      gameplay/src/Container.cpp
  7. 1 1
      gameplay/src/Control.cpp
  8. 2 2
      gameplay/src/Font.cpp
  9. 2 2
      gameplay/src/Font.h
  10. 1 1
      gameplay/src/Form.cpp
  11. 1 1
      gameplay/src/Joystick.cpp
  12. 1 1
      gameplay/src/Label.cpp
  13. 1 1
      gameplay/src/MeshBatch.cpp
  14. 2 2
      gameplay/src/MeshBatch.h
  15. 1 1
      gameplay/src/ParticleEmitter.cpp
  16. 1 1
      gameplay/src/PhysicsController.cpp
  17. 1 1
      gameplay/src/Scene.cpp
  18. 45 0
      gameplay/src/Scene.h
  19. 45 42
      gameplay/src/ScriptController.cpp
  20. 25 2
      gameplay/src/ScriptController.h
  21. 62 9
      gameplay/src/ScriptController.inl
  22. 2 2
      gameplay/src/SpriteBatch.cpp
  23. 3 3
      gameplay/src/SpriteBatch.h
  24. 5 5
      gameplay/src/lua/lua_AbsoluteLayout.cpp
  25. 85 59
      gameplay/src/lua/lua_Animation.cpp
  26. 50 66
      gameplay/src/lua/lua_AnimationClip.cpp
  27. 1 1
      gameplay/src/lua/lua_AnimationClip.h
  28. 5 11
      gameplay/src/lua/lua_AnimationClipListener.cpp
  29. 1 1
      gameplay/src/lua/lua_AnimationController.cpp
  30. 148 108
      gameplay/src/lua/lua_AnimationTarget.cpp
  31. 4 4
      gameplay/src/lua/lua_AnimationValue.cpp
  32. 4 4
      gameplay/src/lua/lua_AudioBuffer.cpp
  33. 1 1
      gameplay/src/lua/lua_AudioController.cpp
  34. 99 81
      gameplay/src/lua/lua_AudioListener.cpp
  35. 76 56
      gameplay/src/lua/lua_AudioSource.cpp
  36. 141 199
      gameplay/src/lua/lua_BoundingBox.cpp
  37. 104 148
      gameplay/src/lua/lua_BoundingSphere.cpp
  38. 102 54
      gameplay/src/lua/lua_Bundle.cpp
  39. 381 198
      gameplay/src/lua/lua_Button.cpp
  40. 5 1
      gameplay/src/lua/lua_Button.h
  41. 161 137
      gameplay/src/lua/lua_Camera.cpp
  42. 382 198
      gameplay/src/lua/lua_CheckBox.cpp
  43. 6 1
      gameplay/src/lua/lua_CheckBox.h
  44. 378 200
      gameplay/src/lua/lua_Container.cpp
  45. 6 1
      gameplay/src/lua/lua_Container.h
  46. 381 198
      gameplay/src/lua/lua_Control.cpp
  47. 5 1
      gameplay/src/lua/lua_Control.h
  48. 5 11
      gameplay/src/lua/lua_ControlListener.cpp
  49. 28 20
      gameplay/src/lua/lua_Curve.cpp
  50. 40 24
      gameplay/src/lua/lua_DepthStencilTarget.cpp
  51. 1 1
      gameplay/src/lua/lua_DepthStencilTarget.h
  52. 221 349
      gameplay/src/lua/lua_Effect.cpp
  53. 15 21
      gameplay/src/lua/lua_FileSystem.cpp
  54. 5 5
      gameplay/src/lua/lua_FlowLayout.cpp
  55. 228 414
      gameplay/src/lua/lua_Font.cpp
  56. 1 1
      gameplay/src/lua/lua_Font.h
  57. 14 6
      gameplay/src/lua/lua_FontGlyph.cpp
  58. 17 9
      gameplay/src/lua/lua_FontText.cpp
  59. 378 201
      gameplay/src/lua/lua_Form.cpp
  60. 6 2
      gameplay/src/lua/lua_Form.h
  61. 92 70
      gameplay/src/lua/lua_FrameBuffer.cpp
  62. 1 1
      gameplay/src/lua/lua_FrameBuffer.h
  63. 153 147
      gameplay/src/lua/lua_Frustum.cpp
  64. 285 81
      gameplay/src/lua/lua_Game.cpp
  65. 3 0
      gameplay/src/lua/lua_Game.h
  66. 439 0
      gameplay/src/lua/lua_Gamepad.cpp
  67. 23 0
      gameplay/src/lua/lua_Gamepad.h
  68. 58 2
      gameplay/src/lua/lua_Global.cpp
  69. 7 0
      gameplay/src/lua/lua_Global.h
  70. 22 14
      gameplay/src/lua/lua_Image.cpp
  71. 379 243
      gameplay/src/lua/lua_Joint.cpp
  72. 382 198
      gameplay/src/lua/lua_Joystick.cpp
  73. 6 1
      gameplay/src/lua/lua_Joystick.h
  74. 1 1
      gameplay/src/lua/lua_Keyboard.cpp
  75. 382 198
      gameplay/src/lua/lua_Label.cpp
  76. 6 1
      gameplay/src/lua/lua_Label.h
  77. 5 5
      gameplay/src/lua/lua_Layout.cpp
  78. 89 73
      gameplay/src/lua/lua_Light.cpp
  79. 190 126
      gameplay/src/lua/lua_Material.cpp
  80. 214 244
      gameplay/src/lua/lua_MaterialParameter.cpp
  81. 1 1
      gameplay/src/lua/lua_MathUtil.cpp
  82. 177 391
      gameplay/src/lua/lua_Matrix.cpp
  83. 225 173
      gameplay/src/lua/lua_Mesh.cpp
  84. 131 129
      gameplay/src/lua/lua_MeshBatch.cpp
  85. 1 1
      gameplay/src/lua/lua_MeshBatch.h
  86. 20 12
      gameplay/src/lua/lua_MeshPart.cpp
  87. 98 68
      gameplay/src/lua/lua_MeshSkin.cpp
  88. 188 118
      gameplay/src/lua/lua_Model.cpp
  89. 1 1
      gameplay/src/lua/lua_Mouse.cpp
  90. 379 243
      gameplay/src/lua/lua_Node.cpp
  91. 56 68
      gameplay/src/lua/lua_NodeCloneContext.cpp
  92. 283 247
      gameplay/src/lua/lua_ParticleEmitter.cpp
  93. 80 60
      gameplay/src/lua/lua_Pass.cpp
  94. 96 150
      gameplay/src/lua/lua_PhysicsCharacter.cpp
  95. 54 80
      gameplay/src/lua/lua_PhysicsCollisionObject.cpp
  96. 19 55
      gameplay/src/lua/lua_PhysicsCollisionObjectCollisionListener.cpp
  97. 45 45
      gameplay/src/lua/lua_PhysicsCollisionObjectCollisionPair.cpp
  98. 203 157
      gameplay/src/lua/lua_PhysicsCollisionShape.cpp
  99. 28 18
      gameplay/src/lua/lua_PhysicsCollisionShapeDefinition.cpp
  100. 52 64
      gameplay/src/lua/lua_PhysicsConstraint.cpp

+ 4 - 1
gameplay-luagen/TODO.txt

@@ -7,11 +7,14 @@ Unsupported:
 
 Normal Priority List:
 =====================
-- Notify users when they generate bindings if a binding will not work due a name clash with a reserved Lua keyword (i.e. "end").
 - Add support for object arrays (i.e. VertexElement*).
 - Add "@script{create}" to the appropriate gameplay functions.
 - Fix memory leaks in gameplay-luagen and in generated code.
+
 - Add support for passing function pointers (i.e. for material parameter binding) (using the same string mechanism that was used for enums?).
+- Add support for function callback parameters using Lua functions (i.e. scene->visit("myLuaFunction")).
+- Add support for touch/key/mouse event callbacks.
+- Add support for listener callbacks.
 
 Low Priority List:
 ==================

+ 72 - 58
gameplay-luagen/src/FunctionBinding.cpp

@@ -3,7 +3,7 @@
 
 
 // Helper functions.
-static inline string getLuaTypeString(const FunctionBinding::Param& p = 
+static inline void outputLuaTypeCheck(ostream& o, int index, const FunctionBinding::Param& p = 
     FunctionBinding::Param(FunctionBinding::Param::TYPE_OBJECT, FunctionBinding::Param::KIND_POINTER));
 static inline void indent(ostream& o, int indentLevel);
 static inline void outputBindingInvocation(ostream& o, const FunctionBinding& b, unsigned int paramCount, unsigned int indentLevel);
@@ -115,17 +115,16 @@ void FunctionBinding::write(ostream& o, const vector<FunctionBinding>& bindings)
         // Pass the return value back to Lua.
         if (bindings[0].returnParam.type == FunctionBinding::Param::TYPE_OBJECT)
         {
-            o << "        " << LUA_OBJECT << "* object = (" << LUA_OBJECT << "*)lua_newuserdata(state, sizeof(" << LUA_OBJECT << "));\n";
             switch (bindings[0].returnParam.kind)
             {
             case FunctionBinding::Param::KIND_POINTER:
-                o << "        object->instance = (void*)instance->" << bindings[0].name << ";\n";
+                o << "        void* returnPtr = (void*)instance->" << bindings[0].name << ";\n";
                 break;
             case FunctionBinding::Param::KIND_VALUE:
-                o << "        object->instance = (void*)new " << bindings[0].returnParam << "(instance->" << bindings[0].name << ");\n";
+                o << "        void* returnPtr = (void*)new " << bindings[0].returnParam << "(instance->" << bindings[0].name << ");\n";
                 break;
             case FunctionBinding::Param::KIND_REFERENCE:
-                o << "        object->instance = (void*)&(instance->" << bindings[0].name << ");\n";
+                o << "        void* returnPtr = (void*)&(instance->" << bindings[0].name << ");\n";
                 break;
             default:
                 GP_ERROR("Invalid return value kind '%d'.", bindings[0].returnParam.kind);
@@ -188,23 +187,22 @@ void FunctionBinding::write(ostream& o, const vector<FunctionBinding>& bindings)
         // Pass the return value back to Lua.
         if (bindings[0].returnParam.type == FunctionBinding::Param::TYPE_OBJECT)
         {
-            o << "        " << LUA_OBJECT << "* object = (" << LUA_OBJECT << "*)lua_newuserdata(state, sizeof(" << LUA_OBJECT << "));\n";
             switch (bindings[0].returnParam.kind)
             {
             case FunctionBinding::Param::KIND_POINTER:
-                o << "        object->instance = (void*)";
+                o << "        void* returnPtr = (void*)";
                 if (bindings[0].classname.size() > 0)
                     o << bindings[0].classname << "::";
                 o << bindings[0].name << ";\n";
                 break;
             case FunctionBinding::Param::KIND_VALUE:
-                o << "        object->instance = (void*)new " << bindings[0].returnParam << "(";
+                o << "        void* returnPtr = (void*)new " << bindings[0].returnParam << "(";
                 if (bindings[0].classname.size() > 0)
                     o << bindings[0].classname << "::";
                 o << bindings[0].name << ");\n";
                 break;
             case FunctionBinding::Param::KIND_REFERENCE:
-                o << "        object->instance = (void*)&(";
+                o << "        void* returnPtr = (void*)&(";
                 if (bindings[0].classname.size() > 0)
                     o << bindings[0].classname << "::";
                 o << bindings[0].name << ");\n";
@@ -239,17 +237,16 @@ void FunctionBinding::write(ostream& o, const vector<FunctionBinding>& bindings)
         o << "    " << bindings[0].classname << "* instance = getInstance(state);\n";
         if (bindings[0].returnParam.type == FunctionBinding::Param::TYPE_OBJECT)
         {
-            o << "    " << LUA_OBJECT << "* object = (" << LUA_OBJECT << "*)lua_newuserdata(state, sizeof(" << LUA_OBJECT << "));\n";
             switch (bindings[0].returnParam.kind)
             {
             case FunctionBinding::Param::KIND_POINTER:
-                o << "    object->instance = (void*)instance->" << bindings[0].name << ";\n";
+                o << "    void* returnPtr = (void*)instance->" << bindings[0].name << ";\n";
                 break;
             case FunctionBinding::Param::KIND_VALUE:
-                o << "    object->instance = (void*)new " << bindings[0].returnParam << "(instance->" << bindings[0].name << ");\n";
+                o << "    void* returnPtr = (void*)new " << bindings[0].returnParam << "(instance->" << bindings[0].name << ");\n";
                 break;
             case FunctionBinding::Param::KIND_REFERENCE:
-                o << "    object->instance = (void*)&(instance->" << bindings[0].name << ");\n";
+                o << "    void* returnPtr = (void*)&(instance->" << bindings[0].name << ");\n";
                 break;
             default:
                 GP_ERROR("Invalid return value kind '%d'.", bindings[0].returnParam.kind);
@@ -278,23 +275,22 @@ void FunctionBinding::write(ostream& o, const vector<FunctionBinding>& bindings)
         // Pass the return value back to Lua.
         if (bindings[0].returnParam.type == FunctionBinding::Param::TYPE_OBJECT)
         {
-            o << "    " << LUA_OBJECT << "* object = (" << LUA_OBJECT << "*)lua_newuserdata(state, sizeof(" << LUA_OBJECT << "));\n";
             switch (bindings[0].returnParam.kind)
             {
             case FunctionBinding::Param::KIND_POINTER:
-                o << "    object->instance = (void*)";
+                o << "    void* returnPtr = (void*)";
                 if (bindings[0].classname.size() > 0)
                     o << bindings[0].classname << "::";
                 o << bindings[0].name << ";\n";
                 break;
             case FunctionBinding::Param::KIND_VALUE:
-                o << "    object->instance = (void*)new " << bindings[0].returnParam << "(";
+                o << "    void* returnPtr = (void*)new " << bindings[0].returnParam << "(";
                 if (bindings[0].classname.size() > 0)
                     o << bindings[0].classname << "::";
                 o << bindings[0].name << ");\n";
                 break;
             case FunctionBinding::Param::KIND_REFERENCE:
-                o << "    object->instance = (void*)&(";
+                o << "    void* returnPtr = (void*)&(";
                 if (bindings[0].classname.size() > 0)
                     o << bindings[0].classname << "::";
                 o << bindings[0].name << ");\n";
@@ -494,12 +490,21 @@ ostream& operator<<(ostream& o, const FunctionBinding::Param& param)
 // ---------------------------------------------
 // Helper functions
 
-static inline string getLuaTypeString(const FunctionBinding::Param& p)
+static inline void outputLuaTypeCheck(ostream& o, int index, const FunctionBinding::Param& p)
 {
     switch (p.type)
     {
     case FunctionBinding::Param::TYPE_BOOL:
-        return ((p.kind == FunctionBinding::Param::KIND_POINTER) ? "LUA_TTABLE" : "LUA_TBOOLEAN");
+        if (p.kind == FunctionBinding::Param::KIND_POINTER) 
+        {
+            o << "(lua_type(state, " << index << ") == LUA_TTABLE || ";
+            o << "lua_type(state, " << index << ") == LUA_TLIGHTUSERDATA)";
+        }
+        else
+        {
+            o << "lua_type(state, " << index << ") == LUA_TBOOLEAN";
+        }
+        break;
     case FunctionBinding::Param::TYPE_CHAR:
     case FunctionBinding::Param::TYPE_SHORT:
     case FunctionBinding::Param::TYPE_INT:
@@ -510,18 +515,31 @@ static inline string getLuaTypeString(const FunctionBinding::Param& p)
     case FunctionBinding::Param::TYPE_ULONG:
     case FunctionBinding::Param::TYPE_FLOAT:
     case FunctionBinding::Param::TYPE_DOUBLE:
-        return ((p.kind == FunctionBinding::Param::KIND_POINTER) ? "LUA_TTABLE" : "LUA_TNUMBER");
+        if (p.kind == FunctionBinding::Param::KIND_POINTER) 
+        {
+            o << "(lua_type(state, " << index << ") == LUA_TTABLE || ";
+            o << "lua_type(state, " << index << ") == LUA_TLIGHTUSERDATA)";
+        }
+        else
+        {
+            o << "lua_type(state, " << index << ") == LUA_TNUMBER";
+        }
+        break;
     case FunctionBinding::Param::TYPE_STRING:
     case FunctionBinding::Param::TYPE_ENUM:
-        return "LUA_TSTRING";
+        o << "(lua_type(state, " << index << ") == LUA_TSTRING || ";
+        o << "lua_type(state, " << index << ") == LUA_TNIL)";
+        break;
     case FunctionBinding::Param::TYPE_OBJECT:
-        return "LUA_TUSERDATA";
+        o << "(lua_type(state, " << index << ") == LUA_TUSERDATA || ";
+        o << "lua_type(state, " << index << ") == LUA_TNIL)";
+        break;
     case FunctionBinding::Param::TYPE_CONSTRUCTOR:
     case FunctionBinding::Param::TYPE_DESTRUCTOR:
     case FunctionBinding::Param::TYPE_VOID:
     case FunctionBinding::Param::TYPE_VARARGS:
     default:
-        return "LUA_TNONE";
+        o << "lua_type(state, " << index << ") == LUA_TNONE";
     }
 }
 
@@ -591,19 +609,17 @@ static inline void outputBindingInvocation(ostream& o, const FunctionBinding& b,
         // For functions that return objects, create the appropriate user data in Lua.
         if (b.returnParam.type == FunctionBinding::Param::TYPE_CONSTRUCTOR || b.returnParam.type == FunctionBinding::Param::TYPE_OBJECT)
         {
-            indent(o, indentLevel);
-            o << LUA_OBJECT << "* object = (" << LUA_OBJECT << "*)lua_newuserdata(state, sizeof(" << LUA_OBJECT << "));\n";
             indent(o, indentLevel);
             switch (b.returnParam.kind)
             {
             case FunctionBinding::Param::KIND_POINTER:
-                o << "object->instance = (void*)";
+                o << "void* returnPtr = (void*)";
                 break;
             case FunctionBinding::Param::KIND_VALUE:
-                o << "object->instance = (void*)new " << b.returnParam << "(";
+                o << "void* returnPtr = (void*)new " << b.returnParam << "(";
                 break;
             case FunctionBinding::Param::KIND_REFERENCE:
-                o << "object->instance = (void*)&(";
+                o << "void* returnPtr = (void*)&(";
                 break;
             default:
                 GP_ERROR("Invalid return value kind '%d'.", b.returnParam.kind);
@@ -756,7 +772,7 @@ static inline void outputGetParam(ostream& o, const FunctionBinding::Param& p, i
             o << "(double)luaL_checknumber(state, " << paramIndex << ");\n";
         break;
     case FunctionBinding::Param::TYPE_STRING:
-        o << "luaL_checkstring(state, " << paramIndex << ");\n";
+        o << "ScriptController::getInstance()->getString(" << paramIndex << ", " << ((p.info == "string") ? "true" : "false") << ");\n";
         break;
     case FunctionBinding::Param::TYPE_ENUM:
         o << "(" << p << ")lua_enumFromString_" << Generator::getInstance()->getUniqueNameFromRef(p.info) << "(luaL_checkstring(state, " << paramIndex << "));\n";
@@ -766,28 +782,15 @@ static inline void outputGetParam(ostream& o, const FunctionBinding::Param& p, i
         o << "(" << p.info << ")luaL_checkunsigned(state, " << paramIndex << ");\n";
         break;
     case FunctionBinding::Param::TYPE_OBJECT:
-        indent(o, indentLevel);
-        o << "void* userdata" << paramIndex << " = ScriptController::getInstance()->getObjectPointer(" << paramIndex;
-        o << ", \"" << Generator::getInstance()->getUniqueNameFromRef(p.info) << "\");\n";
-        indent(o, indentLevel);
-        o << "if (!userdata" << paramIndex << ")\n";
-        indent(o, indentLevel);
-        o << "{\n";
-        indent(o, indentLevel + 1);
-        o << "lua_pushstring(state, \"Failed to retrieve a valid object pointer of type \'";
-        o << Generator::getInstance()->getIdentifier(p.info) << "\' for parameter " << paramIndex << ".\");\n";
-        indent(o, indentLevel + 1);
-        o << "lua_error(state);\n";
-        indent(o, indentLevel);
-        o << "}\n";
         indent(o, indentLevel);
         o << p;
         if (p.kind != FunctionBinding::Param::KIND_POINTER)
             o << "*";
-        o << " param" << i + 1 << " = (" << p;
-        if (p.kind != FunctionBinding::Param::KIND_POINTER)
-            o << "*";
-        o << ")((" << LUA_OBJECT  << "*)userdata" << paramIndex << ")->instance;\n";
+        o << " param" << i + 1 << " = ";
+        o << "ScriptController::getInstance()->getObjectPointer<";
+        o << Generator::getInstance()->getIdentifier(p.info) << ">(" << paramIndex;
+        o << ", \"" << Generator::getInstance()->getUniqueNameFromRef(p.info) << "\", ";
+        o << ((p.kind != FunctionBinding::Param::KIND_POINTER) ? "true" : "false") << ");\n";
         break;
     case FunctionBinding::Param::TYPE_CONSTRUCTOR:
     case FunctionBinding::Param::TYPE_DESTRUCTOR:
@@ -820,17 +823,10 @@ static inline void outputMatchedBinding(ostream& o, const FunctionBinding& b, un
         o << "if (";
         for (unsigned int i = 0, count = paramCount; i < count; i++)
         {
-            string typeStr = "";
             if (isNormalMember && i == 0)
-                typeStr = getLuaTypeString();
+                outputLuaTypeCheck(o, i + 1);
             else
-                typeStr = getLuaTypeString(b.paramTypes[(isNormalMember ? i - 1 : i)]);
-            
-            // If the type is a basic-type pointer, then allow tables or light-userdata from Lua.
-            if (typeStr == "LUA_TTABLE")
-                o << "(lua_type(state, " << i + 1 << ") == LUA_TTABLE || lua_type(state, " << i + 1 << ") == LUA_TLIGHTUSERDATA)";
-            else
-                o << "lua_type(state, " << i + 1 << ") == " << typeStr;
+                outputLuaTypeCheck(o, i + 1, b.paramTypes[(isNormalMember ? i - 1 : i)]);
 
             if (i == count - 1)
                 o << ")\n";
@@ -908,16 +904,34 @@ static inline void outputReturnValue(ostream& o, const FunctionBinding& b, int i
         break;
     case FunctionBinding::Param::TYPE_OBJECT:
     case FunctionBinding::Param::TYPE_CONSTRUCTOR:
+        o << "if (returnPtr)\n";
+        indent(o, indentLevel);
+        o << "{\n";
+        indent(o, indentLevel + 1);
+        o << LUA_OBJECT << "* object = (" << LUA_OBJECT << "*)lua_newuserdata(state, sizeof(" << LUA_OBJECT << "));\n";
+        indent(o, indentLevel + 1);
+        o << "object->instance = returnPtr;\n";
+        indent(o, indentLevel + 1);
         o << "object->owns = ";
         if (b.own || (b.returnParam.type == FunctionBinding::Param::TYPE_OBJECT && b.returnParam.kind == FunctionBinding::Param::KIND_VALUE))
             o << "true";
         else
             o << "false";
         o << ";\n";
-        indent(o, indentLevel);
+        indent(o, indentLevel + 1);
         o << "luaL_getmetatable(state, \"" << Generator::getInstance()->getUniqueNameFromRef(b.returnParam.info) << "\");\n";
-        indent(o, indentLevel);
+        indent(o, indentLevel + 1);
         o << "lua_setmetatable(state, -2);\n";
+        indent(o, indentLevel);
+        o << "}\n";
+        indent(o, indentLevel);
+        o << "else\n";
+        indent(o, indentLevel);
+        o << "{\n";
+        indent(o, indentLevel + 1);
+        o << "lua_pushnil(state);\n";
+        indent(o, indentLevel);
+        o << "}\n";
         break;
     case FunctionBinding::Param::TYPE_DESTRUCTOR:
     case FunctionBinding::Param::TYPE_VOID:

+ 135 - 55
gameplay-luagen/src/Generator.cpp

@@ -2,7 +2,7 @@
 
 Generator* Generator::__instance = NULL;
 
-set<string> __unrecognizedTypes;
+set<string> __warnings;
 
 // Warning flags.
 static bool __printTemplateWarning = false;
@@ -15,6 +15,7 @@ static string stripTypeQualifiers(const string& typeStr, FunctionBinding::Param:
 static inline bool isWantedFileNormal(const string& s);
 static inline bool isNamespaceFile(const string& s);
 static bool getFileList(string directory, vector<string>& files, bool (*isWantedFile)(const string& s));
+static bool isReservedKeyword(string name);
 
 Generator* Generator::getInstance()
 {
@@ -225,13 +226,13 @@ void Generator::run(string inDir, string outDir)
     // Generate the script bindings.
     generateBindings();
 
-    // Print out all unrecognized parameter types.
-    if (__unrecognizedTypes.size() > 0)
+    // Print out all warnings (unsupported types, function name-Lua keyword clashes, etc.)
+    if (__warnings.size() > 0)
     {
-        cout << "\nUnrecognized Types:\n";
-        for (set<string>::iterator iter = __unrecognizedTypes.begin(); iter!= __unrecognizedTypes.end(); iter++)
+        cout << "\nWarnings:\n";
+        for (set<string>::iterator iter = __warnings.begin(); iter!= __warnings.end(); iter++)
         {
-            cout << *iter << "\n";
+            GP_WARN("%s", iter->c_str());
         }
     }
 
@@ -285,19 +286,26 @@ void Generator::getFunctions(XMLElement* fileNode)
                     FunctionBinding b;
                     b.type = FunctionBinding::GLOBAL_FUNCTION;
                     b.name = getName(e);
-                
-                    // Ignore operators.
-                    if (b.name.find("operator") != 0)
+
+                    if (!isReservedKeyword(b.name))
                     {
-                        b.returnParam = getParam(e);
+                        // Ignore operators.
+                        if (b.name.find("operator") != 0)
+                        {
+                            b.returnParam = getParam(e);
 
-                        getParams(e, b);
-                        getCreateFlag(e, b);
-                        _functions[b.getFunctionName()].push_back(b);
+                            getParams(e, b);
+                            getCreateFlag(e, b);
+                            _functions[b.getFunctionName()].push_back(b);
+                        }
+                        else
+                        {
+                            __printOperatorWarning = true;
+                        }
                     }
                     else
                     {
-                        __printOperatorWarning = true;
+                        __warnings.insert(string("Function name '") + b.name + string("' is a reserved Lua keyword; binding '") + b.getFunctionName() + string("' was not generated."));
                     }
                 }
                 e = e->NextSiblingElement("memberdef");
@@ -319,8 +327,15 @@ void Generator::getFunctions(XMLElement* fileNode)
                         b.type = FunctionBinding::GLOBAL_VARIABLE;
 
                     b.name = getName(e);
-                    b.returnParam = getParam(e, true);
-                    _functions[b.getFunctionName()].push_back(b);
+                    if (!isReservedKeyword(b.name))
+                    {
+                        b.returnParam = getParam(e, true);
+                        _functions[b.getFunctionName()].push_back(b);
+                    }
+                    else
+                    {
+                        __warnings.insert(string("Function name '") + b.name + string("' is a reserved Lua keyword; binding '") + b.getFunctionName() + string("' was not generated."));
+                    }
                 }
                 e = e->NextSiblingElement("memberdef");
             }
@@ -423,11 +438,18 @@ void Generator::getClass(XMLElement* classNode, const string& name)
                     b.type = FunctionBinding::STATIC_FUNCTION;
 
                     b.name = getName(e);
-                    b.returnParam = getParam(e, false, b.classname);
+                    if (!isReservedKeyword(b.name))
+                    {
+                        b.returnParam = getParam(e, false, b.classname);
                         
-                    getParams(e, b);
-                    getCreateFlag(e, b);
-                    classBinding.bindings[b.getFunctionName()].push_back(b);
+                        getParams(e, b);
+                        getCreateFlag(e, b);
+                        classBinding.bindings[b.getFunctionName()].push_back(b);
+                    }
+                    else
+                    {
+                        __warnings.insert(string("Function name '") + b.name + string("' is a reserved Lua keyword; binding '") + b.getFunctionName() + string("' was not generated."));
+                    }
                 }
                 e = e->NextSiblingElement("memberdef");
             }
@@ -451,24 +473,31 @@ void Generator::getClass(XMLElement* classNode, const string& name)
                     b.type = FunctionBinding::MEMBER_FUNCTION;
 
                     b.name = getName(e);
-                
-                    // Ignore operators.
-                    if (b.name.find("operator") != 0)
+
+                    if (!isReservedKeyword(b.name))
                     {
-                        b.returnParam = getParam(e, false, b.classname);
-                        if (b.returnParam.type == FunctionBinding::Param::TYPE_CONSTRUCTOR)
+                        // Ignore operators.
+                        if (b.name.find("operator") != 0)
                         {
-                            b.returnParam.info = refId;
-                            b.own = true;
-                        }
+                            b.returnParam = getParam(e, false, b.classname);
+                            if (b.returnParam.type == FunctionBinding::Param::TYPE_CONSTRUCTOR)
+                            {
+                                b.returnParam.info = refId;
+                                b.own = true;
+                            }
 
-                        getParams(e, b);
-                        getCreateFlag(e, b);
-                        classBinding.bindings[b.getFunctionName()].push_back(b);
+                            getParams(e, b);
+                            getCreateFlag(e, b);
+                            classBinding.bindings[b.getFunctionName()].push_back(b);
+                        }
+                        else
+                        {
+                            __printOperatorWarning = true;
+                        }
                     }
                     else
                     {
-                        __printOperatorWarning = true;
+                        __warnings.insert(string("Function name '") + b.name + string("' is a reserved Lua keyword; binding '") + b.getFunctionName() + string("' was not generated."));
                     }
                 }
                 e = e->NextSiblingElement("memberdef");
@@ -489,8 +518,15 @@ void Generator::getClass(XMLElement* classNode, const string& name)
                         b.type = FunctionBinding::STATIC_VARIABLE;
 
                     b.name = getName(e);
-                    b.returnParam = getParam(e, true, b.classname);
-                    classBinding.bindings[b.getFunctionName()].push_back(b);
+                    if (!isReservedKeyword(b.name))
+                    {
+                        b.returnParam = getParam(e, true, b.classname);
+                        classBinding.bindings[b.getFunctionName()].push_back(b);
+                    }
+                    else
+                    {
+                        __warnings.insert(string("Function name '") + b.name + string("' is a reserved Lua keyword; binding '") + b.getFunctionName() + string("' was not generated."));
+                    }
                 }
                 e = e->NextSiblingElement("memberdef");
             }
@@ -514,8 +550,15 @@ void Generator::getClass(XMLElement* classNode, const string& name)
                         b.type = FunctionBinding::MEMBER_VARIABLE;
 
                     b.name = getName(e);
-                    b.returnParam = getParam(e, true, b.classname);
-                    classBinding.bindings[b.getFunctionName()].push_back(b);
+                    if (!isReservedKeyword(b.name))
+                    {
+                        b.returnParam = getParam(e, true, b.classname);
+                        classBinding.bindings[b.getFunctionName()].push_back(b);
+                    }
+                    else
+                    {
+                        __warnings.insert(string("Function name '") + b.name + string("' is a reserved Lua keyword; binding '") + b.getFunctionName() + string("' was not generated."));
+                    }
                 }
                 e = e->NextSiblingElement("memberdef");
             }
@@ -550,23 +593,26 @@ void Generator::getClass(XMLElement* classNode, const string& name)
 
                     b.name = getName(e);
                 
-                    // Ignore operators.
-                    if (b.name.find("operator") != 0)
+                    if (!isReservedKeyword(b.name))
                     {
-                        b.returnParam = getParam(e, false, b.classname);
-                        if (b.returnParam.type == FunctionBinding::Param::TYPE_CONSTRUCTOR)
+                        // Ignore operators.
+                        if (b.name.find("operator") != 0)
                         {
-                            b.returnParam.info = refId;
-                            b.own = true;
-                        }
+                            b.returnParam = getParam(e, false, b.classname);
+                            if (b.returnParam.type == FunctionBinding::Param::TYPE_CONSTRUCTOR)
+                            {
+                                b.returnParam.info = refId;
+                                b.own = true;
+                            }
 
-                        getParams(e, b);
-                        getCreateFlag(e, b);
-                        classBinding.hidden[b.getFunctionName()].push_back(b);
-                    }
-                    else
-                    {
-                        __printOperatorWarning = true;
+                            getParams(e, b);
+                            getCreateFlag(e, b);
+                            classBinding.hidden[b.getFunctionName()].push_back(b);
+                        }
+                        else
+                        {
+                            __printOperatorWarning = true;
+                        }
                     }
                 }
                 e = e->NextSiblingElement("memberdef");
@@ -593,11 +639,14 @@ void Generator::getClass(XMLElement* classNode, const string& name)
                     b.type = FunctionBinding::STATIC_FUNCTION;
 
                     b.name = getName(e);
-                    b.returnParam = getParam(e, false, b.classname);
+                    if (!isReservedKeyword(b.name))
+                    {
+                        b.returnParam = getParam(e, false, b.classname);
                         
-                    getParams(e, b);
-                    getCreateFlag(e, b);
-                    classBinding.hidden[b.getFunctionName()].push_back(b);
+                        getParams(e, b);
+                        getCreateFlag(e, b);
+                        classBinding.hidden[b.getFunctionName()].push_back(b);
+                    }
                 }
                 e = e->NextSiblingElement("memberdef");
             }
@@ -1148,7 +1197,7 @@ void Generator::resolveType(FunctionBinding::Param* param, string functionName)
                 }
                 else
                 {
-                    __unrecognizedTypes.insert(functionName + string(" -- ") + (name.size() > 0 ? name : param->info));
+                    __warnings.insert(string("Unrecognized C++ type: ") + functionName + string(" -- ") + (name.size() > 0 ? name : param->info));
                 }
             }
         }
@@ -1623,4 +1672,35 @@ static bool getFileList(string directory, vector<string>& files, bool (*isWanted
 #endif
 }
 
+bool isReservedKeyword(string name)
+{
+    static set<string> keywords;
+    if (keywords.size() == 0)
+    {
+        keywords.insert("and");
+        keywords.insert("break");
+        keywords.insert("do");
+        keywords.insert("else");
+        keywords.insert("elseif");
+        keywords.insert("end");
+        keywords.insert("false");
+        keywords.insert("for");
+        keywords.insert("function");
+        keywords.insert("if");
+        keywords.insert("in");
+        keywords.insert("local");
+        keywords.insert("nil");
+        keywords.insert("not");
+        keywords.insert("or");
+        keywords.insert("repeat");
+        keywords.insert("return");
+        keywords.insert("then");
+        keywords.insert("true");
+        keywords.insert("until");
+        keywords.insert("while");
+    };
+
+    return keywords.find(name) != keywords.end();
+}
+
 // ----------------------------------------------------------------------------

+ 2 - 0
gameplay/gameplay.vcxproj

@@ -86,6 +86,7 @@
     <ClCompile Include="src\lua\lua_FrameBuffer.cpp" />
     <ClCompile Include="src\lua\lua_Frustum.cpp" />
     <ClCompile Include="src\lua\lua_Game.cpp" />
+    <ClCompile Include="src\lua\lua_Gamepad.cpp" />
     <ClCompile Include="src\lua\lua_Global.cpp" />
     <ClCompile Include="src\lua\lua_Image.cpp" />
     <ClCompile Include="src\lua\lua_Joint.cpp" />
@@ -290,6 +291,7 @@
     <ClInclude Include="src\lua\lua_FrameBuffer.h" />
     <ClInclude Include="src\lua\lua_Frustum.h" />
     <ClInclude Include="src\lua\lua_Game.h" />
+    <ClInclude Include="src\lua\lua_Gamepad.h" />
     <ClInclude Include="src\lua\lua_Global.h" />
     <ClInclude Include="src\lua\lua_Image.h" />
     <ClInclude Include="src\lua\lua_Joint.h" />

+ 69 - 60
gameplay/gameplay.vcxproj.filters

@@ -618,6 +618,12 @@
     <ClCompile Include="src\lua\lua_PhysicsControllerHitFilter.cpp">
       <Filter>lua</Filter>
     </ClCompile>
+    <ClCompile Include="src\lua\lua_Gamepad.cpp">
+      <Filter>lua</Filter>
+    </ClCompile>
+    <ClCompile Include="src\Gamepad.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="src\Animation.h">
@@ -1232,68 +1238,14 @@
     <ClInclude Include="src\lua\lua_PhysicsControllerHitFilter.h">
       <Filter>lua</Filter>
     </ClInclude>
+    <ClInclude Include="src\lua\lua_Gamepad.h">
+      <Filter>lua</Filter>
+    </ClInclude>
+    <ClInclude Include="src\Gamepad.h">
+      <Filter>src</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
-    <None Include="res\shaders\bumped-specular.vsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\colored.fsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\colored.vsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\colored-specular.fsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\colored-specular.vsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\diffuse.fsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\diffuse.vsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\diffuse-specular.fsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\diffuse-specular.vsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\parallax.fsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\parallax.vsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\parallax-specular.fsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\parallax-specular.vsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\solid.fsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\solid.vsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\textured.fsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\textured.vsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\bumped.fsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\bumped.vsh">
-      <Filter>res\shaders</Filter>
-    </None>
-    <None Include="res\shaders\bumped-specular.fsh">
-      <Filter>res\shaders</Filter>
-    </None>
     <None Include="src\gameplay-main-macosx.mm">
       <Filter>src</Filter>
     </None>
@@ -1339,6 +1291,63 @@
     <None Include="src\ScriptController.inl">
       <Filter>src</Filter>
     </None>
+    <None Include="res\shaders\lib\attributes-skinning.vert">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\lib\attributes.vert">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\colored-unlit.frag">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\colored-unlit.vert">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\colored.frag">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\colored.vert">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\lib\lighting-directional.frag">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\lib\lighting-directional.vert">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\lib\lighting-point.frag">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\lib\lighting-point.vert">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\lib\lighting-spot.frag">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\lib\lighting-spot.vert">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\lib\lighting.frag">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\textured-bumped.frag">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\textured-bumped.vert">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\textured-unlit.frag">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\textured-unlit.vert">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\textured.frag">
+      <Filter>res\shaders</Filter>
+    </None>
+    <None Include="res\shaders\textured.vert">
+      <Filter>res\shaders</Filter>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <None Include="src\PhysicsFixedConstraint.inl">

+ 2 - 2
gameplay/src/Container.cpp

@@ -399,7 +399,7 @@ void Container::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needs
 
     spriteBatch->begin();
     Control::drawBorder(spriteBatch, clip);
-    spriteBatch->end();
+    spriteBatch->finish();
 
     std::vector<Control*>::const_iterator it;
     Rectangle boundsUnion = Rectangle::empty();
@@ -485,7 +485,7 @@ void Container::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needs
             spriteBatch->draw(bounds.x, bounds.y, bounds.width, bounds.height, rightUVs.u1, rightUVs.v1, rightUVs.u2, rightUVs.v2, rightColor, clipRegion);
         }
 
-        spriteBatch->end();
+        spriteBatch->finish();
 
         if (_scrollingVelocity.isZero())
         {

+ 1 - 1
gameplay/src/Control.cpp

@@ -979,7 +979,7 @@ void Control::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needsCl
     spriteBatch->begin();
     drawBorder(spriteBatch, clip);
     drawImages(spriteBatch, clip);
-    spriteBatch->end();
+    spriteBatch->finish();
 
     drawText(clip);
     _dirty = false;

+ 2 - 2
gameplay/src/Font.cpp

@@ -733,10 +733,10 @@ void Font::drawText(const char* text, const Rectangle& area, const Vector4& colo
     }
 }
 
-void Font::end()
+void Font::finish()
 {
     GP_ASSERT(_batch);
-    _batch->end();
+    _batch->finish();
 }
 
 void Font::measureText(const char* text, unsigned int size, unsigned int* width, unsigned int* height)

+ 2 - 2
gameplay/src/Font.h

@@ -160,9 +160,9 @@ public:
     void begin();
 
     /**
-     * Ends text batching for this font and renders all drawn text.
+     * Finishes text batching for this font and renders all drawn text.
      */
-    void end();
+    void finish();
 
     /**
      * Draws the specified text in a solid color, with a scaling factor.

+ 1 - 1
gameplay/src/Form.cpp

@@ -566,7 +566,7 @@ void Form::draw()
         }
         _spriteBatch->begin();
         _spriteBatch->draw(_bounds.x, _bounds.y, 0, _bounds.width, _bounds.height, 0, _v1, _u2, 0, Vector4::one());
-        _spriteBatch->end();
+        _spriteBatch->finish();
     }
 }
 

+ 1 - 1
gameplay/src/Joystick.cpp

@@ -242,7 +242,7 @@ void Joystick::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
             spriteBatch->draw(region.x, region.y, _region.width, _region.height, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color);
         }
     }
-    spriteBatch->end();
+    spriteBatch->finish();
 }
 
 const char* Joystick::getType() const

+ 1 - 1
gameplay/src/Label.cpp

@@ -102,7 +102,7 @@ void Label::drawText(const Rectangle& clip)
     {
         _font->begin();
         _font->drawText(_text.c_str(), _textBounds, _textColor, getFontSize(_state), getTextAlignment(_state), true, getTextRightToLeft(_state), &_viewportClipBounds);
-        _font->end();
+        _font->finish();
     }
 
     _dirty = false;

+ 1 - 1
gameplay/src/MeshBatch.cpp

@@ -164,7 +164,7 @@ void MeshBatch::begin()
     _indicesPtr = _indices;
 }
 
-void MeshBatch::end()
+void MeshBatch::finish()
 {
 }
 

+ 2 - 2
gameplay/src/MeshBatch.h

@@ -94,7 +94,7 @@ public:
      * Begins batching.
      *
      * This method should be called before calling add() to add primitives to the batch.
-     * After all primitives have been added to the batch, call the end() method to
+     * After all primitives have been added to the batch, call the finish() method to
      * complete the batch.
      *
      * Calling this method will clear any primitives currently in the batch and set the
@@ -105,7 +105,7 @@ public:
     /**
      * Indicates that batching is complete and prepares the batch for drawing.
      */
-    void end();
+    void finish();
 
     /**
      * Draws the primitives currently in batch.

+ 1 - 1
gameplay/src/ParticleEmitter.cpp

@@ -961,7 +961,7 @@ void ParticleEmitter::draw()
         }
 
         // Render.
-        _spriteBatch->end();
+        _spriteBatch->finish();
     }
 }
 

+ 1 - 1
gameplay/src/PhysicsController.cpp

@@ -1419,7 +1419,7 @@ void PhysicsController::DebugDrawer::begin(const Matrix& viewProjection)
 void PhysicsController::DebugDrawer::end()
 {
     GP_ASSERT(_meshBatch && _meshBatch->getMaterial() && _meshBatch->getMaterial()->getParameter("u_viewProjectionMatrix"));
-    _meshBatch->end();
+    _meshBatch->finish();
     _meshBatch->getMaterial()->getParameter("u_viewProjectionMatrix")->setValue(_viewProjection);
     _meshBatch->draw();
 }

+ 1 - 1
gameplay/src/Scene.cpp

@@ -514,7 +514,7 @@ void Scene::drawDebug(unsigned int debugFlags)
         drawDebugNode(_debugBatch, node, debugFlags);
     }
 
-    _debugBatch->end();
+    _debugBatch->finish();
 
     if (_activeCamera)
     {

+ 45 - 0
gameplay/src/Scene.h

@@ -3,6 +3,7 @@
 
 #include "Node.h"
 #include "MeshBatch.h"
+#include "ScriptController.h"
 
 namespace gameplay
 {
@@ -192,6 +193,20 @@ public:
     template <class T, class C>
     void visit(T* instance, bool (T::*visitMethod)(Node*,C), C cookie);
 
+    /**
+     * Visits each node in the scene and calls the specified Lua function.
+     *
+     * Calling this method invokes the specified Lua function for each node
+     * in the scene hierarchy.
+     *
+     * The visitMethod parameter must be a string containing the name of a
+     * valid Lua function that has a boolean return type and accepts a 
+     * single parameter of type Node*.
+     *
+     * @param visitMethod The name of the Lua function to call for each node in the scene.
+     */
+    inline void visit(const char* visitMethod);
+
     /**
      * Draws debugging information (bounding volumes, etc.) for the scene.
      *
@@ -234,6 +249,11 @@ private:
     template <class T, class C>
     bool visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*,C), C cookie);
 
+    /**
+     * Visits the given node and all of its children recursively.
+     */
+    inline bool visitNode(Node* node, const char* visitMethod);
+
     std::string _id;
     Camera* _activeCamera;
     Node* _firstNode;
@@ -265,6 +285,15 @@ void Scene::visit(T* instance, bool (T::*visitMethod)(Node*,C), C cookie)
     }
 }
 
+inline void Scene::visit(const char* visitMethod)
+{
+    for (Node* node = getFirstNode(); node != NULL; node = node->getNextSibling())
+    {
+        if (!visitNode(node, visitMethod))
+            return;
+    }
+}
+
 template <class T>
 bool Scene::visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*))
 {
@@ -299,6 +328,22 @@ bool Scene::visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*,C),
     return true;
 }
 
+inline bool Scene::visitNode(Node* node, const char* visitMethod)
+{
+    // Invoke the visit method for this node.
+    if (!ScriptController::getInstance()->executeFunction<bool>(visitMethod, "<Node>", node))
+        return false;
+
+    // Recurse for all children.
+    for (Node* child = node->getFirstChild(); child != NULL; child = child->getNextSibling())
+    {
+        if (!ScriptController::getInstance()->executeFunction<bool>(visitMethod, "<Node>", child))
+            return false;
+    }
+
+    return true;
+}
+
 }
 
 #endif

+ 45 - 42
gameplay/src/ScriptController.cpp

@@ -40,16 +40,6 @@ ScriptController* ScriptController::__instance = NULL;
     } \
     return NULL
 
-static bool luaCheckBool(lua_State* state, int n)
-{
-    if (!lua_isboolean(state, n))
-    {
-        const char* msg = lua_pushfstring(state, "%s expected, got %s", lua_typename(state, LUA_TBOOLEAN), luaL_typename(state, n));
-        luaL_argerror(state, n, msg);
-        return false;
-    }
-    return (lua_toboolean(state, n) != 0);
-}
 
 ScriptController* ScriptController::getInstance()
 {
@@ -106,39 +96,17 @@ double* ScriptController::getDoublePointer(int index)
     GENERATE_LUA_GET_POINTER(double, (double)luaL_checknumber);
 }
 
-void* ScriptController::getObjectPointer(int index, const char* type)
+const char* ScriptController::getString(int index, bool isStdString)
 {
-    void* p = lua_touserdata(_lua, index);
-    if (p != NULL)
+    if (lua_type(_lua, index) == LUA_TSTRING)
+        return luaL_checkstring(_lua, index);
+    else if (lua_type(_lua, index) == LUA_TNIL && !isStdString)
+        return NULL;
+    else
     {
-        if (lua_getmetatable(_lua, index))
-        {
-            // Check if it matches the type's metatable.
-            luaL_getmetatable(_lua, type);
-            if (lua_rawequal(_lua, -1, -2))
-            {
-                lua_pop(_lua, 2);
-                return p;
-            }
-            lua_pop(_lua, 1);
-
-            // Check if it matches any of the derived types' metatables.
-            const std::vector<std::string>& types = _hierarchy[type];
-            for (unsigned int i = 0, count = types.size(); i < count; i++)
-            {
-                luaL_getmetatable(_lua, types[i].c_str());
-                if (lua_rawequal(_lua, -1, -2))
-                {
-                    lua_pop(_lua, 2);
-                    return p;
-                }
-                lua_pop(_lua, 1);
-            }
-            
-            lua_pop(_lua, 1);
-        }
+        GP_ERROR("Invalid string parameter (index = %d).", index);
+        return NULL;
     }
-    return NULL;
 }
 
 void ScriptController::loadScript(const char* path)
@@ -539,7 +507,7 @@ void ScriptController::update(long elapsedTime)
 {
     if (_callbacks[UPDATE])
     {
-        executeFunction<void>(_callbacks[UPDATE]->c_str(), "l", elapsedTime);
+        executeFunction<void>(_callbacks[UPDATE]->c_str(), "f", elapsedTime);
     }
 }
 
@@ -547,7 +515,7 @@ void ScriptController::render(long elapsedTime)
 {
     if (_callbacks[RENDER])
     {
-        executeFunction<void>(_callbacks[RENDER]->c_str(), "l", elapsedTime);
+        executeFunction<void>(_callbacks[RENDER]->c_str(), "f", elapsedTime);
     }
 }
 
@@ -598,6 +566,30 @@ void ScriptController::executeFunctionHelper(int resultCount, const char* func,
             case 'p':
                 lua_pushlightuserdata(_lua, va_arg(list, void*));
                 break;
+            // Object references/pointers (Lua userdata).
+            case '<':
+            {
+                std::string type = sig;
+                type = type.substr(0, type.find(">"));
+
+                // Skip past the closing '>' (the semi-colon here is intentional-do not remove).
+                while (*sig++ != '>');
+
+                void* ptr = va_arg(list, void*);
+                if (ptr == NULL)
+                {
+                    lua_pushnil(_lua);
+                }
+                else
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(_lua, sizeof(ScriptController::LuaObject));
+                    object->instance = ptr;
+                    object->owns = false;
+                    luaL_getmetatable(_lua, type.c_str());
+                    lua_setmetatable(_lua, -2);
+                }
+                break;
+            }
             default:
                 GP_ERROR("Invalid argument type '%d'.", *(sig - 1));
             }
@@ -618,4 +610,15 @@ void ScriptController::registerCallback(ScriptCallback callback, std::string fun
     _callbacks[callback] = new std::string(function);
 }
 
+bool ScriptController::luaCheckBool(lua_State* state, int n)
+{
+    if (!lua_isboolean(state, n))
+    {
+        const char* msg = lua_pushfstring(state, "%s expected, got %s", lua_typename(state, LUA_TBOOLEAN), luaL_typename(state, n));
+        luaL_argerror(state, n, msg);
+        return false;
+    }
+    return (lua_toboolean(state, n) != 0);
+}
+
 }

+ 25 - 2
gameplay/src/ScriptController.h

@@ -45,6 +45,7 @@ public:
      *      - 'uh' - unsigned short
      *      - 's' - string
      *      - 'p' - pointer
+     *      - '<object-type>' - a pointer to an object of the given type (where the type is enclosed by angle brackets).
      * @return The return value of the executed Lua function.
      * @script{ignore}
      */
@@ -94,6 +95,7 @@ public:
      *      - 'uh' - unsigned short
      *      - 's' - string
      *      - 'p' - pointer
+     *      - '<object-type>' - a pointer to an object of the given type (where the type is enclosed by angle brackets).
      * @return The return value of the executed Lua function.
      * @script{ignore}
      */
@@ -198,11 +200,22 @@ public:
      * 
      * @param type The type of object pointer to retrieve.
      * @param index The stack index.
+     * @param nonNull Whether the pointer must be non-null (e.g. if the parameter we 
+     *      are retreiving is actually a reference or by-value parameter).
      * @return The object pointer or <code>NULL</code> if the data at the stack index
      *      is not an object or if the object is not derived from the given type.
      * @script{ignore}
      */
-    void* getObjectPointer(int index, const char* type);
+    template<typename T> T* getObjectPointer(int index, const char* type, bool nonNull);
+
+    /**
+     * Gets a string for the given stack index.
+     * 
+     * @param index The stack index.
+     * @return The string or <code>NULL</code>.
+     * @script{ignore}
+     */
+    const char* getString(int index, bool isStdString);
 
     /**
      * Gets the global boolean variable with the given name.
@@ -320,7 +333,7 @@ public:
      * @return The global pointer variable.
      * @script{ignore}
      */
-    template<typename T>T* getPointer(const char* type, const char* name);
+    template<typename T>T* getObjectPointer(const char* type, const char* name);
 
     /**
      * Sets the global boolean variable with the given name.
@@ -590,6 +603,7 @@ private:
      *      - 'uh' - unsigned short
      *      - 's' - string
      *      - 'p' - pointer
+     *      - '<object-type>' - a pointer to an object of the given type (where the type is enclosed by angle brackets).
      * @param list The variable argument list.
      */
     void executeFunctionHelper(int resultCount, const char* func, const char* args, va_list& list);
@@ -602,6 +616,15 @@ private:
      */
     void registerCallback(ScriptCallback callback, std::string function);
 
+    /**
+     * Checks that the parameter at the given stack position is a boolean and returns it.
+     * 
+     * @param state The Lua state.
+     * @param n The stack index.
+     * @return The boolean (if successful; otherwise it logs an error).
+     */
+    static bool luaCheckBool(lua_State* state, int n);
+
     lua_State* _lua;
     unsigned int _returnCount;
     std::map<std::string, std::vector<std::string> > _hierarchy;

+ 62 - 9
gameplay/src/ScriptController.inl

@@ -28,14 +28,7 @@ template<> void ScriptController::executeFunction<void>(const char* func, const
 
 template<> bool ScriptController::executeFunction<bool>(const char* func, const char* args, ...)
 {
-    va_list list;
-    va_start(list, args);
-    executeFunctionHelper(1, func, args, list);
-
-    bool value = (luaL_checkint(_lua, -1) != 0);
-    lua_pop(_lua, -1);
-    va_end(list);
-    return value;
+    SCRIPT_EXECUTE_FUNCTION_PARAM(bool, luaCheckBool);
 }
 
 template<> char ScriptController::executeFunction<char>(const char* func, const char* args, ...)
@@ -105,7 +98,67 @@ template<typename T> T* ScriptController::executeFunction(const Type& type, cons
     return value;
 }
 
-template<typename T>T* ScriptController::getPointer(const char* type, const char* name)
+template<typename T>T* ScriptController::getObjectPointer(int index, const char* type, bool nonNull)
+{
+    if (lua_type(_lua, index) == LUA_TNIL)
+    {
+        if (nonNull)
+        {
+            GP_ERROR("Attempting to pass NULL for required non-NULL parameter at index %d (likely a reference or by-value parameter).", index);
+        }
+
+        return NULL;
+    }
+
+    void* p = lua_touserdata(_lua, index);
+    if (p != NULL)
+    {
+        if (lua_getmetatable(_lua, index))
+        {
+            // Check if it matches the type's metatable.
+            luaL_getmetatable(_lua, type);
+            if (lua_rawequal(_lua, -1, -2))
+            {
+                lua_pop(_lua, 2);
+                T* ptr = (T*)((ScriptController::LuaObject*)p)->instance;
+                if (ptr == NULL && nonNull)
+                {
+                    GP_ERROR("Attempting to pass NULL for required non-NULL parameter at index %d (likely a reference or by-value parameter).", index);
+                }
+                return ptr;
+            }
+            lua_pop(_lua, 1);
+
+            // Check if it matches any of the derived types' metatables.
+            const std::vector<std::string>& types = _hierarchy[type];
+            for (unsigned int i = 0, count = types.size(); i < count; i++)
+            {
+                luaL_getmetatable(_lua, types[i].c_str());
+                if (lua_rawequal(_lua, -1, -2))
+                {
+                    lua_pop(_lua, 2);
+                    T* ptr = (T*)((ScriptController::LuaObject*)p)->instance;
+                    if (ptr == NULL && nonNull)
+                    {
+                        GP_ERROR("Attempting to pass NULL for required non-NULL parameter at index %d (likely a reference or by-value parameter).", index);
+                    }
+                    return ptr;
+                }
+                lua_pop(_lua, 1);
+            }
+            
+            lua_pop(_lua, 1);
+        }
+    }
+
+    if (nonNull)
+    {
+        GP_ERROR("Failed to retrieve a valid object pointer of type '%s' for parameter %d.", type, index);
+    }
+    return NULL;
+}
+
+template<typename T>T* ScriptController::getObjectPointer(const char* type, const char* name)
 {
     lua_getglobal(_lua, name);
     void* userdata = luaL_checkudata(_lua, -1, type);

+ 2 - 2
gameplay/src/SpriteBatch.cpp

@@ -383,10 +383,10 @@ void SpriteBatch::draw(float x, float y, float z, float width, float height, flo
     _batch->add(v, 4, indices, 4);
 }
 
-void SpriteBatch::end()
+void SpriteBatch::finish()
 {
     // Finish and draw the batch
-    _batch->end();
+    _batch->finish();
     _batch->draw();
 }
 

+ 3 - 3
gameplay/src/SpriteBatch.h

@@ -90,7 +90,7 @@ public:
      * Begins drawing sprites.
      *
      * This method must be called before drawing any sprites and it must eventually be
-     * followed by a call to end().
+     * followed by a call to finish().
      */
     void begin();
 
@@ -236,12 +236,12 @@ public:
     void draw(float x, float y, float z, float width, float height, float u1, float v1, float u2, float v2, const Vector4& color, bool positionIsCenter = false);
 
     /**
-     * Ends sprite drawing.
+     * Finishes sprite drawing.
      *
      * This method flushes the batch and commits rendering of all sprites that were
      * drawn since the last call to begin().
      */
-    void end();
+    void finish();
 
     /**
      * Returns the StateBlock for the SpriteBatch.

+ 5 - 5
gameplay/src/lua/lua_AbsoluteLayout.cpp

@@ -42,7 +42,7 @@ int lua_AbsoluteLayout__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "AbsoluteLayout");
                 luaL_argcheck(state, userdata != NULL, 1, "'AbsoluteLayout' expected.");
@@ -82,7 +82,7 @@ int lua_AbsoluteLayout_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AbsoluteLayout* instance = getInstance(state);
                 instance->addRef();
@@ -116,7 +116,7 @@ int lua_AbsoluteLayout_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AbsoluteLayout* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -153,7 +153,7 @@ int lua_AbsoluteLayout_getType(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AbsoluteLayout* instance = getInstance(state);
                 Layout::Type result = instance->getType();
@@ -190,7 +190,7 @@ int lua_AbsoluteLayout_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AbsoluteLayout* instance = getInstance(state);
                 instance->release();

+ 85 - 59
gameplay/src/lua/lua_Animation.cpp

@@ -51,7 +51,7 @@ int lua_Animation__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Animation");
                 luaL_argcheck(state, userdata != NULL, 1, "'Animation' expected.");
@@ -91,7 +91,7 @@ int lua_Animation_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Animation* instance = getInstance(state);
                 instance->addRef();
@@ -125,13 +125,13 @@ int lua_Animation_createClip(lua_State* state)
     {
         case 4:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 lua_type(state, 4) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
                 unsigned long param2 = (unsigned long)luaL_checkunsigned(state, 3);
@@ -140,11 +140,19 @@ int lua_Animation_createClip(lua_State* state)
                 unsigned long param3 = (unsigned long)luaL_checkunsigned(state, 4);
 
                 Animation* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->createClip(param1, param2, param3);
-                object->owns = false;
-                luaL_getmetatable(state, "AnimationClip");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->createClip(param1, param2, param3);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "AnimationClip");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -175,11 +183,11 @@ int lua_Animation_createClips(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Animation* instance = getInstance(state);
                 instance->createClips(param1);
@@ -213,14 +221,22 @@ int lua_Animation_getClip(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Animation* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getClip();
-                object->owns = false;
-                luaL_getmetatable(state, "AnimationClip");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getClip();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "AnimationClip");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -233,33 +249,49 @@ int lua_Animation_getClip(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Animation* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getClip(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "AnimationClip");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getClip(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "AnimationClip");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
                 unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
 
                 Animation* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getClip(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "AnimationClip");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getClip(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "AnimationClip");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -290,7 +322,7 @@ int lua_Animation_getClipCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Animation* instance = getInstance(state);
                 unsigned int result = instance->getClipCount();
@@ -327,7 +359,7 @@ int lua_Animation_getDuration(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Animation* instance = getInstance(state);
                 unsigned long result = instance->getDuration();
@@ -364,7 +396,7 @@ int lua_Animation_getId(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Animation* instance = getInstance(state);
                 const char* result = instance->getId();
@@ -401,7 +433,7 @@ int lua_Animation_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Animation* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -438,7 +470,7 @@ int lua_Animation_pause(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Animation* instance = getInstance(state);
                 instance->pause();
@@ -454,11 +486,11 @@ int lua_Animation_pause(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Animation* instance = getInstance(state);
                 instance->pause(param1);
@@ -492,7 +524,7 @@ int lua_Animation_play(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Animation* instance = getInstance(state);
                 instance->play();
@@ -508,11 +540,11 @@ int lua_Animation_play(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Animation* instance = getInstance(state);
                 instance->play(param1);
@@ -546,7 +578,7 @@ int lua_Animation_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Animation* instance = getInstance(state);
                 instance->release();
@@ -580,7 +612,7 @@ int lua_Animation_stop(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Animation* instance = getInstance(state);
                 instance->stop();
@@ -596,11 +628,11 @@ int lua_Animation_stop(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Animation* instance = getInstance(state);
                 instance->stop(param1);
@@ -634,17 +666,11 @@ int lua_Animation_targets(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "AnimationTarget");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'AnimationTarget' for parameter 2.");
-                    lua_error(state);
-                }
-                AnimationTarget* param1 = (AnimationTarget*)((ScriptController::LuaObject*)userdata2)->instance;
+                AnimationTarget* param1 = ScriptController::getInstance()->getObjectPointer<AnimationTarget>(2, "AnimationTarget", false);
 
                 Animation* instance = getInstance(state);
                 bool result = instance->targets(param1);

+ 50 - 66
gameplay/src/lua/lua_AnimationClip.cpp

@@ -24,7 +24,7 @@ void luaRegister_AnimationClip()
         {"getDuration", lua_AnimationClip_getDuration},
         {"getElaspedTime", lua_AnimationClip_getElaspedTime},
         {"getEndTime", lua_AnimationClip_getEndTime},
-        {"getID", lua_AnimationClip_getID},
+        {"getId", lua_AnimationClip_getId},
         {"getRefCount", lua_AnimationClip_getRefCount},
         {"getRepeatCount", lua_AnimationClip_getRepeatCount},
         {"getSpeed", lua_AnimationClip_getSpeed},
@@ -67,7 +67,7 @@ int lua_AnimationClip__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "AnimationClip");
                 luaL_argcheck(state, userdata != NULL, 1, "'AnimationClip' expected.");
@@ -107,17 +107,11 @@ int lua_AnimationClip_addBeginListener(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "AnimationClipListener");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'AnimationClip::Listener' for parameter 2.");
-                    lua_error(state);
-                }
-                AnimationClip::Listener* param1 = (AnimationClip::Listener*)((ScriptController::LuaObject*)userdata2)->instance;
+                AnimationClip::Listener* param1 = ScriptController::getInstance()->getObjectPointer<AnimationClip::Listener>(2, "AnimationClipListener", false);
 
                 AnimationClip* instance = getInstance(state);
                 instance->addBeginListener(param1);
@@ -151,17 +145,11 @@ int lua_AnimationClip_addEndListener(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "AnimationClipListener");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'AnimationClip::Listener' for parameter 2.");
-                    lua_error(state);
-                }
-                AnimationClip::Listener* param1 = (AnimationClip::Listener*)((ScriptController::LuaObject*)userdata2)->instance;
+                AnimationClip::Listener* param1 = ScriptController::getInstance()->getObjectPointer<AnimationClip::Listener>(2, "AnimationClipListener", false);
 
                 AnimationClip* instance = getInstance(state);
                 instance->addEndListener(param1);
@@ -195,18 +183,12 @@ int lua_AnimationClip_addListener(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "AnimationClipListener");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'AnimationClip::Listener' for parameter 2.");
-                    lua_error(state);
-                }
-                AnimationClip::Listener* param1 = (AnimationClip::Listener*)((ScriptController::LuaObject*)userdata2)->instance;
+                AnimationClip::Listener* param1 = ScriptController::getInstance()->getObjectPointer<AnimationClip::Listener>(2, "AnimationClipListener", false);
 
                 // Get parameter 2 off the stack.
                 unsigned long param2 = (unsigned long)luaL_checkunsigned(state, 3);
@@ -243,7 +225,7 @@ int lua_AnimationClip_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 instance->addRef();
@@ -277,18 +259,12 @@ int lua_AnimationClip_crossFade(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "AnimationClip");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'AnimationClip' for parameter 2.");
-                    lua_error(state);
-                }
-                AnimationClip* param1 = (AnimationClip*)((ScriptController::LuaObject*)userdata2)->instance;
+                AnimationClip* param1 = ScriptController::getInstance()->getObjectPointer<AnimationClip>(2, "AnimationClip", false);
 
                 // Get parameter 2 off the stack.
                 unsigned long param2 = (unsigned long)luaL_checkunsigned(state, 3);
@@ -325,7 +301,7 @@ int lua_AnimationClip_getActiveDuration(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 unsigned long result = instance->getActiveDuration();
@@ -362,14 +338,22 @@ int lua_AnimationClip_getAnimation(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getAnimation();
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getAnimation();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -400,7 +384,7 @@ int lua_AnimationClip_getBlendWeight(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 float result = instance->getBlendWeight();
@@ -437,7 +421,7 @@ int lua_AnimationClip_getDuration(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 unsigned long result = instance->getDuration();
@@ -474,7 +458,7 @@ int lua_AnimationClip_getElaspedTime(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 float result = instance->getElaspedTime();
@@ -511,7 +495,7 @@ int lua_AnimationClip_getEndTime(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 unsigned long result = instance->getEndTime();
@@ -538,7 +522,7 @@ int lua_AnimationClip_getEndTime(lua_State* state)
     return 0;
 }
 
-int lua_AnimationClip_getID(lua_State* state)
+int lua_AnimationClip_getId(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -548,10 +532,10 @@ int lua_AnimationClip_getID(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
-                const char* result = instance->getID();
+                const char* result = instance->getId();
 
                 // Push the return value onto the stack.
                 lua_pushstring(state, result);
@@ -585,7 +569,7 @@ int lua_AnimationClip_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -622,7 +606,7 @@ int lua_AnimationClip_getRepeatCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 float result = instance->getRepeatCount();
@@ -659,7 +643,7 @@ int lua_AnimationClip_getSpeed(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 float result = instance->getSpeed();
@@ -696,7 +680,7 @@ int lua_AnimationClip_getStartTime(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 unsigned long result = instance->getStartTime();
@@ -733,7 +717,7 @@ int lua_AnimationClip_isPlaying(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 bool result = instance->isPlaying();
@@ -770,7 +754,7 @@ int lua_AnimationClip_pause(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 instance->pause();
@@ -804,7 +788,7 @@ int lua_AnimationClip_play(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 instance->play();
@@ -838,7 +822,7 @@ int lua_AnimationClip_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 instance->release();
@@ -872,7 +856,7 @@ int lua_AnimationClip_setActiveDuration(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -910,7 +894,7 @@ int lua_AnimationClip_setBlendWeight(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -948,7 +932,7 @@ int lua_AnimationClip_setRepeatCount(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -986,7 +970,7 @@ int lua_AnimationClip_setSpeed(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -1041,7 +1025,7 @@ int lua_AnimationClip_stop(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationClip* instance = getInstance(state);
                 instance->stop();

+ 1 - 1
gameplay/src/lua/lua_AnimationClip.h

@@ -17,7 +17,7 @@ int lua_AnimationClip_getBlendWeight(lua_State* state);
 int lua_AnimationClip_getDuration(lua_State* state);
 int lua_AnimationClip_getElaspedTime(lua_State* state);
 int lua_AnimationClip_getEndTime(lua_State* state);
-int lua_AnimationClip_getID(lua_State* state);
+int lua_AnimationClip_getId(lua_State* state);
 int lua_AnimationClip_getRefCount(lua_State* state);
 int lua_AnimationClip_getRepeatCount(lua_State* state);
 int lua_AnimationClip_getSpeed(lua_State* state);

+ 5 - 11
gameplay/src/lua/lua_AnimationClipListener.cpp

@@ -40,7 +40,7 @@ int lua_AnimationClipListener__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "AnimationClipListener");
                 luaL_argcheck(state, userdata != NULL, 1, "'AnimationClipListener' expected.");
@@ -80,18 +80,12 @@ int lua_AnimationClipListener_animationEvent(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "AnimationClip");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'AnimationClip' for parameter 2.");
-                    lua_error(state);
-                }
-                AnimationClip* param1 = (AnimationClip*)((ScriptController::LuaObject*)userdata2)->instance;
+                AnimationClip* param1 = ScriptController::getInstance()->getObjectPointer<AnimationClip>(2, "AnimationClip", false);
 
                 // Get parameter 2 off the stack.
                 AnimationClip::Listener::EventType param2 = (AnimationClip::Listener::EventType)lua_enumFromString_AnimationClipListenerEventType(luaL_checkstring(state, 3));

+ 1 - 1
gameplay/src/lua/lua_AnimationController.cpp

@@ -39,7 +39,7 @@ int lua_AnimationController_stopAllAnimations(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationController* instance = getInstance(state);
                 instance->stopAllAnimations();

+ 148 - 108
gameplay/src/lua/lua_AnimationTarget.cpp

@@ -46,47 +46,57 @@ int lua_AnimationTarget_createAnimation(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
-                const char* param2 = luaL_checkstring(state, 3);
+                const char* param2 = ScriptController::getInstance()->getString(3, false);
 
                 AnimationTarget* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->createAnimation(param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->createAnimation(param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Properties");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Properties' for parameter 3.");
-                    lua_error(state);
-                }
-                Properties* param2 = (Properties*)((ScriptController::LuaObject*)userdata3)->instance;
+                Properties* param2 = ScriptController::getInstance()->getObjectPointer<Properties>(3, "Properties", false);
 
                 AnimationTarget* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->createAnimation(param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->createAnimation(param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -99,16 +109,16 @@ int lua_AnimationTarget_createAnimation(lua_State* state)
         }
         case 7:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 lua_type(state, 4) == LUA_TNUMBER &&
                 (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 6) == LUA_TTABLE || lua_type(state, 6) == LUA_TLIGHTUSERDATA) &&
-                lua_type(state, 7) == LUA_TSTRING)
+                (lua_type(state, 7) == LUA_TSTRING || lua_type(state, 7) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
                 int param2 = (int)luaL_checkint(state, 3);
@@ -126,11 +136,19 @@ int lua_AnimationTarget_createAnimation(lua_State* state)
                 Curve::InterpolationType param6 = (Curve::InterpolationType)lua_enumFromString_CurveInterpolationType(luaL_checkstring(state, 7));
 
                 AnimationTarget* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->createAnimation(param1, param2, param3, param4, param5, param6);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->createAnimation(param1, param2, param3, param4, param5, param6);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -143,18 +161,18 @@ int lua_AnimationTarget_createAnimation(lua_State* state)
         }
         case 9:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 lua_type(state, 4) == LUA_TNUMBER &&
                 (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 6) == LUA_TTABLE || lua_type(state, 6) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 7) == LUA_TTABLE || lua_type(state, 7) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 8) == LUA_TTABLE || lua_type(state, 8) == LUA_TLIGHTUSERDATA) &&
-                lua_type(state, 9) == LUA_TSTRING)
+                (lua_type(state, 9) == LUA_TSTRING || lua_type(state, 9) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
                 int param2 = (int)luaL_checkint(state, 3);
@@ -178,11 +196,19 @@ int lua_AnimationTarget_createAnimation(lua_State* state)
                 Curve::InterpolationType param8 = (Curve::InterpolationType)lua_enumFromString_CurveInterpolationType(luaL_checkstring(state, 9));
 
                 AnimationTarget* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->createAnimation(param1, param2, param3, param4, param5, param6, param7, param8);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->createAnimation(param1, param2, param3, param4, param5, param6, param7, param8);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -213,16 +239,16 @@ int lua_AnimationTarget_createAnimationFromBy(lua_State* state)
     {
         case 7:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA) &&
-                lua_type(state, 6) == LUA_TSTRING &&
+                (lua_type(state, 6) == LUA_TSTRING || lua_type(state, 6) == LUA_TNIL) &&
                 lua_type(state, 7) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
                 int param2 = (int)luaL_checkint(state, 3);
@@ -240,11 +266,19 @@ int lua_AnimationTarget_createAnimationFromBy(lua_State* state)
                 unsigned long param6 = (unsigned long)luaL_checkunsigned(state, 7);
 
                 AnimationTarget* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->createAnimationFromBy(param1, param2, param3, param4, param5, param6);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->createAnimationFromBy(param1, param2, param3, param4, param5, param6);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -275,16 +309,16 @@ int lua_AnimationTarget_createAnimationFromTo(lua_State* state)
     {
         case 7:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA) &&
-                lua_type(state, 6) == LUA_TSTRING &&
+                (lua_type(state, 6) == LUA_TSTRING || lua_type(state, 6) == LUA_TNIL) &&
                 lua_type(state, 7) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
                 int param2 = (int)luaL_checkint(state, 3);
@@ -302,11 +336,19 @@ int lua_AnimationTarget_createAnimationFromTo(lua_State* state)
                 unsigned long param6 = (unsigned long)luaL_checkunsigned(state, 7);
 
                 AnimationTarget* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->createAnimationFromTo(param1, param2, param3, param4, param5, param6);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->createAnimationFromTo(param1, param2, param3, param4, param5, param6);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -337,7 +379,7 @@ int lua_AnimationTarget_destroyAnimation(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationTarget* instance = getInstance(state);
                 instance->destroyAnimation();
@@ -353,11 +395,11 @@ int lua_AnimationTarget_destroyAnimation(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 AnimationTarget* instance = getInstance(state);
                 instance->destroyAnimation(param1);
@@ -391,14 +433,22 @@ int lua_AnimationTarget_getAnimation(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AnimationTarget* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getAnimation();
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getAnimation();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -411,18 +461,26 @@ int lua_AnimationTarget_getAnimation(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 AnimationTarget* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getAnimation(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getAnimation(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -453,7 +511,7 @@ int lua_AnimationTarget_getAnimationPropertyComponentCount(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -494,21 +552,15 @@ int lua_AnimationTarget_getAnimationPropertyValue(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
                 int param1 = (int)luaL_checkint(state, 2);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "AnimationValue");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'AnimationValue' for parameter 3.");
-                    lua_error(state);
-                }
-                AnimationValue* param2 = (AnimationValue*)((ScriptController::LuaObject*)userdata3)->instance;
+                AnimationValue* param2 = ScriptController::getInstance()->getObjectPointer<AnimationValue>(3, "AnimationValue", false);
 
                 AnimationTarget* instance = getInstance(state);
                 instance->getAnimationPropertyValue(param1, param2);
@@ -542,21 +594,15 @@ int lua_AnimationTarget_setAnimationPropertyValue(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
                 int param1 = (int)luaL_checkint(state, 2);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "AnimationValue");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'AnimationValue' for parameter 3.");
-                    lua_error(state);
-                }
-                AnimationValue* param2 = (AnimationValue*)((ScriptController::LuaObject*)userdata3)->instance;
+                AnimationValue* param2 = ScriptController::getInstance()->getObjectPointer<AnimationValue>(3, "AnimationValue", false);
 
                 AnimationTarget* instance = getInstance(state);
                 instance->setAnimationPropertyValue(param1, param2);
@@ -572,22 +618,16 @@ int lua_AnimationTarget_setAnimationPropertyValue(lua_State* state)
         }
         case 4:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
                 int param1 = (int)luaL_checkint(state, 2);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "AnimationValue");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'AnimationValue' for parameter 3.");
-                    lua_error(state);
-                }
-                AnimationValue* param2 = (AnimationValue*)((ScriptController::LuaObject*)userdata3)->instance;
+                AnimationValue* param2 = ScriptController::getInstance()->getObjectPointer<AnimationValue>(3, "AnimationValue", false);
 
                 // Get parameter 3 off the stack.
                 float param3 = (float)luaL_checknumber(state, 4);

+ 4 - 4
gameplay/src/lua/lua_AnimationValue.cpp

@@ -40,7 +40,7 @@ int lua_AnimationValue_getFloat(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -63,7 +63,7 @@ int lua_AnimationValue_getFloat(lua_State* state)
         }
         case 4:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 lua_type(state, 4) == LUA_TNUMBER)
@@ -109,7 +109,7 @@ int lua_AnimationValue_setFloat(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
@@ -133,7 +133,7 @@ int lua_AnimationValue_setFloat(lua_State* state)
         }
         case 4:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 lua_type(state, 4) == LUA_TNUMBER)

+ 4 - 4
gameplay/src/lua/lua_AudioBuffer.cpp

@@ -41,7 +41,7 @@ int lua_AudioBuffer__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "AudioBuffer");
                 luaL_argcheck(state, userdata != NULL, 1, "'AudioBuffer' expected.");
@@ -81,7 +81,7 @@ int lua_AudioBuffer_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioBuffer* instance = getInstance(state);
                 instance->addRef();
@@ -115,7 +115,7 @@ int lua_AudioBuffer_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioBuffer* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -152,7 +152,7 @@ int lua_AudioBuffer_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioBuffer* instance = getInstance(state);
                 instance->release();

+ 1 - 1
gameplay/src/lua/lua_AudioController.cpp

@@ -38,7 +38,7 @@ int lua_AudioController__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "AudioController");
                 luaL_argcheck(state, userdata != NULL, 1, "'AudioController' expected.");

+ 99 - 81
gameplay/src/lua/lua_AudioListener.cpp

@@ -53,14 +53,22 @@ int lua_AudioListener_getCamera(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioListener* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getCamera();
-                object->owns = false;
-                luaL_getmetatable(state, "Camera");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getCamera();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Camera");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -91,7 +99,7 @@ int lua_AudioListener_getGain(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioListener* instance = getInstance(state);
                 float result = instance->getGain();
@@ -128,14 +136,22 @@ int lua_AudioListener_getOrientationForward(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioListener* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getOrientationForward());
-                object->owns = false;
-                luaL_getmetatable(state, "Vector3");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getOrientationForward());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Vector3");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -166,14 +182,22 @@ int lua_AudioListener_getOrientationUp(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioListener* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getOrientationUp());
-                object->owns = false;
-                luaL_getmetatable(state, "Vector3");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getOrientationUp());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Vector3");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -204,14 +228,22 @@ int lua_AudioListener_getPosition(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioListener* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getPosition());
-                object->owns = false;
-                luaL_getmetatable(state, "Vector3");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getPosition());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Vector3");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -242,14 +274,22 @@ int lua_AudioListener_getVelocity(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioListener* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getVelocity());
-                object->owns = false;
-                luaL_getmetatable(state, "Vector3");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getVelocity());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Vector3");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -280,17 +320,11 @@ int lua_AudioListener_setCamera(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Camera");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Camera' for parameter 2.");
-                    lua_error(state);
-                }
-                Camera* param1 = (Camera*)((ScriptController::LuaObject*)userdata2)->instance;
+                Camera* param1 = ScriptController::getInstance()->getObjectPointer<Camera>(2, "Camera", false);
 
                 AudioListener* instance = getInstance(state);
                 instance->setCamera(param1);
@@ -324,7 +358,7 @@ int lua_AudioListener_setGain(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -362,27 +396,15 @@ int lua_AudioListener_setOrientation(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector3");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", true);
 
                 AudioListener* instance = getInstance(state);
                 instance->setOrientation(*param1, *param2);
@@ -416,17 +438,11 @@ int lua_AudioListener_setPosition(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 AudioListener* instance = getInstance(state);
                 instance->setPosition(*param1);
@@ -460,17 +476,11 @@ int lua_AudioListener_setVelocity(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 AudioListener* instance = getInstance(state);
                 instance->setVelocity(*param1);
@@ -504,11 +514,19 @@ int lua_AudioListener_static_getInstance(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)AudioListener::getInstance();
-            object->owns = false;
-            luaL_getmetatable(state, "AudioListener");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)AudioListener::getInstance();
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = false;
+                luaL_getmetatable(state, "AudioListener");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;

+ 76 - 56
gameplay/src/lua/lua_AudioSource.cpp

@@ -60,7 +60,7 @@ int lua_AudioSource__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "AudioSource");
                 luaL_argcheck(state, userdata != NULL, 1, "'AudioSource' expected.");
@@ -100,7 +100,7 @@ int lua_AudioSource_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
                 instance->addRef();
@@ -134,7 +134,7 @@ int lua_AudioSource_getGain(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
                 float result = instance->getGain();
@@ -171,14 +171,22 @@ int lua_AudioSource_getNode(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getNode();
-                object->owns = false;
-                luaL_getmetatable(state, "Node");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getNode();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Node");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -209,7 +217,7 @@ int lua_AudioSource_getPitch(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
                 float result = instance->getPitch();
@@ -246,7 +254,7 @@ int lua_AudioSource_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -283,7 +291,7 @@ int lua_AudioSource_getState(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
                 AudioSource::State result = instance->getState();
@@ -320,14 +328,22 @@ int lua_AudioSource_getVelocity(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getVelocity());
-                object->owns = false;
-                luaL_getmetatable(state, "Vector3");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getVelocity());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Vector3");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -358,7 +374,7 @@ int lua_AudioSource_isLooped(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
                 bool result = instance->isLooped();
@@ -395,7 +411,7 @@ int lua_AudioSource_pause(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
                 instance->pause();
@@ -429,7 +445,7 @@ int lua_AudioSource_play(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
                 instance->play();
@@ -463,7 +479,7 @@ int lua_AudioSource_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
                 instance->release();
@@ -497,7 +513,7 @@ int lua_AudioSource_resume(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
                 instance->resume();
@@ -531,7 +547,7 @@ int lua_AudioSource_rewind(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
                 instance->rewind();
@@ -565,7 +581,7 @@ int lua_AudioSource_setGain(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -603,7 +619,7 @@ int lua_AudioSource_setLooped(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
@@ -641,7 +657,7 @@ int lua_AudioSource_setPitch(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -679,17 +695,11 @@ int lua_AudioSource_setVelocity(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 AudioSource* instance = getInstance(state);
                 instance->setVelocity(*param1);
@@ -723,35 +733,45 @@ int lua_AudioSource_static_create(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)AudioSource::create(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "AudioSource");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)AudioSource::create(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "AudioSource");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Properties");
-                if (!userdata1)
+                Properties* param1 = ScriptController::getInstance()->getObjectPointer<Properties>(1, "Properties", false);
+
+                void* returnPtr = (void*)AudioSource::create(param1);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Properties' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "AudioSource");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Properties* param1 = (Properties*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)AudioSource::create(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "AudioSource");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -782,7 +802,7 @@ int lua_AudioSource_stop(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 AudioSource* instance = getInstance(state);
                 instance->stop();

+ 141 - 199
gameplay/src/lua/lua_BoundingBox.cpp

@@ -51,7 +51,7 @@ int lua_BoundingBox__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "BoundingBox");
                 luaL_argcheck(state, userdata != NULL, 1, "'BoundingBox' expected.");
@@ -91,33 +91,43 @@ int lua_BoundingBox__init(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)new BoundingBox();
-            object->owns = true;
-            luaL_getmetatable(state, "BoundingBox");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)new BoundingBox();
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = true;
+                luaL_getmetatable(state, "BoundingBox");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;
         }
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "BoundingBox");
-                if (!userdata1)
+                BoundingBox* param1 = ScriptController::getInstance()->getObjectPointer<BoundingBox>(1, "BoundingBox", true);
+
+                void* returnPtr = (void*)new BoundingBox(*param1);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingBox' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "BoundingBox");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                BoundingBox* param1 = (BoundingBox*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new BoundingBox(*param1);
-                object->owns = true;
-                luaL_getmetatable(state, "BoundingBox");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -130,32 +140,28 @@ int lua_BoundingBox__init(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Vector3");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 1.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata1)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(1, "Vector3", true);
 
                 // Get parameter 2 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
+
+                void* returnPtr = (void*)new BoundingBox(*param1, *param2);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "BoundingBox");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new BoundingBox(*param1, *param2);
-                object->owns = true;
-                luaL_getmetatable(state, "BoundingBox");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -186,14 +192,22 @@ int lua_BoundingBox_getCenter(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 BoundingBox* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new Vector3(instance->getCenter());
-                object->owns = true;
-                luaL_getmetatable(state, "Vector3");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)new Vector3(instance->getCenter());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "Vector3");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -206,17 +220,11 @@ int lua_BoundingBox_getCenter(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", false);
 
                 BoundingBox* instance = getInstance(state);
                 instance->getCenter(param1);
@@ -250,17 +258,11 @@ int lua_BoundingBox_getCorners(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", false);
 
                 BoundingBox* instance = getInstance(state);
                 instance->getCorners(param1);
@@ -294,17 +296,11 @@ int lua_BoundingBox_intersects(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingBox");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingBox' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingBox* param1 = (BoundingBox*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingBox* param1 = ScriptController::getInstance()->getObjectPointer<BoundingBox>(2, "BoundingBox", true);
 
                 BoundingBox* instance = getInstance(state);
                 bool result = instance->intersects(*param1);
@@ -314,17 +310,11 @@ int lua_BoundingBox_intersects(lua_State* state)
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingSphere");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingSphere' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingSphere* param1 = (BoundingSphere*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingSphere* param1 = ScriptController::getInstance()->getObjectPointer<BoundingSphere>(2, "BoundingSphere", true);
 
                 BoundingBox* instance = getInstance(state);
                 bool result = instance->intersects(*param1);
@@ -334,17 +324,11 @@ int lua_BoundingBox_intersects(lua_State* state)
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Frustum");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Frustum' for parameter 2.");
-                    lua_error(state);
-                }
-                Frustum* param1 = (Frustum*)((ScriptController::LuaObject*)userdata2)->instance;
+                Frustum* param1 = ScriptController::getInstance()->getObjectPointer<Frustum>(2, "Frustum", true);
 
                 BoundingBox* instance = getInstance(state);
                 bool result = instance->intersects(*param1);
@@ -354,17 +338,11 @@ int lua_BoundingBox_intersects(lua_State* state)
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Plane");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Plane' for parameter 2.");
-                    lua_error(state);
-                }
-                Plane* param1 = (Plane*)((ScriptController::LuaObject*)userdata2)->instance;
+                Plane* param1 = ScriptController::getInstance()->getObjectPointer<Plane>(2, "Plane", true);
 
                 BoundingBox* instance = getInstance(state);
                 float result = instance->intersects(*param1);
@@ -374,17 +352,11 @@ int lua_BoundingBox_intersects(lua_State* state)
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Ray");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Ray' for parameter 2.");
-                    lua_error(state);
-                }
-                Ray* param1 = (Ray*)((ScriptController::LuaObject*)userdata2)->instance;
+                Ray* param1 = ScriptController::getInstance()->getObjectPointer<Ray>(2, "Ray", true);
 
                 BoundingBox* instance = getInstance(state);
                 float result = instance->intersects(*param1);
@@ -421,7 +393,7 @@ int lua_BoundingBox_isEmpty(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 BoundingBox* instance = getInstance(state);
                 bool result = instance->isEmpty();
@@ -461,24 +433,26 @@ int lua_BoundingBox_max(lua_State* state)
     if (lua_gettop(state) == 2)
     {
         // Get parameter 2 off the stack.
-        void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-        if (!userdata2)
-        {
-            lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-            lua_error(state);
-        }
-        Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+        Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
         instance->max = *param2;
         return 0;
     }
     else
     {
-        ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-        object->instance = (void*)new Vector3(instance->max);
-        object->owns = true;
-        luaL_getmetatable(state, "Vector3");
-        lua_setmetatable(state, -2);
+        void* returnPtr = (void*)new Vector3(instance->max);
+        if (returnPtr)
+        {
+            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+            object->instance = returnPtr;
+            object->owns = true;
+            luaL_getmetatable(state, "Vector3");
+            lua_setmetatable(state, -2);
+        }
+        else
+        {
+            lua_pushnil(state);
+        }
 
         return 1;
     }
@@ -494,34 +468,22 @@ int lua_BoundingBox_merge(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingSphere");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingSphere' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingSphere* param1 = (BoundingSphere*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingSphere* param1 = ScriptController::getInstance()->getObjectPointer<BoundingSphere>(2, "BoundingSphere", true);
 
                 BoundingBox* instance = getInstance(state);
                 instance->merge(*param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingBox");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingBox' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingBox* param1 = (BoundingBox*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingBox* param1 = ScriptController::getInstance()->getObjectPointer<BoundingBox>(2, "BoundingBox", true);
 
                 BoundingBox* instance = getInstance(state);
                 instance->merge(*param1);
@@ -558,24 +520,26 @@ int lua_BoundingBox_min(lua_State* state)
     if (lua_gettop(state) == 2)
     {
         // Get parameter 2 off the stack.
-        void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-        if (!userdata2)
-        {
-            lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-            lua_error(state);
-        }
-        Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+        Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
         instance->min = *param2;
         return 0;
     }
     else
     {
-        ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-        object->instance = (void*)new Vector3(instance->min);
-        object->owns = true;
-        luaL_getmetatable(state, "Vector3");
-        lua_setmetatable(state, -2);
+        void* returnPtr = (void*)new Vector3(instance->min);
+        if (returnPtr)
+        {
+            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+            object->instance = returnPtr;
+            object->owns = true;
+            luaL_getmetatable(state, "Vector3");
+            lua_setmetatable(state, -2);
+        }
+        else
+        {
+            lua_pushnil(state);
+        }
 
         return 1;
     }
@@ -591,34 +555,22 @@ int lua_BoundingBox_set(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingBox");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingBox' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingBox* param1 = (BoundingBox*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingBox* param1 = ScriptController::getInstance()->getObjectPointer<BoundingBox>(2, "BoundingBox", true);
 
                 BoundingBox* instance = getInstance(state);
                 instance->set(*param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingSphere");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingSphere' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingSphere* param1 = (BoundingSphere*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingSphere* param1 = ScriptController::getInstance()->getObjectPointer<BoundingSphere>(2, "BoundingSphere", true);
 
                 BoundingBox* instance = getInstance(state);
                 instance->set(*param1);
@@ -634,27 +586,15 @@ int lua_BoundingBox_set(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector3");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", true);
 
                 BoundingBox* instance = getInstance(state);
                 instance->set(*param1, *param2);
@@ -688,11 +628,19 @@ int lua_BoundingBox_static_empty(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)&(BoundingBox::empty());
-            object->owns = false;
-            luaL_getmetatable(state, "BoundingBox");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)&(BoundingBox::empty());
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = false;
+                luaL_getmetatable(state, "BoundingBox");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;
@@ -717,17 +665,11 @@ int lua_BoundingBox_transform(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Matrix");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Matrix' for parameter 2.");
-                    lua_error(state);
-                }
-                Matrix* param1 = (Matrix*)((ScriptController::LuaObject*)userdata2)->instance;
+                Matrix* param1 = ScriptController::getInstance()->getObjectPointer<Matrix>(2, "Matrix", true);
 
                 BoundingBox* instance = getInstance(state);
                 instance->transform(*param1);

+ 104 - 148
gameplay/src/lua/lua_BoundingSphere.cpp

@@ -49,7 +49,7 @@ int lua_BoundingSphere__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "BoundingSphere");
                 luaL_argcheck(state, userdata != NULL, 1, "'BoundingSphere' expected.");
@@ -89,33 +89,43 @@ int lua_BoundingSphere__init(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)new BoundingSphere();
-            object->owns = true;
-            luaL_getmetatable(state, "BoundingSphere");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)new BoundingSphere();
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = true;
+                luaL_getmetatable(state, "BoundingSphere");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;
         }
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "BoundingSphere");
-                if (!userdata1)
+                BoundingSphere* param1 = ScriptController::getInstance()->getObjectPointer<BoundingSphere>(1, "BoundingSphere", true);
+
+                void* returnPtr = (void*)new BoundingSphere(*param1);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingSphere' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "BoundingSphere");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                BoundingSphere* param1 = (BoundingSphere*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new BoundingSphere(*param1);
-                object->owns = true;
-                luaL_getmetatable(state, "BoundingSphere");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -128,26 +138,28 @@ int lua_BoundingSphere__init(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Vector3");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 1.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata1)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(1, "Vector3", true);
 
                 // Get parameter 2 off the stack.
                 float param2 = (float)luaL_checknumber(state, 2);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new BoundingSphere(*param1, param2);
-                object->owns = true;
-                luaL_getmetatable(state, "BoundingSphere");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)new BoundingSphere(*param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "BoundingSphere");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -181,24 +193,26 @@ int lua_BoundingSphere_center(lua_State* state)
     if (lua_gettop(state) == 2)
     {
         // Get parameter 2 off the stack.
-        void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-        if (!userdata2)
-        {
-            lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-            lua_error(state);
-        }
-        Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+        Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
         instance->center = *param2;
         return 0;
     }
     else
     {
-        ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-        object->instance = (void*)new Vector3(instance->center);
-        object->owns = true;
-        luaL_getmetatable(state, "Vector3");
-        lua_setmetatable(state, -2);
+        void* returnPtr = (void*)new Vector3(instance->center);
+        if (returnPtr)
+        {
+            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+            object->instance = returnPtr;
+            object->owns = true;
+            luaL_getmetatable(state, "Vector3");
+            lua_setmetatable(state, -2);
+        }
+        else
+        {
+            lua_pushnil(state);
+        }
 
         return 1;
     }
@@ -214,17 +228,11 @@ int lua_BoundingSphere_intersects(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingSphere");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingSphere' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingSphere* param1 = (BoundingSphere*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingSphere* param1 = ScriptController::getInstance()->getObjectPointer<BoundingSphere>(2, "BoundingSphere", true);
 
                 BoundingSphere* instance = getInstance(state);
                 bool result = instance->intersects(*param1);
@@ -234,17 +242,11 @@ int lua_BoundingSphere_intersects(lua_State* state)
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingBox");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingBox' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingBox* param1 = (BoundingBox*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingBox* param1 = ScriptController::getInstance()->getObjectPointer<BoundingBox>(2, "BoundingBox", true);
 
                 BoundingSphere* instance = getInstance(state);
                 bool result = instance->intersects(*param1);
@@ -254,17 +256,11 @@ int lua_BoundingSphere_intersects(lua_State* state)
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Frustum");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Frustum' for parameter 2.");
-                    lua_error(state);
-                }
-                Frustum* param1 = (Frustum*)((ScriptController::LuaObject*)userdata2)->instance;
+                Frustum* param1 = ScriptController::getInstance()->getObjectPointer<Frustum>(2, "Frustum", true);
 
                 BoundingSphere* instance = getInstance(state);
                 bool result = instance->intersects(*param1);
@@ -274,17 +270,11 @@ int lua_BoundingSphere_intersects(lua_State* state)
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Plane");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Plane' for parameter 2.");
-                    lua_error(state);
-                }
-                Plane* param1 = (Plane*)((ScriptController::LuaObject*)userdata2)->instance;
+                Plane* param1 = ScriptController::getInstance()->getObjectPointer<Plane>(2, "Plane", true);
 
                 BoundingSphere* instance = getInstance(state);
                 float result = instance->intersects(*param1);
@@ -294,17 +284,11 @@ int lua_BoundingSphere_intersects(lua_State* state)
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Ray");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Ray' for parameter 2.");
-                    lua_error(state);
-                }
-                Ray* param1 = (Ray*)((ScriptController::LuaObject*)userdata2)->instance;
+                Ray* param1 = ScriptController::getInstance()->getObjectPointer<Ray>(2, "Ray", true);
 
                 BoundingSphere* instance = getInstance(state);
                 float result = instance->intersects(*param1);
@@ -341,7 +325,7 @@ int lua_BoundingSphere_isEmpty(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 BoundingSphere* instance = getInstance(state);
                 bool result = instance->isEmpty();
@@ -378,34 +362,22 @@ int lua_BoundingSphere_merge(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingSphere");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingSphere' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingSphere* param1 = (BoundingSphere*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingSphere* param1 = ScriptController::getInstance()->getObjectPointer<BoundingSphere>(2, "BoundingSphere", true);
 
                 BoundingSphere* instance = getInstance(state);
                 instance->merge(*param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingBox");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingBox' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingBox* param1 = (BoundingBox*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingBox* param1 = ScriptController::getInstance()->getObjectPointer<BoundingBox>(2, "BoundingBox", true);
 
                 BoundingSphere* instance = getInstance(state);
                 instance->merge(*param1);
@@ -468,34 +440,22 @@ int lua_BoundingSphere_set(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingSphere");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingSphere' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingSphere* param1 = (BoundingSphere*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingSphere* param1 = ScriptController::getInstance()->getObjectPointer<BoundingSphere>(2, "BoundingSphere", true);
 
                 BoundingSphere* instance = getInstance(state);
                 instance->set(*param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingBox");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingBox' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingBox* param1 = (BoundingBox*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingBox* param1 = ScriptController::getInstance()->getObjectPointer<BoundingBox>(2, "BoundingBox", true);
 
                 BoundingSphere* instance = getInstance(state);
                 instance->set(*param1);
@@ -511,18 +471,12 @@ int lua_BoundingSphere_set(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 // Get parameter 2 off the stack.
                 float param2 = (float)luaL_checknumber(state, 3);
@@ -559,11 +513,19 @@ int lua_BoundingSphere_static_empty(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)&(BoundingSphere::empty());
-            object->owns = false;
-            luaL_getmetatable(state, "BoundingSphere");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)&(BoundingSphere::empty());
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = false;
+                luaL_getmetatable(state, "BoundingSphere");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;
@@ -588,17 +550,11 @@ int lua_BoundingSphere_transform(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Matrix");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Matrix' for parameter 2.");
-                    lua_error(state);
-                }
-                Matrix* param1 = (Matrix*)((ScriptController::LuaObject*)userdata2)->instance;
+                Matrix* param1 = ScriptController::getInstance()->getObjectPointer<Matrix>(2, "Matrix", true);
 
                 BoundingSphere* instance = getInstance(state);
                 instance->transform(*param1);

+ 102 - 54
gameplay/src/lua/lua_Bundle.cpp

@@ -52,7 +52,7 @@ int lua_Bundle__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Bundle");
                 luaL_argcheck(state, userdata != NULL, 1, "'Bundle' expected.");
@@ -92,7 +92,7 @@ int lua_Bundle_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Bundle* instance = getInstance(state);
                 instance->addRef();
@@ -126,11 +126,11 @@ int lua_Bundle_contains(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Bundle* instance = getInstance(state);
                 bool result = instance->contains(param1);
@@ -167,7 +167,7 @@ int lua_Bundle_getObjectCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Bundle* instance = getInstance(state);
                 unsigned int result = instance->getObjectCount();
@@ -204,7 +204,7 @@ int lua_Bundle_getObjectID(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -245,7 +245,7 @@ int lua_Bundle_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Bundle* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -282,18 +282,26 @@ int lua_Bundle_loadFont(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Bundle* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->loadFont(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Font");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->loadFont(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Font");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -324,18 +332,26 @@ int lua_Bundle_loadMesh(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Bundle* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->loadMesh(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Mesh");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->loadMesh(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Mesh");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -366,18 +382,26 @@ int lua_Bundle_loadNode(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Bundle* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->loadNode(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Node");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->loadNode(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Node");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -408,14 +432,22 @@ int lua_Bundle_loadScene(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Bundle* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->loadScene();
-                object->owns = false;
-                luaL_getmetatable(state, "Scene");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->loadScene();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Scene");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -428,18 +460,26 @@ int lua_Bundle_loadScene(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Bundle* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->loadScene(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Scene");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->loadScene(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Scene");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -470,7 +510,7 @@ int lua_Bundle_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Bundle* instance = getInstance(state);
                 instance->release();
@@ -504,16 +544,24 @@ int lua_Bundle_static_create(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Bundle::create(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Bundle");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Bundle::create(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Bundle");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }

文件差异内容过多而无法显示
+ 381 - 198
gameplay/src/lua/lua_Button.cpp


+ 5 - 1
gameplay/src/lua/lua_Button.h

@@ -28,10 +28,11 @@ 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_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);
@@ -51,6 +52,7 @@ 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_isContainer(lua_State* state);
 int lua_Button_isEnabled(lua_State* state);
 int lua_Button_release(lua_State* state);
 int lua_Button_setAlignment(lua_State* state);
@@ -62,6 +64,7 @@ int lua_Button_setBounds(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_setFocusIndex(lua_State* state);
 int lua_Button_setFont(lua_State* state);
 int lua_Button_setFontSize(lua_State* state);
 int lua_Button_setImageColor(lua_State* state);
@@ -87,6 +90,7 @@ 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();
 

+ 161 - 137
gameplay/src/lua/lua_Camera.cpp

@@ -69,7 +69,7 @@ int lua_Camera__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Camera");
                 luaL_argcheck(state, userdata != NULL, 1, "'Camera' expected.");
@@ -109,7 +109,7 @@ int lua_Camera_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
                 instance->addRef();
@@ -143,7 +143,7 @@ int lua_Camera_getAspectRatio(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
                 float result = instance->getAspectRatio();
@@ -180,7 +180,7 @@ int lua_Camera_getCameraType(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
                 Camera::Type result = instance->getCameraType();
@@ -217,7 +217,7 @@ int lua_Camera_getFarPlane(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
                 float result = instance->getFarPlane();
@@ -254,7 +254,7 @@ int lua_Camera_getFieldOfView(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
                 float result = instance->getFieldOfView();
@@ -291,14 +291,22 @@ int lua_Camera_getFrustum(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getFrustum());
-                object->owns = false;
-                luaL_getmetatable(state, "Frustum");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getFrustum());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Frustum");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -329,14 +337,22 @@ int lua_Camera_getInverseViewMatrix(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getInverseViewMatrix());
-                object->owns = false;
-                luaL_getmetatable(state, "Matrix");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getInverseViewMatrix());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Matrix");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -367,14 +383,22 @@ int lua_Camera_getInverseViewProjectionMatrix(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getInverseViewProjectionMatrix());
-                object->owns = false;
-                luaL_getmetatable(state, "Matrix");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getInverseViewProjectionMatrix());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Matrix");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -405,7 +429,7 @@ int lua_Camera_getNearPlane(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
                 float result = instance->getNearPlane();
@@ -442,14 +466,22 @@ int lua_Camera_getNode(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getNode();
-                object->owns = false;
-                luaL_getmetatable(state, "Node");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getNode();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Node");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -480,14 +512,22 @@ int lua_Camera_getProjectionMatrix(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getProjectionMatrix());
-                object->owns = false;
-                luaL_getmetatable(state, "Matrix");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getProjectionMatrix());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Matrix");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -518,7 +558,7 @@ int lua_Camera_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -555,14 +595,22 @@ int lua_Camera_getViewMatrix(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getViewMatrix());
-                object->owns = false;
-                luaL_getmetatable(state, "Matrix");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getViewMatrix());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Matrix");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -593,14 +641,22 @@ int lua_Camera_getViewProjectionMatrix(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getViewProjectionMatrix());
-                object->owns = false;
-                luaL_getmetatable(state, "Matrix");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getViewProjectionMatrix());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Matrix");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -631,7 +687,7 @@ int lua_Camera_getZoomX(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
                 float result = instance->getZoomX();
@@ -668,7 +724,7 @@ int lua_Camera_getZoomY(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
                 float result = instance->getZoomY();
@@ -705,20 +761,14 @@ int lua_Camera_pickRay(lua_State* state)
     {
         case 5:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 lua_type(state, 4) == LUA_TNUMBER &&
-                lua_type(state, 5) == LUA_TUSERDATA)
+                (lua_type(state, 5) == LUA_TUSERDATA || lua_type(state, 5) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Rectangle");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Rectangle' for parameter 2.");
-                    lua_error(state);
-                }
-                Rectangle* param1 = (Rectangle*)((ScriptController::LuaObject*)userdata2)->instance;
+                Rectangle* param1 = ScriptController::getInstance()->getObjectPointer<Rectangle>(2, "Rectangle", true);
 
                 // Get parameter 2 off the stack.
                 float param2 = (float)luaL_checknumber(state, 3);
@@ -727,13 +777,7 @@ int lua_Camera_pickRay(lua_State* state)
                 float param3 = (float)luaL_checknumber(state, 4);
 
                 // Get parameter 4 off the stack.
-                void* userdata5 = ScriptController::getInstance()->getObjectPointer(5, "Ray");
-                if (!userdata5)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Ray' for parameter 5.");
-                    lua_error(state);
-                }
-                Ray* param4 = (Ray*)((ScriptController::LuaObject*)userdata5)->instance;
+                Ray* param4 = ScriptController::getInstance()->getObjectPointer<Ray>(5, "Ray", false);
 
                 Camera* instance = getInstance(state);
                 instance->pickRay(*param1, param2, param3, param4);
@@ -767,29 +811,17 @@ int lua_Camera_project(lua_State* state)
     {
         case 5:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
                 (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Rectangle");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Rectangle' for parameter 2.");
-                    lua_error(state);
-                }
-                Rectangle* param1 = (Rectangle*)((ScriptController::LuaObject*)userdata2)->instance;
+                Rectangle* param1 = ScriptController::getInstance()->getObjectPointer<Rectangle>(2, "Rectangle", true);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector3");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", true);
 
                 // Get parameter 3 off the stack.
                 float* param3 = ScriptController::getInstance()->getFloatPointer(4);
@@ -811,30 +843,18 @@ int lua_Camera_project(lua_State* state)
         }
         case 6:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
                 (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 6) == LUA_TTABLE || lua_type(state, 6) == LUA_TLIGHTUSERDATA))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Rectangle");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Rectangle' for parameter 2.");
-                    lua_error(state);
-                }
-                Rectangle* param1 = (Rectangle*)((ScriptController::LuaObject*)userdata2)->instance;
+                Rectangle* param1 = ScriptController::getInstance()->getObjectPointer<Rectangle>(2, "Rectangle", true);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector3");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", true);
 
                 // Get parameter 3 off the stack.
                 float* param3 = ScriptController::getInstance()->getFloatPointer(4);
@@ -877,7 +897,7 @@ int lua_Camera_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Camera* instance = getInstance(state);
                 instance->release();
@@ -911,7 +931,7 @@ int lua_Camera_setAspectRatio(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -949,7 +969,7 @@ int lua_Camera_setFarPlane(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -987,7 +1007,7 @@ int lua_Camera_setFieldOfView(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -1025,7 +1045,7 @@ int lua_Camera_setNearPlane(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -1063,7 +1083,7 @@ int lua_Camera_setZoomX(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -1101,7 +1121,7 @@ int lua_Camera_setZoomY(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -1160,11 +1180,19 @@ int lua_Camera_static_createOrthographic(lua_State* state)
                 // Get parameter 5 off the stack.
                 float param5 = (float)luaL_checknumber(state, 5);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Camera::createOrthographic(param1, param2, param3, param4, param5);
-                object->owns = false;
-                luaL_getmetatable(state, "Camera");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Camera::createOrthographic(param1, param2, param3, param4, param5);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Camera");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -1212,11 +1240,19 @@ int lua_Camera_static_createPerspective(lua_State* state)
                 // Get parameter 4 off the stack.
                 float param4 = (float)luaL_checknumber(state, 4);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Camera::createPerspective(param1, param2, param3, param4);
-                object->owns = false;
-                luaL_getmetatable(state, "Camera");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Camera::createPerspective(param1, param2, param3, param4);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Camera");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -1247,21 +1283,15 @@ int lua_Camera_unproject(lua_State* state)
     {
         case 6:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 lua_type(state, 4) == LUA_TNUMBER &&
                 lua_type(state, 5) == LUA_TNUMBER &&
-                lua_type(state, 6) == LUA_TUSERDATA)
+                (lua_type(state, 6) == LUA_TUSERDATA || lua_type(state, 6) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Rectangle");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Rectangle' for parameter 2.");
-                    lua_error(state);
-                }
-                Rectangle* param1 = (Rectangle*)((ScriptController::LuaObject*)userdata2)->instance;
+                Rectangle* param1 = ScriptController::getInstance()->getObjectPointer<Rectangle>(2, "Rectangle", true);
 
                 // Get parameter 2 off the stack.
                 float param2 = (float)luaL_checknumber(state, 3);
@@ -1273,13 +1303,7 @@ int lua_Camera_unproject(lua_State* state)
                 float param4 = (float)luaL_checknumber(state, 5);
 
                 // Get parameter 5 off the stack.
-                void* userdata6 = ScriptController::getInstance()->getObjectPointer(6, "Vector3");
-                if (!userdata6)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 6.");
-                    lua_error(state);
-                }
-                Vector3* param5 = (Vector3*)((ScriptController::LuaObject*)userdata6)->instance;
+                Vector3* param5 = ScriptController::getInstance()->getObjectPointer<Vector3>(6, "Vector3", false);
 
                 Camera* instance = getInstance(state);
                 instance->unproject(*param1, param2, param3, param4, param5);

文件差异内容过多而无法显示
+ 382 - 198
gameplay/src/lua/lua_CheckBox.cpp


+ 6 - 1
gameplay/src/lua/lua_CheckBox.h

@@ -28,10 +28,11 @@ 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_getId(lua_State* state);
 int lua_CheckBox_getImageColor(lua_State* state);
 int lua_CheckBox_getImageRegion(lua_State* state);
 int lua_CheckBox_getImageSize(lua_State* state);
@@ -48,11 +49,13 @@ 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_getType(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_isChecked(lua_State* state);
+int lua_CheckBox_isContainer(lua_State* state);
 int lua_CheckBox_isEnabled(lua_State* state);
 int lua_CheckBox_release(lua_State* state);
 int lua_CheckBox_setAlignment(lua_State* state);
@@ -65,6 +68,7 @@ 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_setFocusIndex(lua_State* state);
 int lua_CheckBox_setFont(lua_State* state);
 int lua_CheckBox_setFontSize(lua_State* state);
 int lua_CheckBox_setImageColor(lua_State* state);
@@ -91,6 +95,7 @@ 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();
 

文件差异内容过多而无法显示
+ 378 - 200
gameplay/src/lua/lua_Container.cpp


+ 6 - 1
gameplay/src/lua/lua_Container.h

@@ -30,10 +30,11 @@ int lua_Container_getControl(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_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);
@@ -50,11 +51,13 @@ 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_getType(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_insertControl(lua_State* state);
+int lua_Container_isContainer(lua_State* state);
 int lua_Container_isEnabled(lua_State* state);
 int lua_Container_isScrollBarsAutoHide(lua_State* state);
 int lua_Container_release(lua_State* state);
@@ -68,6 +71,7 @@ int lua_Container_setBounds(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_setFocusIndex(lua_State* state);
 int lua_Container_setFont(lua_State* state);
 int lua_Container_setFontSize(lua_State* state);
 int lua_Container_setImageColor(lua_State* state);
@@ -95,6 +99,7 @@ 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);
 
 void luaRegister_Container();
 

文件差异内容过多而无法显示
+ 381 - 198
gameplay/src/lua/lua_Control.cpp


+ 5 - 1
gameplay/src/lua/lua_Control.h

@@ -28,10 +28,11 @@ 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_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);
@@ -46,10 +47,12 @@ 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_getType(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_isContainer(lua_State* state);
 int lua_Control_isEnabled(lua_State* state);
 int lua_Control_release(lua_State* state);
 int lua_Control_setAlignment(lua_State* state);
@@ -61,6 +64,7 @@ int lua_Control_setBounds(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_setFocusIndex(lua_State* state);
 int lua_Control_setFont(lua_State* state);
 int lua_Control_setFontSize(lua_State* state);
 int lua_Control_setImageColor(lua_State* state);

+ 5 - 11
gameplay/src/lua/lua_ControlListener.cpp

@@ -40,7 +40,7 @@ int lua_ControlListener__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "ControlListener");
                 luaL_argcheck(state, userdata != NULL, 1, "'ControlListener' expected.");
@@ -80,18 +80,12 @@ int lua_ControlListener_controlEvent(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Control");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Control' for parameter 2.");
-                    lua_error(state);
-                }
-                Control* param1 = (Control*)((ScriptController::LuaObject*)userdata2)->instance;
+                Control* param1 = ScriptController::getInstance()->getObjectPointer<Control>(2, "Control", false);
 
                 // Get parameter 2 off the stack.
                 Control::Listener::EventType param2 = (Control::Listener::EventType)lua_enumFromString_ControlListenerEventType(luaL_checkstring(state, 3));

+ 28 - 20
gameplay/src/lua/lua_Curve.cpp

@@ -53,7 +53,7 @@ int lua_Curve__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Curve");
                 luaL_argcheck(state, userdata != NULL, 1, "'Curve' expected.");
@@ -93,7 +93,7 @@ int lua_Curve_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Curve* instance = getInstance(state);
                 instance->addRef();
@@ -127,7 +127,7 @@ int lua_Curve_evaluate(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER &&
                 (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA))
             {
@@ -169,7 +169,7 @@ int lua_Curve_getComponentCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Curve* instance = getInstance(state);
                 unsigned int result = instance->getComponentCount();
@@ -206,7 +206,7 @@ int lua_Curve_getEndTime(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Curve* instance = getInstance(state);
                 float result = instance->getEndTime();
@@ -243,7 +243,7 @@ int lua_Curve_getPointCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Curve* instance = getInstance(state);
                 unsigned int result = instance->getPointCount();
@@ -280,7 +280,7 @@ int lua_Curve_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Curve* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -317,7 +317,7 @@ int lua_Curve_getStartTime(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Curve* instance = getInstance(state);
                 float result = instance->getStartTime();
@@ -354,7 +354,7 @@ int lua_Curve_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Curve* instance = getInstance(state);
                 instance->release();
@@ -388,11 +388,11 @@ int lua_Curve_setPoint(lua_State* state)
     {
         case 5:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
-                lua_type(state, 5) == LUA_TSTRING)
+                (lua_type(state, 5) == LUA_TSTRING || lua_type(state, 5) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
                 unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
@@ -420,11 +420,11 @@ int lua_Curve_setPoint(lua_State* state)
         }
         case 7:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
-                lua_type(state, 5) == LUA_TSTRING &&
+                (lua_type(state, 5) == LUA_TSTRING || lua_type(state, 5) == LUA_TNIL) &&
                 (lua_type(state, 6) == LUA_TTABLE || lua_type(state, 6) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 7) == LUA_TTABLE || lua_type(state, 7) == LUA_TLIGHTUSERDATA))
             {
@@ -478,9 +478,9 @@ int lua_Curve_setTangent(lua_State* state)
     {
         case 5:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER &&
-                lua_type(state, 3) == LUA_TSTRING &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
                 (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA))
             {
@@ -537,11 +537,19 @@ int lua_Curve_static_create(lua_State* state)
                 // Get parameter 2 off the stack.
                 unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Curve::create(param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "Curve");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Curve::create(param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Curve");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }

+ 40 - 24
gameplay/src/lua/lua_DepthStencilTarget.cpp

@@ -15,7 +15,7 @@ void luaRegister_DepthStencilTarget()
     {
         {"addRef", lua_DepthStencilTarget_addRef},
         {"getFormat", lua_DepthStencilTarget_getFormat},
-        {"getID", lua_DepthStencilTarget_getID},
+        {"getId", lua_DepthStencilTarget_getId},
         {"getRefCount", lua_DepthStencilTarget_getRefCount},
         {"release", lua_DepthStencilTarget_release},
         {NULL, NULL}
@@ -48,7 +48,7 @@ int lua_DepthStencilTarget__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "DepthStencilTarget");
                 luaL_argcheck(state, userdata != NULL, 1, "'DepthStencilTarget' expected.");
@@ -88,7 +88,7 @@ int lua_DepthStencilTarget_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 DepthStencilTarget* instance = getInstance(state);
                 instance->addRef();
@@ -122,7 +122,7 @@ int lua_DepthStencilTarget_getFormat(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 DepthStencilTarget* instance = getInstance(state);
                 DepthStencilTarget::Format result = instance->getFormat();
@@ -149,7 +149,7 @@ int lua_DepthStencilTarget_getFormat(lua_State* state)
     return 0;
 }
 
-int lua_DepthStencilTarget_getID(lua_State* state)
+int lua_DepthStencilTarget_getId(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -159,10 +159,10 @@ int lua_DepthStencilTarget_getID(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 DepthStencilTarget* instance = getInstance(state);
-                const char* result = instance->getID();
+                const char* result = instance->getId();
 
                 // Push the return value onto the stack.
                 lua_pushstring(state, result);
@@ -196,7 +196,7 @@ int lua_DepthStencilTarget_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 DepthStencilTarget* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -233,7 +233,7 @@ int lua_DepthStencilTarget_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 DepthStencilTarget* instance = getInstance(state);
                 instance->release();
@@ -267,13 +267,13 @@ int lua_DepthStencilTarget_static_create(lua_State* state)
     {
         case 4:
         {
-            if (lua_type(state, 1) == LUA_TSTRING &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 lua_type(state, 4) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 // Get parameter 2 off the stack.
                 DepthStencilTarget::Format param2 = (DepthStencilTarget::Format)lua_enumFromString_DepthStencilTargetFormat(luaL_checkstring(state, 2));
@@ -284,11 +284,19 @@ int lua_DepthStencilTarget_static_create(lua_State* state)
                 // Get parameter 4 off the stack.
                 unsigned int param4 = (unsigned int)luaL_checkunsigned(state, 4);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)DepthStencilTarget::create(param1, param2, param3, param4);
-                object->owns = false;
-                luaL_getmetatable(state, "DepthStencilTarget");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)DepthStencilTarget::create(param1, param2, param3, param4);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "DepthStencilTarget");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -319,16 +327,24 @@ int lua_DepthStencilTarget_static_getDepthStencilTarget(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)DepthStencilTarget::getDepthStencilTarget(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "DepthStencilTarget");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)DepthStencilTarget::getDepthStencilTarget(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "DepthStencilTarget");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }

+ 1 - 1
gameplay/src/lua/lua_DepthStencilTarget.h

@@ -8,7 +8,7 @@ namespace gameplay
 int lua_DepthStencilTarget__gc(lua_State* state);
 int lua_DepthStencilTarget_addRef(lua_State* state);
 int lua_DepthStencilTarget_getFormat(lua_State* state);
-int lua_DepthStencilTarget_getID(lua_State* state);
+int lua_DepthStencilTarget_getId(lua_State* state);
 int lua_DepthStencilTarget_getRefCount(lua_State* state);
 int lua_DepthStencilTarget_release(lua_State* state);
 int lua_DepthStencilTarget_static_create(lua_State* state);

+ 221 - 349
gameplay/src/lua/lua_Effect.cpp

@@ -53,7 +53,7 @@ int lua_Effect__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Effect");
                 luaL_argcheck(state, userdata != NULL, 1, "'Effect' expected.");
@@ -93,7 +93,7 @@ int lua_Effect_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Effect* instance = getInstance(state);
                 instance->addRef();
@@ -127,7 +127,7 @@ int lua_Effect_bind(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Effect* instance = getInstance(state);
                 instance->bind();
@@ -161,7 +161,7 @@ int lua_Effect_getId(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Effect* instance = getInstance(state);
                 const char* result = instance->getId();
@@ -198,7 +198,7 @@ int lua_Effect_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Effect* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -235,33 +235,49 @@ int lua_Effect_getUniform(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Effect* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getUniform(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Uniform");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getUniform(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Uniform");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
                 unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
 
                 Effect* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getUniform(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Uniform");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getUniform(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Uniform");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -292,7 +308,7 @@ int lua_Effect_getUniformCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Effect* instance = getInstance(state);
                 unsigned int result = instance->getUniformCount();
@@ -329,18 +345,26 @@ int lua_Effect_getVertexAttribute(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Effect* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new GLint(instance->getVertexAttribute(param1));
-                object->owns = true;
-                luaL_getmetatable(state, "GLint");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)new GLint(instance->getVertexAttribute(param1));
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "GLint");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -371,7 +395,7 @@ int lua_Effect_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Effect* instance = getInstance(state);
                 instance->release();
@@ -405,18 +429,12 @@ int lua_Effect_setValue(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
                 float param2 = (float)luaL_checknumber(state, 3);
@@ -426,18 +444,12 @@ int lua_Effect_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
                 float* param2 = ScriptController::getInstance()->getFloatPointer(3);
@@ -447,18 +459,12 @@ int lua_Effect_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
                 int param2 = (int)luaL_checkint(state, 3);
@@ -468,18 +474,12 @@ int lua_Effect_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
                 int* param2 = ScriptController::getInstance()->getIntPointer(3);
@@ -489,243 +489,135 @@ int lua_Effect_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Matrix");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Matrix' for parameter 3.");
-                    lua_error(state);
-                }
-                Matrix* param2 = (Matrix*)((ScriptController::LuaObject*)userdata3)->instance;
+                Matrix* param2 = ScriptController::getInstance()->getObjectPointer<Matrix>(3, "Matrix", true);
 
                 Effect* instance = getInstance(state);
                 instance->setValue(param1, *param2);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Matrix");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Matrix' for parameter 3.");
-                    lua_error(state);
-                }
-                Matrix* param2 = (Matrix*)((ScriptController::LuaObject*)userdata3)->instance;
+                Matrix* param2 = ScriptController::getInstance()->getObjectPointer<Matrix>(3, "Matrix", false);
 
                 Effect* instance = getInstance(state);
                 instance->setValue(param1, param2);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector2");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector2' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector2* param2 = (Vector2*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector2* param2 = ScriptController::getInstance()->getObjectPointer<Vector2>(3, "Vector2", true);
 
                 Effect* instance = getInstance(state);
                 instance->setValue(param1, *param2);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector2");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector2' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector2* param2 = (Vector2*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector2* param2 = ScriptController::getInstance()->getObjectPointer<Vector2>(3, "Vector2", false);
 
                 Effect* instance = getInstance(state);
                 instance->setValue(param1, param2);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector3");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", true);
 
                 Effect* instance = getInstance(state);
                 instance->setValue(param1, *param2);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector3");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", false);
 
                 Effect* instance = getInstance(state);
                 instance->setValue(param1, param2);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector4");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector4' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector4* param2 = (Vector4*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector4* param2 = ScriptController::getInstance()->getObjectPointer<Vector4>(3, "Vector4", true);
 
                 Effect* instance = getInstance(state);
                 instance->setValue(param1, *param2);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector4");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector4' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector4* param2 = (Vector4*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector4* param2 = ScriptController::getInstance()->getObjectPointer<Vector4>(3, "Vector4", false);
 
                 Effect* instance = getInstance(state);
                 instance->setValue(param1, param2);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "TextureSampler");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Texture::Sampler' for parameter 3.");
-                    lua_error(state);
-                }
-                Texture::Sampler* param2 = (Texture::Sampler*)((ScriptController::LuaObject*)userdata3)->instance;
+                Texture::Sampler* param2 = ScriptController::getInstance()->getObjectPointer<Texture::Sampler>(3, "TextureSampler", false);
 
                 Effect* instance = getInstance(state);
                 instance->setValue(param1, param2);
@@ -741,19 +633,13 @@ int lua_Effect_setValue(lua_State* state)
         }
         case 4:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA) &&
                 lua_type(state, 4) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
                 float* param2 = ScriptController::getInstance()->getFloatPointer(3);
@@ -766,19 +652,13 @@ int lua_Effect_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA) &&
                 lua_type(state, 4) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
                 int* param2 = ScriptController::getInstance()->getIntPointer(3);
@@ -791,28 +671,16 @@ int lua_Effect_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Matrix");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Matrix' for parameter 3.");
-                    lua_error(state);
-                }
-                Matrix* param2 = (Matrix*)((ScriptController::LuaObject*)userdata3)->instance;
+                Matrix* param2 = ScriptController::getInstance()->getObjectPointer<Matrix>(3, "Matrix", false);
 
                 // Get parameter 3 off the stack.
                 unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
@@ -822,28 +690,16 @@ int lua_Effect_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector2");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector2' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector2* param2 = (Vector2*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector2* param2 = ScriptController::getInstance()->getObjectPointer<Vector2>(3, "Vector2", false);
 
                 // Get parameter 3 off the stack.
                 unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
@@ -853,28 +709,16 @@ int lua_Effect_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector3");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", false);
 
                 // Get parameter 3 off the stack.
                 unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
@@ -884,28 +728,16 @@ int lua_Effect_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Uniform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Uniform' for parameter 2.");
-                    lua_error(state);
-                }
-                Uniform* param1 = (Uniform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector4");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector4' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector4* param2 = (Vector4*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector4* param2 = ScriptController::getInstance()->getObjectPointer<Vector4>(3, "Vector4", false);
 
                 // Get parameter 3 off the stack.
                 unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
@@ -942,20 +774,28 @@ int lua_Effect_static_createFromFile(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TSTRING &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 // Get parameter 2 off the stack.
-                const char* param2 = luaL_checkstring(state, 2);
+                const char* param2 = ScriptController::getInstance()->getString(2, false);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Effect::createFromFile(param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "Effect");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Effect::createFromFile(param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Effect");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -968,24 +808,32 @@ int lua_Effect_static_createFromFile(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TSTRING &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 // Get parameter 2 off the stack.
-                const char* param2 = luaL_checkstring(state, 2);
+                const char* param2 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 3 off the stack.
-                const char* param3 = luaL_checkstring(state, 3);
+                const char* param3 = ScriptController::getInstance()->getString(3, false);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Effect::createFromFile(param1, param2, param3);
-                object->owns = false;
-                luaL_getmetatable(state, "Effect");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Effect::createFromFile(param1, param2, param3);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Effect");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -1016,20 +864,28 @@ int lua_Effect_static_createFromSource(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TSTRING &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 // Get parameter 2 off the stack.
-                const char* param2 = luaL_checkstring(state, 2);
+                const char* param2 = ScriptController::getInstance()->getString(2, false);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Effect::createFromSource(param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "Effect");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Effect::createFromSource(param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Effect");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -1042,24 +898,32 @@ int lua_Effect_static_createFromSource(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TSTRING &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 // Get parameter 2 off the stack.
-                const char* param2 = luaL_checkstring(state, 2);
+                const char* param2 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 3 off the stack.
-                const char* param3 = luaL_checkstring(state, 3);
+                const char* param3 = ScriptController::getInstance()->getString(3, false);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Effect::createFromSource(param1, param2, param3);
-                object->owns = false;
-                luaL_getmetatable(state, "Effect");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Effect::createFromSource(param1, param2, param3);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Effect");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -1090,11 +954,19 @@ int lua_Effect_static_getCurrentEffect(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)Effect::getCurrentEffect();
-            object->owns = false;
-            luaL_getmetatable(state, "Effect");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)Effect::getCurrentEffect();
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = false;
+                luaL_getmetatable(state, "Effect");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;

+ 15 - 21
gameplay/src/lua/lua_FileSystem.cpp

@@ -47,7 +47,7 @@ int lua_FileSystem__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "FileSystem");
                 luaL_argcheck(state, userdata != NULL, 1, "'FileSystem' expected.");
@@ -87,10 +87,10 @@ int lua_FileSystem_static_fileExists(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 bool result = FileSystem::fileExists(param1);
 
@@ -154,25 +154,19 @@ int lua_FileSystem_static_loadResourceAliases(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 FileSystem::loadResourceAliases(param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Properties");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Properties' for parameter 1.");
-                    lua_error(state);
-                }
-                Properties* param1 = (Properties*)((ScriptController::LuaObject*)userdata1)->instance;
+                Properties* param1 = ScriptController::getInstance()->getObjectPointer<Properties>(1, "Properties", false);
 
                 FileSystem::loadResourceAliases(param1);
                 
@@ -205,10 +199,10 @@ int lua_FileSystem_static_readAll(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 const char* result = FileSystem::readAll(param1);
 
@@ -226,11 +220,11 @@ int lua_FileSystem_static_readAll(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
                 (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 // Get parameter 2 off the stack.
                 int* param2 = ScriptController::getInstance()->getIntPointer(2);
@@ -269,10 +263,10 @@ int lua_FileSystem_static_resolvePath(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 const char* result = FileSystem::resolvePath(param1);
 
@@ -308,10 +302,10 @@ int lua_FileSystem_static_setResourcePath(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 FileSystem::setResourcePath(param1);
                 

+ 5 - 5
gameplay/src/lua/lua_FlowLayout.cpp

@@ -42,7 +42,7 @@ int lua_FlowLayout__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "FlowLayout");
                 luaL_argcheck(state, userdata != NULL, 1, "'FlowLayout' expected.");
@@ -82,7 +82,7 @@ int lua_FlowLayout_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 FlowLayout* instance = getInstance(state);
                 instance->addRef();
@@ -116,7 +116,7 @@ int lua_FlowLayout_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 FlowLayout* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -153,7 +153,7 @@ int lua_FlowLayout_getType(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 FlowLayout* instance = getInstance(state);
                 Layout::Type result = instance->getType();
@@ -190,7 +190,7 @@ int lua_FlowLayout_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 FlowLayout* instance = getInstance(state);
                 instance->release();

文件差异内容过多而无法显示
+ 228 - 414
gameplay/src/lua/lua_Font.cpp


+ 1 - 1
gameplay/src/lua/lua_Font.h

@@ -10,7 +10,7 @@ int lua_Font_addRef(lua_State* state);
 int lua_Font_begin(lua_State* state);
 int lua_Font_createText(lua_State* state);
 int lua_Font_drawText(lua_State* state);
-int lua_Font_end(lua_State* state);
+int lua_Font_finish(lua_State* state);
 int lua_Font_getIndexAtLocation(lua_State* state);
 int lua_Font_getLocationAtIndex(lua_State* state);
 int lua_Font_getRefCount(lua_State* state);

+ 14 - 6
gameplay/src/lua/lua_FontGlyph.cpp

@@ -42,7 +42,7 @@ int lua_FontGlyph__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "FontGlyph");
                 luaL_argcheck(state, userdata != NULL, 1, "'FontGlyph' expected.");
@@ -82,11 +82,19 @@ int lua_FontGlyph__init(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)new Font::Glyph();
-            object->owns = true;
-            luaL_getmetatable(state, "FontGlyph");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)new Font::Glyph();
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = true;
+                luaL_getmetatable(state, "FontGlyph");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;

+ 17 - 9
gameplay/src/lua/lua_FontText.cpp

@@ -40,7 +40,7 @@ int lua_FontText__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "FontText");
                 luaL_argcheck(state, userdata != NULL, 1, "'FontText' expected.");
@@ -80,16 +80,24 @@ int lua_FontText__init(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new Font::Text(param1);
-                object->owns = true;
-                luaL_getmetatable(state, "FontText");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)new Font::Text(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "FontText");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -120,7 +128,7 @@ int lua_FontText_getText(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Font::Text* instance = getInstance(state);
                 const char* result = instance->getText();

文件差异内容过多而无法显示
+ 378 - 201
gameplay/src/lua/lua_Form.cpp


+ 6 - 2
gameplay/src/lua/lua_Form.h

@@ -31,10 +31,11 @@ int lua_Form_getControl(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_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);
@@ -51,11 +52,14 @@ 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_getType(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_insertControl(lua_State* state);
+int lua_Form_isContainer(lua_State* state);
 int lua_Form_isEnabled(lua_State* state);
 int lua_Form_isScrollBarsAutoHide(lua_State* state);
 int lua_Form_release(lua_State* state);
@@ -69,6 +73,7 @@ int lua_Form_setBounds(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_setFocusIndex(lua_State* state);
 int lua_Form_setFont(lua_State* state);
 int lua_Form_setFontSize(lua_State* state);
 int lua_Form_setImageColor(lua_State* state);
@@ -78,7 +83,6 @@ int lua_Form_setNode(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_setQuad(lua_State* state);
 int lua_Form_setScroll(lua_State* state);
 int lua_Form_setScrollBarsAutoHide(lua_State* state);
 int lua_Form_setSize(lua_State* state);

+ 92 - 70
gameplay/src/lua/lua_FrameBuffer.cpp

@@ -17,7 +17,7 @@ void luaRegister_FrameBuffer()
         {"bind", lua_FrameBuffer_bind},
         {"getDepthStencilTarget", lua_FrameBuffer_getDepthStencilTarget},
         {"getHeight", lua_FrameBuffer_getHeight},
-        {"getID", lua_FrameBuffer_getID},
+        {"getId", lua_FrameBuffer_getId},
         {"getRefCount", lua_FrameBuffer_getRefCount},
         {"getRenderTarget", lua_FrameBuffer_getRenderTarget},
         {"getWidth", lua_FrameBuffer_getWidth},
@@ -56,7 +56,7 @@ int lua_FrameBuffer__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "FrameBuffer");
                 luaL_argcheck(state, userdata != NULL, 1, "'FrameBuffer' expected.");
@@ -96,7 +96,7 @@ int lua_FrameBuffer_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 FrameBuffer* instance = getInstance(state);
                 instance->addRef();
@@ -130,7 +130,7 @@ int lua_FrameBuffer_bind(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 FrameBuffer* instance = getInstance(state);
                 instance->bind();
@@ -164,14 +164,22 @@ int lua_FrameBuffer_getDepthStencilTarget(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 FrameBuffer* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getDepthStencilTarget();
-                object->owns = false;
-                luaL_getmetatable(state, "DepthStencilTarget");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getDepthStencilTarget();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "DepthStencilTarget");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -202,7 +210,7 @@ int lua_FrameBuffer_getHeight(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 FrameBuffer* instance = getInstance(state);
                 unsigned int result = instance->getHeight();
@@ -229,7 +237,7 @@ int lua_FrameBuffer_getHeight(lua_State* state)
     return 0;
 }
 
-int lua_FrameBuffer_getID(lua_State* state)
+int lua_FrameBuffer_getId(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -239,10 +247,10 @@ int lua_FrameBuffer_getID(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 FrameBuffer* instance = getInstance(state);
-                const char* result = instance->getID();
+                const char* result = instance->getId();
 
                 // Push the return value onto the stack.
                 lua_pushstring(state, result);
@@ -276,7 +284,7 @@ int lua_FrameBuffer_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 FrameBuffer* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -313,14 +321,22 @@ int lua_FrameBuffer_getRenderTarget(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 FrameBuffer* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getRenderTarget();
-                object->owns = false;
-                luaL_getmetatable(state, "RenderTarget");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getRenderTarget();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "RenderTarget");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -333,18 +349,26 @@ int lua_FrameBuffer_getRenderTarget(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
                 unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
 
                 FrameBuffer* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getRenderTarget(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "RenderTarget");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getRenderTarget(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "RenderTarget");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -375,7 +399,7 @@ int lua_FrameBuffer_getWidth(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 FrameBuffer* instance = getInstance(state);
                 unsigned int result = instance->getWidth();
@@ -412,7 +436,7 @@ int lua_FrameBuffer_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 FrameBuffer* instance = getInstance(state);
                 instance->release();
@@ -446,17 +470,11 @@ int lua_FrameBuffer_setDepthStencilTarget(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "DepthStencilTarget");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'DepthStencilTarget' for parameter 2.");
-                    lua_error(state);
-                }
-                DepthStencilTarget* param1 = (DepthStencilTarget*)((ScriptController::LuaObject*)userdata2)->instance;
+                DepthStencilTarget* param1 = ScriptController::getInstance()->getObjectPointer<DepthStencilTarget>(2, "DepthStencilTarget", false);
 
                 FrameBuffer* instance = getInstance(state);
                 instance->setDepthStencilTarget(param1);
@@ -490,17 +508,11 @@ int lua_FrameBuffer_setRenderTarget(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "RenderTarget");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'RenderTarget' for parameter 2.");
-                    lua_error(state);
-                }
-                RenderTarget* param1 = (RenderTarget*)((ScriptController::LuaObject*)userdata2)->instance;
+                RenderTarget* param1 = ScriptController::getInstance()->getObjectPointer<RenderTarget>(2, "RenderTarget", false);
 
                 FrameBuffer* instance = getInstance(state);
                 instance->setRenderTarget(param1);
@@ -516,18 +528,12 @@ int lua_FrameBuffer_setRenderTarget(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "RenderTarget");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'RenderTarget' for parameter 2.");
-                    lua_error(state);
-                }
-                RenderTarget* param1 = (RenderTarget*)((ScriptController::LuaObject*)userdata2)->instance;
+                RenderTarget* param1 = ScriptController::getInstance()->getObjectPointer<RenderTarget>(2, "RenderTarget", false);
 
                 // Get parameter 2 off the stack.
                 unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
@@ -589,12 +595,12 @@ int lua_FrameBuffer_static_create(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TSTRING &&
+            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)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 // Get parameter 2 off the stack.
                 unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
@@ -602,11 +608,19 @@ int lua_FrameBuffer_static_create(lua_State* state)
                 // Get parameter 3 off the stack.
                 unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 3);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)FrameBuffer::create(param1, param2, param3);
-                object->owns = false;
-                luaL_getmetatable(state, "FrameBuffer");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)FrameBuffer::create(param1, param2, param3);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "FrameBuffer");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -637,16 +651,24 @@ int lua_FrameBuffer_static_getFrameBuffer(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)FrameBuffer::getFrameBuffer(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "FrameBuffer");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)FrameBuffer::getFrameBuffer(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "FrameBuffer");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }

+ 1 - 1
gameplay/src/lua/lua_FrameBuffer.h

@@ -10,7 +10,7 @@ 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_getId(lua_State* state);
 int lua_FrameBuffer_getRefCount(lua_State* state);
 int lua_FrameBuffer_getRenderTarget(lua_State* state);
 int lua_FrameBuffer_getWidth(lua_State* state);

+ 153 - 147
gameplay/src/lua/lua_Frustum.cpp

@@ -48,7 +48,7 @@ int lua_Frustum__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Frustum");
                 luaL_argcheck(state, userdata != NULL, 1, "'Frustum' expected.");
@@ -88,52 +88,64 @@ int lua_Frustum__init(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)new Frustum();
-            object->owns = true;
-            luaL_getmetatable(state, "Frustum");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)new Frustum();
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = true;
+                luaL_getmetatable(state, "Frustum");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;
         }
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Matrix");
-                if (!userdata1)
+                Matrix* param1 = ScriptController::getInstance()->getObjectPointer<Matrix>(1, "Matrix", true);
+
+                void* returnPtr = (void*)new Frustum(*param1);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Matrix' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "Frustum");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Matrix* param1 = (Matrix*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new Frustum(*param1);
-                object->owns = true;
-                luaL_getmetatable(state, "Frustum");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Frustum");
-                if (!userdata1)
+                Frustum* param1 = ScriptController::getInstance()->getObjectPointer<Frustum>(1, "Frustum", true);
+
+                void* returnPtr = (void*)new Frustum(*param1);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Frustum' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "Frustum");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Frustum* param1 = (Frustum*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new Frustum(*param1);
-                object->owns = true;
-                luaL_getmetatable(state, "Frustum");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -164,14 +176,22 @@ int lua_Frustum_getBottom(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Frustum* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getBottom());
-                object->owns = false;
-                luaL_getmetatable(state, "Plane");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getBottom());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Plane");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -202,17 +222,11 @@ int lua_Frustum_getCorners(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", false);
 
                 Frustum* instance = getInstance(state);
                 instance->getCorners(param1);
@@ -246,14 +260,22 @@ int lua_Frustum_getFar(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Frustum* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getFar());
-                object->owns = false;
-                luaL_getmetatable(state, "Plane");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getFar());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Plane");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -284,14 +306,22 @@ int lua_Frustum_getLeft(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Frustum* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getLeft());
-                object->owns = false;
-                luaL_getmetatable(state, "Plane");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getLeft());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Plane");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -322,17 +352,11 @@ int lua_Frustum_getMatrix(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Matrix");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Matrix' for parameter 2.");
-                    lua_error(state);
-                }
-                Matrix* param1 = (Matrix*)((ScriptController::LuaObject*)userdata2)->instance;
+                Matrix* param1 = ScriptController::getInstance()->getObjectPointer<Matrix>(2, "Matrix", false);
 
                 Frustum* instance = getInstance(state);
                 instance->getMatrix(param1);
@@ -366,14 +390,22 @@ int lua_Frustum_getNear(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Frustum* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getNear());
-                object->owns = false;
-                luaL_getmetatable(state, "Plane");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getNear());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Plane");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -404,14 +436,22 @@ int lua_Frustum_getRight(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Frustum* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getRight());
-                object->owns = false;
-                luaL_getmetatable(state, "Plane");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getRight());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Plane");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -442,14 +482,22 @@ int lua_Frustum_getTop(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Frustum* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getTop());
-                object->owns = false;
-                luaL_getmetatable(state, "Plane");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getTop());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Plane");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -480,17 +528,11 @@ int lua_Frustum_intersects(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 Frustum* instance = getInstance(state);
                 bool result = instance->intersects(*param1);
@@ -500,17 +542,11 @@ int lua_Frustum_intersects(lua_State* state)
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingSphere");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingSphere' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingSphere* param1 = (BoundingSphere*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingSphere* param1 = ScriptController::getInstance()->getObjectPointer<BoundingSphere>(2, "BoundingSphere", true);
 
                 Frustum* instance = getInstance(state);
                 bool result = instance->intersects(*param1);
@@ -520,17 +556,11 @@ int lua_Frustum_intersects(lua_State* state)
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingBox");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingBox' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingBox* param1 = (BoundingBox*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingBox* param1 = ScriptController::getInstance()->getObjectPointer<BoundingBox>(2, "BoundingBox", true);
 
                 Frustum* instance = getInstance(state);
                 bool result = instance->intersects(*param1);
@@ -540,17 +570,11 @@ int lua_Frustum_intersects(lua_State* state)
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Plane");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Plane' for parameter 2.");
-                    lua_error(state);
-                }
-                Plane* param1 = (Plane*)((ScriptController::LuaObject*)userdata2)->instance;
+                Plane* param1 = ScriptController::getInstance()->getObjectPointer<Plane>(2, "Plane", true);
 
                 Frustum* instance = getInstance(state);
                 float result = instance->intersects(*param1);
@@ -560,17 +584,11 @@ int lua_Frustum_intersects(lua_State* state)
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Ray");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Ray' for parameter 2.");
-                    lua_error(state);
-                }
-                Ray* param1 = (Ray*)((ScriptController::LuaObject*)userdata2)->instance;
+                Ray* param1 = ScriptController::getInstance()->getObjectPointer<Ray>(2, "Ray", true);
 
                 Frustum* instance = getInstance(state);
                 float result = instance->intersects(*param1);
@@ -607,34 +625,22 @@ int lua_Frustum_set(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Frustum");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Frustum' for parameter 2.");
-                    lua_error(state);
-                }
-                Frustum* param1 = (Frustum*)((ScriptController::LuaObject*)userdata2)->instance;
+                Frustum* param1 = ScriptController::getInstance()->getObjectPointer<Frustum>(2, "Frustum", true);
 
                 Frustum* instance = getInstance(state);
                 instance->set(*param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Matrix");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Matrix' for parameter 2.");
-                    lua_error(state);
-                }
-                Matrix* param1 = (Matrix*)((ScriptController::LuaObject*)userdata2)->instance;
+                Matrix* param1 = ScriptController::getInstance()->getObjectPointer<Matrix>(2, "Matrix", true);
 
                 Frustum* instance = getInstance(state);
                 instance->set(*param1);

+ 285 - 81
gameplay/src/lua/lua_Game.cpp

@@ -17,12 +17,15 @@ void luaRegister_Game()
         {"displayKeyboard", lua_Game_displayKeyboard},
         {"exit", lua_Game_exit},
         {"frame", lua_Game_frame},
+        {"gamepadEvent", lua_Game_gamepadEvent},
         {"getAccelerometerValues", lua_Game_getAccelerometerValues},
         {"getAnimationController", lua_Game_getAnimationController},
         {"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},
         {"getState", lua_Game_getState},
@@ -71,7 +74,7 @@ int lua_Game__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Game");
                 luaL_argcheck(state, userdata != NULL, 1, "'Game' expected.");
@@ -111,9 +114,9 @@ int lua_Game_clear(lua_State* state)
     {
         case 5:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TNUMBER &&
                 lua_type(state, 5) == LUA_TNUMBER)
             {
@@ -121,13 +124,7 @@ int lua_Game_clear(lua_State* state)
                 Game::ClearFlags param1 = (Game::ClearFlags)lua_enumFromString_GameClearFlags(luaL_checkstring(state, 2));
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector4");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector4' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector4* param2 = (Vector4*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector4* param2 = ScriptController::getInstance()->getObjectPointer<Vector4>(3, "Vector4", true);
 
                 // Get parameter 3 off the stack.
                 float param3 = (float)luaL_checknumber(state, 4);
@@ -167,7 +164,7 @@ int lua_Game_displayKeyboard(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
@@ -205,7 +202,7 @@ int lua_Game_exit(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
                 instance->exit();
@@ -239,7 +236,7 @@ int lua_Game_frame(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
                 instance->frame();
@@ -263,6 +260,48 @@ int lua_Game_frame(lua_State* state)
     return 0;
 }
 
+int lua_Game_gamepadEvent(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 3:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
+            {
+                // Get parameter 1 off the stack.
+                Gamepad::GamepadEvent param1 = (Gamepad::GamepadEvent)lua_enumFromString_GamepadGamepadEvent(luaL_checkstring(state, 2));
+
+                // Get parameter 2 off the stack.
+                Gamepad* param2 = ScriptController::getInstance()->getObjectPointer<Gamepad>(3, "Gamepad", false);
+
+                Game* instance = getInstance(state);
+                instance->gamepadEvent(param1, param2);
+                
+                return 0;
+            }
+            else
+            {
+                lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
+                lua_error(state);
+            }
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 3).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_Game_getAccelerometerValues(lua_State* state)
 {
     // Get the number of parameters.
@@ -273,7 +312,7 @@ int lua_Game_getAccelerometerValues(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA))
             {
@@ -315,14 +354,22 @@ int lua_Game_getAnimationController(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getAnimationController();
-                object->owns = false;
-                luaL_getmetatable(state, "AnimationController");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getAnimationController();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "AnimationController");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -353,14 +400,22 @@ int lua_Game_getAudioController(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getAudioController();
-                object->owns = false;
-                luaL_getmetatable(state, "AudioController");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getAudioController();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "AudioController");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -391,14 +446,22 @@ int lua_Game_getAudioListener(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getAudioListener();
-                object->owns = false;
-                luaL_getmetatable(state, "AudioListener");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getAudioListener();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "AudioListener");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -429,14 +492,22 @@ int lua_Game_getConfig(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getConfig();
-                object->owns = false;
-                luaL_getmetatable(state, "Properties");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getConfig();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Properties");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -467,7 +538,7 @@ int lua_Game_getFrameRate(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
                 unsigned int result = instance->getFrameRate();
@@ -494,6 +565,121 @@ int lua_Game_getFrameRate(lua_State* state)
     return 0;
 }
 
+int lua_Game_getGamepad(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 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
+            {
+                Game* instance = getInstance(state);
+                void* returnPtr = (void*)instance->getGamepad();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Gamepad");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
+                lua_error(state);
+            }
+            break;
+        }
+        case 2:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                lua_type(state, 2) == LUA_TNUMBER)
+            {
+                // Get parameter 1 off the stack.
+                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
+
+                Game* instance = getInstance(state);
+                void* returnPtr = (void*)instance->getGamepad(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Gamepad");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "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 2).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
+int lua_Game_getGamepadCount(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 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
+            {
+                Game* instance = getInstance(state);
+                unsigned int result = instance->getGamepadCount();
+
+                // Push the return value onto the stack.
+                lua_pushunsigned(state, result);
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "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_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_Game_getHeight(lua_State* state)
 {
     // Get the number of parameters.
@@ -504,7 +690,7 @@ int lua_Game_getHeight(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
                 unsigned int result = instance->getHeight();
@@ -541,14 +727,22 @@ int lua_Game_getPhysicsController(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getPhysicsController();
-                object->owns = false;
-                luaL_getmetatable(state, "PhysicsController");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getPhysicsController();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "PhysicsController");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -579,7 +773,7 @@ int lua_Game_getState(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
                 Game::State result = instance->getState();
@@ -616,14 +810,22 @@ int lua_Game_getViewport(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getViewport());
-                object->owns = false;
-                luaL_getmetatable(state, "Rectangle");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getViewport());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Rectangle");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -654,7 +856,7 @@ int lua_Game_getWidth(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
                 unsigned int result = instance->getWidth();
@@ -691,7 +893,7 @@ int lua_Game_isMultiTouch(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
                 bool result = instance->isMultiTouch();
@@ -728,8 +930,8 @@ int lua_Game_keyEvent(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -770,7 +972,7 @@ int lua_Game_menu(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
                 instance->menu();
@@ -804,8 +1006,8 @@ int lua_Game_mouseEvent(lua_State* state)
     {
         case 5:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 lua_type(state, 4) == LUA_TNUMBER &&
                 lua_type(state, 5) == LUA_TNUMBER)
@@ -857,7 +1059,7 @@ int lua_Game_pause(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
                 instance->pause();
@@ -891,7 +1093,7 @@ int lua_Game_resume(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
                 instance->resume();
@@ -925,7 +1127,7 @@ int lua_Game_run(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Game* instance = getInstance(state);
                 int result = instance->run();
@@ -962,7 +1164,7 @@ int lua_Game_setMultiTouch(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
@@ -1000,17 +1202,11 @@ int lua_Game_setViewport(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Rectangle");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Rectangle' for parameter 2.");
-                    lua_error(state);
-                }
-                Rectangle* param1 = (Rectangle*)((ScriptController::LuaObject*)userdata2)->instance;
+                Rectangle* param1 = ScriptController::getInstance()->getObjectPointer<Rectangle>(2, "Rectangle", true);
 
                 Game* instance = getInstance(state);
                 instance->setViewport(*param1);
@@ -1100,11 +1296,19 @@ int lua_Game_static_getInstance(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)Game::getInstance();
-            object->owns = false;
-            luaL_getmetatable(state, "Game");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)Game::getInstance();
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = false;
+                luaL_getmetatable(state, "Game");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;
@@ -1193,8 +1397,8 @@ int lua_Game_touchEvent(lua_State* state)
     {
         case 5:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 lua_type(state, 4) == LUA_TNUMBER &&
                 lua_type(state, 5) == LUA_TNUMBER)

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

@@ -10,12 +10,15 @@ int lua_Game_clear(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_getAccelerometerValues(lua_State* state);
 int lua_Game_getAnimationController(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_getState(lua_State* state);

+ 439 - 0
gameplay/src/lua/lua_Gamepad.cpp

@@ -0,0 +1,439 @@
+#include "Base.h"
+#include "ScriptController.h"
+#include "Gamepad.h"
+#include "lua_Gamepad.h"
+#include "lua_Global.h"
+
+namespace gameplay
+{
+
+void luaRegister_Gamepad()
+{
+    ScriptController* sc = ScriptController::getInstance();
+
+    const luaL_Reg lua_members[] = 
+    {
+        {"draw", lua_Gamepad_draw},
+        {"getButtonCount", lua_Gamepad_getButtonCount},
+        {"getButtonState", lua_Gamepad_getButtonState},
+        {"getForm", lua_Gamepad_getForm},
+        {"getId", lua_Gamepad_getId},
+        {"getJoystickCount", lua_Gamepad_getJoystickCount},
+        {"getJoystickValue", lua_Gamepad_getJoystickValue},
+        {"isJoystickActive", lua_Gamepad_isJoystickActive},
+        {"isVirtual", lua_Gamepad_isVirtual},
+        {"update", lua_Gamepad_update},
+        {NULL, NULL}
+    };
+    const luaL_Reg* lua_statics = NULL;
+    std::vector<std::string> scopePath;
+
+    sc->registerClass("Gamepad", lua_members, NULL, NULL, lua_statics, scopePath);
+}
+
+static Gamepad* getInstance(lua_State* state)
+{
+    void* userdata = luaL_checkudata(state, 1, "Gamepad");
+    luaL_argcheck(state, userdata != NULL, 1, "'Gamepad' expected.");
+    return (Gamepad*)((ScriptController::LuaObject*)userdata)->instance;
+}
+
+int lua_Gamepad_draw(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 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
+            {
+                Gamepad* instance = getInstance(state);
+                instance->draw();
+                
+                return 0;
+            }
+            else
+            {
+                lua_pushstring(state, "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_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
+int lua_Gamepad_getButtonCount(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 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
+            {
+                Gamepad* instance = getInstance(state);
+                unsigned int result = instance->getButtonCount();
+
+                // Push the return value onto the stack.
+                lua_pushunsigned(state, result);
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "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_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
+int lua_Gamepad_getButtonState(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, 1) == LUA_TNIL) &&
+                lua_type(state, 2) == LUA_TNUMBER)
+            {
+                // Get parameter 1 off the stack.
+                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
+
+                Gamepad* instance = getInstance(state);
+                Gamepad::ButtonState result = instance->getButtonState(param1);
+
+                // Push the return value onto the stack.
+                lua_pushstring(state, lua_stringFromEnum_GamepadButtonState(result).c_str());
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "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;
+}
+
+int lua_Gamepad_getForm(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 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
+            {
+                Gamepad* instance = getInstance(state);
+                void* returnPtr = (void*)instance->getForm();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Form");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "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_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
+int lua_Gamepad_getId(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 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
+            {
+                Gamepad* instance = getInstance(state);
+                const char* result = instance->getId();
+
+                // Push the return value onto the stack.
+                lua_pushstring(state, result);
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "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_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
+int lua_Gamepad_getJoystickCount(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 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
+            {
+                Gamepad* instance = getInstance(state);
+                unsigned int result = instance->getJoystickCount();
+
+                // Push the return value onto the stack.
+                lua_pushunsigned(state, result);
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "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_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
+int lua_Gamepad_getJoystickValue(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, 1) == LUA_TNIL) &&
+                lua_type(state, 2) == LUA_TNUMBER)
+            {
+                // Get parameter 1 off the stack.
+                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
+
+                Gamepad* instance = getInstance(state);
+                void* returnPtr = (void*)&(instance->getJoystickValue(param1));
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Vector2");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "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;
+}
+
+int lua_Gamepad_isJoystickActive(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, 1) == LUA_TNIL) &&
+                lua_type(state, 2) == LUA_TNUMBER)
+            {
+                // Get parameter 1 off the stack.
+                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
+
+                Gamepad* instance = getInstance(state);
+                bool result = instance->isJoystickActive(param1);
+
+                // Push the return value onto the stack.
+                lua_pushboolean(state, result);
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "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;
+}
+
+int lua_Gamepad_isVirtual(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 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
+            {
+                Gamepad* instance = getInstance(state);
+                bool result = instance->isVirtual();
+
+                // Push the return value onto the stack.
+                lua_pushboolean(state, result);
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "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_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
+int lua_Gamepad_update(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, 1) == LUA_TNIL) &&
+                lua_type(state, 2) == LUA_TNUMBER)
+            {
+                // Get parameter 1 off the stack.
+                float param1 = (float)luaL_checknumber(state, 2);
+
+                Gamepad* instance = getInstance(state);
+                instance->update(param1);
+                
+                return 0;
+            }
+            else
+            {
+                lua_pushstring(state, "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;
+}
+
+}

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

@@ -0,0 +1,23 @@
+#ifndef LUA_GAMEPAD_H_
+#define LUA_GAMEPAD_H_
+
+namespace gameplay
+{
+
+// Lua bindings for Gamepad.
+int lua_Gamepad_draw(lua_State* state);
+int lua_Gamepad_getButtonCount(lua_State* state);
+int lua_Gamepad_getButtonState(lua_State* state);
+int lua_Gamepad_getForm(lua_State* state);
+int lua_Gamepad_getId(lua_State* state);
+int lua_Gamepad_getJoystickCount(lua_State* state);
+int lua_Gamepad_getJoystickValue(lua_State* state);
+int lua_Gamepad_isJoystickActive(lua_State* state);
+int lua_Gamepad_isVirtual(lua_State* state);
+int lua_Gamepad_update(lua_State* state);
+
+void luaRegister_Gamepad();
+
+}
+
+#endif

+ 58 - 2
gameplay/src/lua/lua_Global.cpp

@@ -321,6 +321,22 @@ void luaRegister_lua_Global()
         sc->registerConstantString("PAUSED", "PAUSED", scopePath);
     }
 
+    // Register enumeration Gamepad::ButtonState.
+    {
+        std::vector<std::string> scopePath;
+        scopePath.push_back("Gamepad");
+        sc->registerConstantString("BUTTON_PRESSED", "BUTTON_PRESSED", scopePath);
+        sc->registerConstantString("BUTTON_RELEASED", "BUTTON_RELEASED", scopePath);
+    }
+
+    // Register enumeration Gamepad::GamepadEvent.
+    {
+        std::vector<std::string> scopePath;
+        scopePath.push_back("Gamepad");
+        sc->registerConstantString("ATTACHED_EVENT", "ATTACHED_EVENT", scopePath);
+        sc->registerConstantString("DETACHED_EVENT", "DETACHED_EVENT", scopePath);
+    }
+
     // Register enumeration Image::Format.
     {
         std::vector<std::string> scopePath;
@@ -794,10 +810,10 @@ int lua__printError(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 printError(param1);
                 
@@ -1444,6 +1460,46 @@ std::string lua_stringFromEnum_GameState(Game::State e)
     return std::string();
 }
 
+Gamepad::ButtonState lua_enumFromString_GamepadButtonState(const char* s)
+{
+    if (strcmp(s, "BUTTON_PRESSED") == 0)
+        return Gamepad::BUTTON_PRESSED;
+    if (strcmp(s, "BUTTON_RELEASED") == 0)
+        return Gamepad::BUTTON_RELEASED;
+    GP_ERROR("Invalid enumeration value '%s' for enumeration Gamepad::ButtonState.", s);
+    return Gamepad::BUTTON_PRESSED;
+}
+
+std::string lua_stringFromEnum_GamepadButtonState(Gamepad::ButtonState e)
+{
+    if (e == Gamepad::BUTTON_PRESSED)
+        return std::string("BUTTON_PRESSED");
+    if (e == Gamepad::BUTTON_RELEASED)
+        return std::string("BUTTON_RELEASED");
+    GP_ERROR("Invalid enumeration value '%d' for enumeration Gamepad::ButtonState.", e);
+    return std::string();
+}
+
+Gamepad::GamepadEvent lua_enumFromString_GamepadGamepadEvent(const char* s)
+{
+    if (strcmp(s, "ATTACHED_EVENT") == 0)
+        return Gamepad::ATTACHED_EVENT;
+    if (strcmp(s, "DETACHED_EVENT") == 0)
+        return Gamepad::DETACHED_EVENT;
+    GP_ERROR("Invalid enumeration value '%s' for enumeration Gamepad::GamepadEvent.", s);
+    return Gamepad::ATTACHED_EVENT;
+}
+
+std::string lua_stringFromEnum_GamepadGamepadEvent(Gamepad::GamepadEvent e)
+{
+    if (e == Gamepad::ATTACHED_EVENT)
+        return std::string("ATTACHED_EVENT");
+    if (e == Gamepad::DETACHED_EVENT)
+        return std::string("DETACHED_EVENT");
+    GP_ERROR("Invalid enumeration value '%d' for enumeration Gamepad::GamepadEvent.", e);
+    return std::string();
+}
+
 Image::Format lua_enumFromString_ImageFormat(const char* s)
 {
     if (strcmp(s, "RGB") == 0)

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

@@ -17,6 +17,7 @@
 #include "C:/git/gameplay/gameplay/src/BoundingBox.h"
 #include "C:/git/gameplay/gameplay/src/BoundingSphere.h"
 #include "C:/git/gameplay/gameplay/src/Image.h"
+#include "C:/git/gameplay/gameplay/src/Joystick.h"
 #include "C:/git/gameplay/gameplay/src/Matrix.h"
 #include "C:/git/gameplay/gameplay/src/MeshBatch.h"
 #include "C:/git/gameplay/gameplay/src/PhysicsConstraint.h"
@@ -44,7 +45,9 @@
 #include "FrameBuffer.h"
 #include "Frustum.h"
 #include "Game.h"
+#include "Gamepad.h"
 #include "Image.h"
+#include "Joystick.h"
 #include "Keyboard.h"
 #include "Label.h"
 #include "Layout.h"
@@ -131,6 +134,10 @@ Game::ClearFlags lua_enumFromString_GameClearFlags(const char* s);
 std::string lua_stringFromEnum_GameClearFlags(Game::ClearFlags e);
 Game::State lua_enumFromString_GameState(const char* s);
 std::string lua_stringFromEnum_GameState(Game::State e);
+Gamepad::ButtonState lua_enumFromString_GamepadButtonState(const char* s);
+std::string lua_stringFromEnum_GamepadButtonState(Gamepad::ButtonState e);
+Gamepad::GamepadEvent lua_enumFromString_GamepadGamepadEvent(const char* s);
+std::string lua_stringFromEnum_GamepadGamepadEvent(Gamepad::GamepadEvent e);
 Image::Format lua_enumFromString_ImageFormat(const char* s);
 std::string lua_stringFromEnum_ImageFormat(Image::Format e);
 Keyboard::Key lua_enumFromString_KeyboardKey(const char* s);

+ 22 - 14
gameplay/src/lua/lua_Image.cpp

@@ -48,7 +48,7 @@ int lua_Image__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Image");
                 luaL_argcheck(state, userdata != NULL, 1, "'Image' expected.");
@@ -88,7 +88,7 @@ int lua_Image_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Image* instance = getInstance(state);
                 instance->addRef();
@@ -122,7 +122,7 @@ int lua_Image_getFormat(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Image* instance = getInstance(state);
                 Image::Format result = instance->getFormat();
@@ -159,7 +159,7 @@ int lua_Image_getHeight(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Image* instance = getInstance(state);
                 unsigned int result = instance->getHeight();
@@ -196,7 +196,7 @@ int lua_Image_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Image* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -233,7 +233,7 @@ int lua_Image_getWidth(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Image* instance = getInstance(state);
                 unsigned int result = instance->getWidth();
@@ -270,7 +270,7 @@ int lua_Image_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Image* instance = getInstance(state);
                 instance->release();
@@ -304,16 +304,24 @@ int lua_Image_static_create(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Image::create(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Image");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Image::create(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Image");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }

文件差异内容过多而无法显示
+ 379 - 243
gameplay/src/lua/lua_Joint.cpp


文件差异内容过多而无法显示
+ 382 - 198
gameplay/src/lua/lua_Joystick.cpp


+ 6 - 1
gameplay/src/lua/lua_Joystick.h

@@ -28,10 +28,11 @@ int lua_Joystick_getConsumeInputEvents(lua_State* state);
 int lua_Joystick_getCursorColor(lua_State* state);
 int lua_Joystick_getCursorRegion(lua_State* state);
 int lua_Joystick_getCursorUVs(lua_State* state);
+int lua_Joystick_getFocusIndex(lua_State* state);
 int lua_Joystick_getFont(lua_State* state);
 int lua_Joystick_getFontSize(lua_State* state);
 int lua_Joystick_getHeight(lua_State* state);
-int lua_Joystick_getID(lua_State* state);
+int lua_Joystick_getId(lua_State* state);
 int lua_Joystick_getImageColor(lua_State* state);
 int lua_Joystick_getImageRegion(lua_State* state);
 int lua_Joystick_getImageUVs(lua_State* state);
@@ -47,12 +48,14 @@ int lua_Joystick_getStyle(lua_State* state);
 int lua_Joystick_getTextAlignment(lua_State* state);
 int lua_Joystick_getTextColor(lua_State* state);
 int lua_Joystick_getTextRightToLeft(lua_State* state);
+int lua_Joystick_getType(lua_State* state);
 int lua_Joystick_getValue(lua_State* state);
 int lua_Joystick_getWidth(lua_State* state);
 int lua_Joystick_getX(lua_State* state);
 int lua_Joystick_getY(lua_State* state);
 int lua_Joystick_getZIndex(lua_State* state);
 int lua_Joystick_isAbsolute(lua_State* state);
+int lua_Joystick_isContainer(lua_State* state);
 int lua_Joystick_isEnabled(lua_State* state);
 int lua_Joystick_release(lua_State* state);
 int lua_Joystick_setAbsolute(lua_State* state);
@@ -65,6 +68,7 @@ int lua_Joystick_setBounds(lua_State* state);
 int lua_Joystick_setConsumeInputEvents(lua_State* state);
 int lua_Joystick_setCursorColor(lua_State* state);
 int lua_Joystick_setCursorRegion(lua_State* state);
+int lua_Joystick_setFocusIndex(lua_State* state);
 int lua_Joystick_setFont(lua_State* state);
 int lua_Joystick_setFontSize(lua_State* state);
 int lua_Joystick_setImageColor(lua_State* state);
@@ -90,6 +94,7 @@ int lua_Joystick_static_ANIMATE_POSITION_Y(lua_State* state);
 int lua_Joystick_static_ANIMATE_SIZE(lua_State* state);
 int lua_Joystick_static_ANIMATE_SIZE_HEIGHT(lua_State* state);
 int lua_Joystick_static_ANIMATE_SIZE_WIDTH(lua_State* state);
+int lua_Joystick_static_create(lua_State* state);
 
 void luaRegister_Joystick();
 

+ 1 - 1
gameplay/src/lua/lua_Keyboard.cpp

@@ -38,7 +38,7 @@ int lua_Keyboard__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Keyboard");
                 luaL_argcheck(state, userdata != NULL, 1, "'Keyboard' expected.");

文件差异内容过多而无法显示
+ 382 - 198
gameplay/src/lua/lua_Label.cpp


+ 6 - 1
gameplay/src/lua/lua_Label.h

@@ -28,10 +28,11 @@ int lua_Label_getConsumeInputEvents(lua_State* state);
 int lua_Label_getCursorColor(lua_State* state);
 int lua_Label_getCursorRegion(lua_State* state);
 int lua_Label_getCursorUVs(lua_State* state);
+int lua_Label_getFocusIndex(lua_State* state);
 int lua_Label_getFont(lua_State* state);
 int lua_Label_getFontSize(lua_State* state);
 int lua_Label_getHeight(lua_State* state);
-int lua_Label_getID(lua_State* state);
+int lua_Label_getId(lua_State* state);
 int lua_Label_getImageColor(lua_State* state);
 int lua_Label_getImageRegion(lua_State* state);
 int lua_Label_getImageUVs(lua_State* state);
@@ -47,10 +48,12 @@ int lua_Label_getText(lua_State* state);
 int lua_Label_getTextAlignment(lua_State* state);
 int lua_Label_getTextColor(lua_State* state);
 int lua_Label_getTextRightToLeft(lua_State* state);
+int lua_Label_getType(lua_State* state);
 int lua_Label_getWidth(lua_State* state);
 int lua_Label_getX(lua_State* state);
 int lua_Label_getY(lua_State* state);
 int lua_Label_getZIndex(lua_State* state);
+int lua_Label_isContainer(lua_State* state);
 int lua_Label_isEnabled(lua_State* state);
 int lua_Label_release(lua_State* state);
 int lua_Label_setAlignment(lua_State* state);
@@ -62,6 +65,7 @@ int lua_Label_setBounds(lua_State* state);
 int lua_Label_setConsumeInputEvents(lua_State* state);
 int lua_Label_setCursorColor(lua_State* state);
 int lua_Label_setCursorRegion(lua_State* state);
+int lua_Label_setFocusIndex(lua_State* state);
 int lua_Label_setFont(lua_State* state);
 int lua_Label_setFontSize(lua_State* state);
 int lua_Label_setImageColor(lua_State* state);
@@ -87,6 +91,7 @@ int lua_Label_static_ANIMATE_POSITION_Y(lua_State* state);
 int lua_Label_static_ANIMATE_SIZE(lua_State* state);
 int lua_Label_static_ANIMATE_SIZE_HEIGHT(lua_State* state);
 int lua_Label_static_ANIMATE_SIZE_WIDTH(lua_State* state);
+int lua_Label_static_create(lua_State* state);
 
 void luaRegister_Label();
 

+ 5 - 5
gameplay/src/lua/lua_Layout.cpp

@@ -42,7 +42,7 @@ int lua_Layout__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Layout");
                 luaL_argcheck(state, userdata != NULL, 1, "'Layout' expected.");
@@ -82,7 +82,7 @@ int lua_Layout_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Layout* instance = getInstance(state);
                 instance->addRef();
@@ -116,7 +116,7 @@ int lua_Layout_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Layout* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -153,7 +153,7 @@ int lua_Layout_getType(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Layout* instance = getInstance(state);
                 Layout::Type result = instance->getType();
@@ -190,7 +190,7 @@ int lua_Layout_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Layout* instance = getInstance(state);
                 instance->release();

+ 89 - 73
gameplay/src/lua/lua_Light.cpp

@@ -60,7 +60,7 @@ int lua_Light__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Light");
                 luaL_argcheck(state, userdata != NULL, 1, "'Light' expected.");
@@ -100,7 +100,7 @@ int lua_Light_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Light* instance = getInstance(state);
                 instance->addRef();
@@ -134,14 +134,22 @@ int lua_Light_getColor(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Light* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getColor());
-                object->owns = false;
-                luaL_getmetatable(state, "Vector3");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getColor());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Vector3");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -172,7 +180,7 @@ int lua_Light_getInnerAngle(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Light* instance = getInstance(state);
                 float result = instance->getInnerAngle();
@@ -209,7 +217,7 @@ int lua_Light_getInnerAngleCos(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Light* instance = getInstance(state);
                 float result = instance->getInnerAngleCos();
@@ -246,7 +254,7 @@ int lua_Light_getLightType(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Light* instance = getInstance(state);
                 Light::Type result = instance->getLightType();
@@ -283,14 +291,22 @@ int lua_Light_getNode(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Light* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getNode();
-                object->owns = false;
-                luaL_getmetatable(state, "Node");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getNode();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Node");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -321,7 +337,7 @@ int lua_Light_getOuterAngle(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Light* instance = getInstance(state);
                 float result = instance->getOuterAngle();
@@ -358,7 +374,7 @@ int lua_Light_getOuterAngleCos(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Light* instance = getInstance(state);
                 float result = instance->getOuterAngleCos();
@@ -395,7 +411,7 @@ int lua_Light_getRange(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Light* instance = getInstance(state);
                 float result = instance->getRange();
@@ -432,7 +448,7 @@ int lua_Light_getRangeInverse(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Light* instance = getInstance(state);
                 float result = instance->getRangeInverse();
@@ -469,7 +485,7 @@ int lua_Light_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Light* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -506,7 +522,7 @@ int lua_Light_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Light* instance = getInstance(state);
                 instance->release();
@@ -540,17 +556,11 @@ int lua_Light_setColor(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 Light* instance = getInstance(state);
                 instance->setColor(*param1);
@@ -584,7 +594,7 @@ int lua_Light_setInnerAngle(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -622,7 +632,7 @@ int lua_Light_setOuterAngle(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -660,7 +670,7 @@ int lua_Light_setRange(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -698,22 +708,24 @@ int lua_Light_static_createDirectional(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Vector3");
-                if (!userdata1)
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(1, "Vector3", true);
+
+                void* returnPtr = (void*)Light::createDirectional(*param1);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Light");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Light::createDirectional(*param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Light");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -744,26 +756,28 @@ int lua_Light_static_createPoint(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Vector3");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 1.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata1)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(1, "Vector3", true);
 
                 // Get parameter 2 off the stack.
                 float param2 = (float)luaL_checknumber(state, 2);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Light::createPoint(*param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "Light");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Light::createPoint(*param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Light");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -794,19 +808,13 @@ int lua_Light_static_createSpot(lua_State* state)
     {
         case 4:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || 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.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Vector3");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 1.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata1)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(1, "Vector3", true);
 
                 // Get parameter 2 off the stack.
                 float param2 = (float)luaL_checknumber(state, 2);
@@ -817,11 +825,19 @@ int lua_Light_static_createSpot(lua_State* state)
                 // Get parameter 4 off the stack.
                 float param4 = (float)luaL_checknumber(state, 4);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Light::createSpot(*param1, param2, param3, param4);
-                object->owns = false;
-                luaL_getmetatable(state, "Light");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Light::createSpot(*param1, param2, param3, param4);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Light");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }

+ 190 - 126
gameplay/src/lua/lua_Material.cpp

@@ -53,7 +53,7 @@ int lua_Material__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Material");
                 luaL_argcheck(state, userdata != NULL, 1, "'Material' expected.");
@@ -93,7 +93,7 @@ int lua_Material_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Material* instance = getInstance(state);
                 instance->addRef();
@@ -127,24 +127,26 @@ int lua_Material_clone(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "NodeCloneContext");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'NodeCloneContext' for parameter 2.");
-                    lua_error(state);
-                }
-                NodeCloneContext* param1 = (NodeCloneContext*)((ScriptController::LuaObject*)userdata2)->instance;
+                NodeCloneContext* param1 = ScriptController::getInstance()->getObjectPointer<NodeCloneContext>(2, "NodeCloneContext", true);
 
                 Material* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->clone(*param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->clone(*param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -175,18 +177,26 @@ int lua_Material_getParameter(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Material* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getParameter(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "MaterialParameter");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getParameter(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MaterialParameter");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -217,7 +227,7 @@ int lua_Material_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Material* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -254,14 +264,22 @@ int lua_Material_getStateBlock(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Material* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getStateBlock();
-                object->owns = false;
-                luaL_getmetatable(state, "RenderStateStateBlock");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getStateBlock();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "RenderStateStateBlock");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -292,14 +310,22 @@ int lua_Material_getTechnique(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Material* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getTechnique();
-                object->owns = false;
-                luaL_getmetatable(state, "Technique");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getTechnique();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Technique");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -312,33 +338,49 @@ int lua_Material_getTechnique(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
                 unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
 
                 Material* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getTechnique(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Technique");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getTechnique(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Technique");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Material* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getTechnique(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Technique");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getTechnique(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Technique");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -369,7 +411,7 @@ int lua_Material_getTechniqueCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Material* instance = getInstance(state);
                 unsigned int result = instance->getTechniqueCount();
@@ -406,7 +448,7 @@ int lua_Material_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Material* instance = getInstance(state);
                 instance->release();
@@ -440,12 +482,12 @@ int lua_Material_setParameterAutoBinding(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
                 RenderState::AutoBinding param2 = (RenderState::AutoBinding)lua_enumFromString_RenderStateAutoBinding(luaL_checkstring(state, 3));
@@ -455,15 +497,15 @@ int lua_Material_setParameterAutoBinding(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
-                const char* param2 = luaL_checkstring(state, 3);
+                const char* param2 = ScriptController::getInstance()->getString(3, false);
 
                 Material* instance = getInstance(state);
                 instance->setParameterAutoBinding(param1, param2);
@@ -497,17 +539,11 @@ int lua_Material_setStateBlock(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "RenderStateStateBlock");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'RenderState::StateBlock' for parameter 2.");
-                    lua_error(state);
-                }
-                RenderState::StateBlock* param1 = (RenderState::StateBlock*)((ScriptController::LuaObject*)userdata2)->instance;
+                RenderState::StateBlock* param1 = ScriptController::getInstance()->getObjectPointer<RenderState::StateBlock>(2, "RenderStateStateBlock", false);
 
                 Material* instance = getInstance(state);
                 instance->setStateBlock(param1);
@@ -541,7 +577,7 @@ int lua_Material_setTechnique(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -552,11 +588,11 @@ int lua_Material_setTechnique(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Material* instance = getInstance(state);
                 instance->setTechnique(param1);
@@ -590,54 +626,66 @@ int lua_Material_static_create(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Material::create(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Material::create(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Properties");
-                if (!userdata1)
+                Properties* param1 = ScriptController::getInstance()->getObjectPointer<Properties>(1, "Properties", false);
+
+                void* returnPtr = (void*)Material::create(param1);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Properties' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Properties* param1 = (Properties*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Material::create(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Effect");
-                if (!userdata1)
+                Effect* param1 = ScriptController::getInstance()->getObjectPointer<Effect>(1, "Effect", false);
+
+                void* returnPtr = (void*)Material::create(param1);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Effect' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Effect* param1 = (Effect*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Material::create(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -650,20 +698,28 @@ int lua_Material_static_create(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TSTRING &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 // Get parameter 2 off the stack.
-                const char* param2 = luaL_checkstring(state, 2);
+                const char* param2 = ScriptController::getInstance()->getString(2, false);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Material::create(param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Material::create(param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -676,24 +732,32 @@ int lua_Material_static_create(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TSTRING &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 1);
+                const char* param1 = ScriptController::getInstance()->getString(1, false);
 
                 // Get parameter 2 off the stack.
-                const char* param2 = luaL_checkstring(state, 2);
+                const char* param2 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 3 off the stack.
-                const char* param3 = luaL_checkstring(state, 3);
+                const char* param3 = ScriptController::getInstance()->getString(3, false);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Material::create(param1, param2, param3);
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Material::create(param1, param2, param3);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }

+ 214 - 244
gameplay/src/lua/lua_MaterialParameter.cpp

@@ -55,7 +55,7 @@ int lua_MaterialParameter__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "MaterialParameter");
                 luaL_argcheck(state, userdata != NULL, 1, "'MaterialParameter' expected.");
@@ -95,7 +95,7 @@ int lua_MaterialParameter_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MaterialParameter* instance = getInstance(state);
                 instance->addRef();
@@ -129,47 +129,57 @@ int lua_MaterialParameter_createAnimation(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
-                const char* param2 = luaL_checkstring(state, 3);
+                const char* param2 = ScriptController::getInstance()->getString(3, false);
 
                 MaterialParameter* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->createAnimation(param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->createAnimation(param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Properties");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Properties' for parameter 3.");
-                    lua_error(state);
-                }
-                Properties* param2 = (Properties*)((ScriptController::LuaObject*)userdata3)->instance;
+                Properties* param2 = ScriptController::getInstance()->getObjectPointer<Properties>(3, "Properties", false);
 
                 MaterialParameter* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->createAnimation(param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->createAnimation(param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -182,16 +192,16 @@ int lua_MaterialParameter_createAnimation(lua_State* state)
         }
         case 7:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 lua_type(state, 4) == LUA_TNUMBER &&
                 (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 6) == LUA_TTABLE || lua_type(state, 6) == LUA_TLIGHTUSERDATA) &&
-                lua_type(state, 7) == LUA_TSTRING)
+                (lua_type(state, 7) == LUA_TSTRING || lua_type(state, 7) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
                 int param2 = (int)luaL_checkint(state, 3);
@@ -209,11 +219,19 @@ int lua_MaterialParameter_createAnimation(lua_State* state)
                 Curve::InterpolationType param6 = (Curve::InterpolationType)lua_enumFromString_CurveInterpolationType(luaL_checkstring(state, 7));
 
                 MaterialParameter* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->createAnimation(param1, param2, param3, param4, param5, param6);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->createAnimation(param1, param2, param3, param4, param5, param6);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -226,18 +244,18 @@ int lua_MaterialParameter_createAnimation(lua_State* state)
         }
         case 9:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 lua_type(state, 4) == LUA_TNUMBER &&
                 (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 6) == LUA_TTABLE || lua_type(state, 6) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 7) == LUA_TTABLE || lua_type(state, 7) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 8) == LUA_TTABLE || lua_type(state, 8) == LUA_TLIGHTUSERDATA) &&
-                lua_type(state, 9) == LUA_TSTRING)
+                (lua_type(state, 9) == LUA_TSTRING || lua_type(state, 9) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
                 int param2 = (int)luaL_checkint(state, 3);
@@ -261,11 +279,19 @@ int lua_MaterialParameter_createAnimation(lua_State* state)
                 Curve::InterpolationType param8 = (Curve::InterpolationType)lua_enumFromString_CurveInterpolationType(luaL_checkstring(state, 9));
 
                 MaterialParameter* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->createAnimation(param1, param2, param3, param4, param5, param6, param7, param8);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->createAnimation(param1, param2, param3, param4, param5, param6, param7, param8);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -296,16 +322,16 @@ int lua_MaterialParameter_createAnimationFromBy(lua_State* state)
     {
         case 7:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA) &&
-                lua_type(state, 6) == LUA_TSTRING &&
+                (lua_type(state, 6) == LUA_TSTRING || lua_type(state, 6) == LUA_TNIL) &&
                 lua_type(state, 7) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
                 int param2 = (int)luaL_checkint(state, 3);
@@ -323,11 +349,19 @@ int lua_MaterialParameter_createAnimationFromBy(lua_State* state)
                 unsigned long param6 = (unsigned long)luaL_checkunsigned(state, 7);
 
                 MaterialParameter* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->createAnimationFromBy(param1, param2, param3, param4, param5, param6);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->createAnimationFromBy(param1, param2, param3, param4, param5, param6);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -358,16 +392,16 @@ int lua_MaterialParameter_createAnimationFromTo(lua_State* state)
     {
         case 7:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER &&
                 (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
                 (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA) &&
-                lua_type(state, 6) == LUA_TSTRING &&
+                (lua_type(state, 6) == LUA_TSTRING || lua_type(state, 6) == LUA_TNIL) &&
                 lua_type(state, 7) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
                 int param2 = (int)luaL_checkint(state, 3);
@@ -385,11 +419,19 @@ int lua_MaterialParameter_createAnimationFromTo(lua_State* state)
                 unsigned long param6 = (unsigned long)luaL_checkunsigned(state, 7);
 
                 MaterialParameter* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->createAnimationFromTo(param1, param2, param3, param4, param5, param6);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->createAnimationFromTo(param1, param2, param3, param4, param5, param6);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -420,7 +462,7 @@ int lua_MaterialParameter_destroyAnimation(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MaterialParameter* instance = getInstance(state);
                 instance->destroyAnimation();
@@ -436,11 +478,11 @@ int lua_MaterialParameter_destroyAnimation(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 MaterialParameter* instance = getInstance(state);
                 instance->destroyAnimation(param1);
@@ -474,14 +516,22 @@ int lua_MaterialParameter_getAnimation(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MaterialParameter* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getAnimation();
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getAnimation();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -494,18 +544,26 @@ int lua_MaterialParameter_getAnimation(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 MaterialParameter* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getAnimation(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getAnimation(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -536,7 +594,7 @@ int lua_MaterialParameter_getAnimationPropertyComponentCount(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -577,21 +635,15 @@ int lua_MaterialParameter_getAnimationPropertyValue(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
                 int param1 = (int)luaL_checkint(state, 2);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "AnimationValue");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'AnimationValue' for parameter 3.");
-                    lua_error(state);
-                }
-                AnimationValue* param2 = (AnimationValue*)((ScriptController::LuaObject*)userdata3)->instance;
+                AnimationValue* param2 = ScriptController::getInstance()->getObjectPointer<AnimationValue>(3, "AnimationValue", false);
 
                 MaterialParameter* instance = getInstance(state);
                 instance->getAnimationPropertyValue(param1, param2);
@@ -625,7 +677,7 @@ int lua_MaterialParameter_getName(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MaterialParameter* instance = getInstance(state);
                 const char* result = instance->getName();
@@ -662,7 +714,7 @@ int lua_MaterialParameter_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MaterialParameter* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -699,7 +751,7 @@ int lua_MaterialParameter_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MaterialParameter* instance = getInstance(state);
                 instance->release();
@@ -733,21 +785,15 @@ int lua_MaterialParameter_setAnimationPropertyValue(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
                 int param1 = (int)luaL_checkint(state, 2);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "AnimationValue");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'AnimationValue' for parameter 3.");
-                    lua_error(state);
-                }
-                AnimationValue* param2 = (AnimationValue*)((ScriptController::LuaObject*)userdata3)->instance;
+                AnimationValue* param2 = ScriptController::getInstance()->getObjectPointer<AnimationValue>(3, "AnimationValue", false);
 
                 MaterialParameter* instance = getInstance(state);
                 instance->setAnimationPropertyValue(param1, param2);
@@ -763,22 +809,16 @@ int lua_MaterialParameter_setAnimationPropertyValue(lua_State* state)
         }
         case 4:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
                 int param1 = (int)luaL_checkint(state, 2);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "AnimationValue");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'AnimationValue' for parameter 3.");
-                    lua_error(state);
-                }
-                AnimationValue* param2 = (AnimationValue*)((ScriptController::LuaObject*)userdata3)->instance;
+                AnimationValue* param2 = ScriptController::getInstance()->getObjectPointer<AnimationValue>(3, "AnimationValue", false);
 
                 // Get parameter 3 off the stack.
                 float param3 = (float)luaL_checknumber(state, 4);
@@ -815,7 +855,7 @@ int lua_MaterialParameter_setValue(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -826,7 +866,7 @@ int lua_MaterialParameter_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -837,7 +877,7 @@ int lua_MaterialParameter_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA))
             {
                 // Get parameter 1 off the stack.
@@ -848,7 +888,7 @@ int lua_MaterialParameter_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA))
             {
                 // Get parameter 1 off the stack.
@@ -859,153 +899,99 @@ int lua_MaterialParameter_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector2");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector2' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector2* param1 = (Vector2*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector2* param1 = ScriptController::getInstance()->getObjectPointer<Vector2>(2, "Vector2", true);
 
                 MaterialParameter* instance = getInstance(state);
                 instance->setValue(*param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector2");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector2' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector2* param1 = (Vector2*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector2* param1 = ScriptController::getInstance()->getObjectPointer<Vector2>(2, "Vector2", false);
 
                 MaterialParameter* instance = getInstance(state);
                 instance->setValue(param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 MaterialParameter* instance = getInstance(state);
                 instance->setValue(*param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", false);
 
                 MaterialParameter* instance = getInstance(state);
                 instance->setValue(param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector4");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector4' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector4* param1 = (Vector4*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector4* param1 = ScriptController::getInstance()->getObjectPointer<Vector4>(2, "Vector4", true);
 
                 MaterialParameter* instance = getInstance(state);
                 instance->setValue(*param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector4");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector4' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector4* param1 = (Vector4*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector4* param1 = ScriptController::getInstance()->getObjectPointer<Vector4>(2, "Vector4", false);
 
                 MaterialParameter* instance = getInstance(state);
                 instance->setValue(param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Matrix");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Matrix' for parameter 2.");
-                    lua_error(state);
-                }
-                Matrix* param1 = (Matrix*)((ScriptController::LuaObject*)userdata2)->instance;
+                Matrix* param1 = ScriptController::getInstance()->getObjectPointer<Matrix>(2, "Matrix", true);
 
                 MaterialParameter* instance = getInstance(state);
                 instance->setValue(*param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Matrix");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Matrix' for parameter 2.");
-                    lua_error(state);
-                }
-                Matrix* param1 = (Matrix*)((ScriptController::LuaObject*)userdata2)->instance;
+                Matrix* param1 = ScriptController::getInstance()->getObjectPointer<Matrix>(2, "Matrix", false);
 
                 MaterialParameter* instance = getInstance(state);
                 instance->setValue(param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "TextureSampler");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Texture::Sampler' for parameter 2.");
-                    lua_error(state);
-                }
-                Texture::Sampler* param1 = (Texture::Sampler*)((ScriptController::LuaObject*)userdata2)->instance;
+                Texture::Sampler* param1 = ScriptController::getInstance()->getObjectPointer<Texture::Sampler>(2, "TextureSampler", false);
 
                 MaterialParameter* instance = getInstance(state);
                 instance->setValue(param1);
@@ -1021,7 +1007,7 @@ int lua_MaterialParameter_setValue(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
@@ -1036,7 +1022,7 @@ int lua_MaterialParameter_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
@@ -1051,18 +1037,12 @@ int lua_MaterialParameter_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector2");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector2' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector2* param1 = (Vector2*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector2* param1 = ScriptController::getInstance()->getObjectPointer<Vector2>(2, "Vector2", false);
 
                 // Get parameter 2 off the stack.
                 unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
@@ -1072,18 +1052,12 @@ int lua_MaterialParameter_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", false);
 
                 // Get parameter 2 off the stack.
                 unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
@@ -1093,18 +1067,12 @@ int lua_MaterialParameter_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector4");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector4' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector4* param1 = (Vector4*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector4* param1 = ScriptController::getInstance()->getObjectPointer<Vector4>(2, "Vector4", false);
 
                 // Get parameter 2 off the stack.
                 unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
@@ -1114,18 +1082,12 @@ int lua_MaterialParameter_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Matrix");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Matrix' for parameter 2.");
-                    lua_error(state);
-                }
-                Matrix* param1 = (Matrix*)((ScriptController::LuaObject*)userdata2)->instance;
+                Matrix* param1 = ScriptController::getInstance()->getObjectPointer<Matrix>(2, "Matrix", false);
 
                 // Get parameter 2 off the stack.
                 unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
@@ -1135,22 +1097,30 @@ int lua_MaterialParameter_setValue(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
                 bool param2 = (luaL_checkint(state, 3) != 0);
 
                 MaterialParameter* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->setValue(param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "TextureSampler");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->setValue(param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "TextureSampler");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }

+ 1 - 1
gameplay/src/lua/lua_MathUtil.cpp

@@ -38,7 +38,7 @@ int lua_MathUtil__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "MathUtil");
                 luaL_argcheck(state, userdata != NULL, 1, "'MathUtil' expected.");

文件差异内容过多而无法显示
+ 177 - 391
gameplay/src/lua/lua_Matrix.cpp


+ 225 - 173
gameplay/src/lua/lua_Mesh.cpp

@@ -64,7 +64,7 @@ int lua_Mesh__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Mesh");
                 luaL_argcheck(state, userdata != NULL, 1, "'Mesh' expected.");
@@ -104,9 +104,9 @@ int lua_Mesh_addPart(lua_State* state)
     {
         case 4:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -119,11 +119,19 @@ int lua_Mesh_addPart(lua_State* state)
                 unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
 
                 Mesh* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->addPart(param1, param2, param3);
-                object->owns = false;
-                luaL_getmetatable(state, "MeshPart");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->addPart(param1, param2, param3);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MeshPart");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -136,9 +144,9 @@ int lua_Mesh_addPart(lua_State* state)
         }
         case 5:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TNUMBER &&
                 lua_type(state, 5) == LUA_TBOOLEAN)
             {
@@ -155,11 +163,19 @@ int lua_Mesh_addPart(lua_State* state)
                 bool param4 = (luaL_checkint(state, 5) != 0);
 
                 Mesh* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->addPart(param1, param2, param3, param4);
-                object->owns = false;
-                luaL_getmetatable(state, "MeshPart");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->addPart(param1, param2, param3, param4);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MeshPart");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -190,7 +206,7 @@ int lua_Mesh_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Mesh* instance = getInstance(state);
                 instance->addRef();
@@ -224,14 +240,22 @@ int lua_Mesh_getBoundingBox(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Mesh* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getBoundingBox());
-                object->owns = false;
-                luaL_getmetatable(state, "BoundingBox");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getBoundingBox());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "BoundingBox");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -262,14 +286,22 @@ int lua_Mesh_getBoundingSphere(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Mesh* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getBoundingSphere());
-                object->owns = false;
-                luaL_getmetatable(state, "BoundingSphere");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getBoundingSphere());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "BoundingSphere");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -300,18 +332,26 @@ int lua_Mesh_getPart(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
                 unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
 
                 Mesh* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getPart(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "MeshPart");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getPart(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MeshPart");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -342,7 +382,7 @@ int lua_Mesh_getPartCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Mesh* instance = getInstance(state);
                 unsigned int result = instance->getPartCount();
@@ -379,7 +419,7 @@ int lua_Mesh_getPrimitiveType(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Mesh* instance = getInstance(state);
                 Mesh::PrimitiveType result = instance->getPrimitiveType();
@@ -416,7 +456,7 @@ int lua_Mesh_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Mesh* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -453,7 +493,7 @@ int lua_Mesh_getUrl(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Mesh* instance = getInstance(state);
                 const char* result = instance->getUrl();
@@ -490,14 +530,22 @@ int lua_Mesh_getVertexBuffer(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Mesh* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new GLuint(instance->getVertexBuffer());
-                object->owns = true;
-                luaL_getmetatable(state, "GLuint");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)new GLuint(instance->getVertexBuffer());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "GLuint");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -528,7 +576,7 @@ int lua_Mesh_getVertexCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Mesh* instance = getInstance(state);
                 unsigned int result = instance->getVertexCount();
@@ -565,14 +613,22 @@ int lua_Mesh_getVertexFormat(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Mesh* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getVertexFormat());
-                object->owns = false;
-                luaL_getmetatable(state, "VertexFormat");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getVertexFormat());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "VertexFormat");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -603,7 +659,7 @@ int lua_Mesh_getVertexSize(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Mesh* instance = getInstance(state);
                 unsigned int result = instance->getVertexSize();
@@ -640,7 +696,7 @@ int lua_Mesh_isDynamic(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Mesh* instance = getInstance(state);
                 bool result = instance->isDynamic();
@@ -677,7 +733,7 @@ int lua_Mesh_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Mesh* instance = getInstance(state);
                 instance->release();
@@ -711,17 +767,11 @@ int lua_Mesh_setBoundingBox(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingBox");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingBox' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingBox* param1 = (BoundingBox*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingBox* param1 = ScriptController::getInstance()->getObjectPointer<BoundingBox>(2, "BoundingBox", true);
 
                 Mesh* instance = getInstance(state);
                 instance->setBoundingBox(*param1);
@@ -755,17 +805,11 @@ int lua_Mesh_setBoundingSphere(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "BoundingSphere");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingSphere' for parameter 2.");
-                    lua_error(state);
-                }
-                BoundingSphere* param1 = (BoundingSphere*)((ScriptController::LuaObject*)userdata2)->instance;
+                BoundingSphere* param1 = ScriptController::getInstance()->getObjectPointer<BoundingSphere>(2, "BoundingSphere", true);
 
                 Mesh* instance = getInstance(state);
                 instance->setBoundingSphere(*param1);
@@ -799,8 +843,8 @@ int lua_Mesh_setPrimitiveType(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
                 Mesh::PrimitiveType param1 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
@@ -837,22 +881,24 @@ int lua_Mesh_static_createBoundingBox(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "BoundingBox");
-                if (!userdata1)
+                BoundingBox* param1 = ScriptController::getInstance()->getObjectPointer<BoundingBox>(1, "BoundingBox", true);
+
+                void* returnPtr = (void*)Mesh::createBoundingBox(*param1);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'BoundingBox' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Mesh");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                BoundingBox* param1 = (BoundingBox*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Mesh::createBoundingBox(*param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Mesh");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -883,26 +929,28 @@ int lua_Mesh_static_createLines(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Vector3");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 1.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata1)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(1, "Vector3", false);
 
                 // Get parameter 2 off the stack.
                 unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Mesh::createLines(param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "Mesh");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Mesh::createLines(param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Mesh");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -933,26 +981,28 @@ int lua_Mesh_static_createMesh(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "VertexFormat");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'VertexFormat' for parameter 1.");
-                    lua_error(state);
-                }
-                VertexFormat* param1 = (VertexFormat*)((ScriptController::LuaObject*)userdata1)->instance;
+                VertexFormat* param1 = ScriptController::getInstance()->getObjectPointer<VertexFormat>(1, "VertexFormat", true);
 
                 // Get parameter 2 off the stack.
                 unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Mesh::createMesh(*param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "Mesh");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Mesh::createMesh(*param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Mesh");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -965,18 +1015,12 @@ int lua_Mesh_static_createMesh(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER &&
                 lua_type(state, 3) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "VertexFormat");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'VertexFormat' for parameter 1.");
-                    lua_error(state);
-                }
-                VertexFormat* param1 = (VertexFormat*)((ScriptController::LuaObject*)userdata1)->instance;
+                VertexFormat* param1 = ScriptController::getInstance()->getObjectPointer<VertexFormat>(1, "VertexFormat", true);
 
                 // Get parameter 2 off the stack.
                 unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
@@ -984,11 +1028,19 @@ int lua_Mesh_static_createMesh(lua_State* state)
                 // Get parameter 3 off the stack.
                 bool param3 = (luaL_checkint(state, 3) != 0);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Mesh::createMesh(*param1, param2, param3);
-                object->owns = false;
-                luaL_getmetatable(state, "Mesh");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Mesh::createMesh(*param1, param2, param3);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Mesh");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -1019,52 +1071,36 @@ int lua_Mesh_static_createQuad(lua_State* state)
     {
         case 4:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
-                lua_type(state, 4) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
+                (lua_type(state, 4) == LUA_TUSERDATA || lua_type(state, 4) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Vector3");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 1.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata1)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(1, "Vector3", true);
 
                 // Get parameter 2 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 // Get parameter 3 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector3");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector3* param3 = (Vector3*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector3* param3 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", true);
 
                 // Get parameter 4 off the stack.
-                void* userdata4 = ScriptController::getInstance()->getObjectPointer(4, "Vector3");
-                if (!userdata4)
+                Vector3* param4 = ScriptController::getInstance()->getObjectPointer<Vector3>(4, "Vector3", true);
+
+                void* returnPtr = (void*)Mesh::createQuad(*param1, *param2, *param3, *param4);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 4.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Mesh");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Vector3* param4 = (Vector3*)((ScriptController::LuaObject*)userdata4)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Mesh::createQuad(*param1, *param2, *param3, *param4);
-                object->owns = false;
-                luaL_getmetatable(state, "Mesh");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -1085,11 +1121,19 @@ int lua_Mesh_static_createQuad(lua_State* state)
                 // Get parameter 4 off the stack.
                 float param4 = (float)luaL_checknumber(state, 4);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Mesh::createQuad(param1, param2, param3, param4);
-                object->owns = false;
-                luaL_getmetatable(state, "Mesh");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)Mesh::createQuad(param1, param2, param3, param4);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Mesh");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -1120,11 +1164,19 @@ int lua_Mesh_static_createQuadFullscreen(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)Mesh::createQuadFullscreen();
-            object->owns = false;
-            luaL_getmetatable(state, "Mesh");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)Mesh::createQuadFullscreen();
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = false;
+                luaL_getmetatable(state, "Mesh");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;

+ 131 - 129
gameplay/src/lua/lua_MeshBatch.cpp

@@ -15,7 +15,7 @@ void luaRegister_MeshBatch()
     {
         {"begin", lua_MeshBatch_begin},
         {"draw", lua_MeshBatch_draw},
-        {"end", lua_MeshBatch_end},
+        {"finish", lua_MeshBatch_finish},
         {"getCapacity", lua_MeshBatch_getCapacity},
         {"getMaterial", lua_MeshBatch_getMaterial},
         {"setCapacity", lua_MeshBatch_setCapacity},
@@ -48,7 +48,7 @@ int lua_MeshBatch__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "MeshBatch");
                 luaL_argcheck(state, userdata != NULL, 1, "'MeshBatch' expected.");
@@ -88,7 +88,7 @@ int lua_MeshBatch_begin(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshBatch* instance = getInstance(state);
                 instance->begin();
@@ -122,7 +122,7 @@ int lua_MeshBatch_draw(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshBatch* instance = getInstance(state);
                 instance->draw();
@@ -146,7 +146,7 @@ int lua_MeshBatch_draw(lua_State* state)
     return 0;
 }
 
-int lua_MeshBatch_end(lua_State* state)
+int lua_MeshBatch_finish(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -156,10 +156,10 @@ int lua_MeshBatch_end(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshBatch* instance = getInstance(state);
-                instance->end();
+                instance->finish();
                 
                 return 0;
             }
@@ -190,7 +190,7 @@ int lua_MeshBatch_getCapacity(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshBatch* instance = getInstance(state);
                 unsigned int result = instance->getCapacity();
@@ -227,14 +227,22 @@ int lua_MeshBatch_getMaterial(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshBatch* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getMaterial();
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getMaterial();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -265,7 +273,7 @@ int lua_MeshBatch_setCapacity(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -303,71 +311,69 @@ int lua_MeshBatch_static_create(lua_State* state)
     {
         case 4:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "VertexFormat");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'VertexFormat' for parameter 1.");
-                    lua_error(state);
-                }
-                VertexFormat* param1 = (VertexFormat*)((ScriptController::LuaObject*)userdata1)->instance;
+                VertexFormat* param1 = ScriptController::getInstance()->getObjectPointer<VertexFormat>(1, "VertexFormat", true);
 
                 // Get parameter 2 off the stack.
                 Mesh::PrimitiveType param2 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
 
                 // Get parameter 3 off the stack.
-                const char* param3 = luaL_checkstring(state, 3);
+                const char* param3 = ScriptController::getInstance()->getString(3, false);
 
                 // Get parameter 4 off the stack.
                 bool param4 = (luaL_checkint(state, 4) != 0);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)MeshBatch::create(*param1, param2, param3, param4);
-                object->owns = false;
-                luaL_getmetatable(state, "MeshBatch");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)MeshBatch::create(*param1, param2, param3, param4);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MeshBatch");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "VertexFormat");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'VertexFormat' for parameter 1.");
-                    lua_error(state);
-                }
-                VertexFormat* param1 = (VertexFormat*)((ScriptController::LuaObject*)userdata1)->instance;
+                VertexFormat* param1 = ScriptController::getInstance()->getObjectPointer<VertexFormat>(1, "VertexFormat", true);
 
                 // Get parameter 2 off the stack.
                 Mesh::PrimitiveType param2 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
 
                 // Get parameter 3 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Material");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Material' for parameter 3.");
-                    lua_error(state);
-                }
-                Material* param3 = (Material*)((ScriptController::LuaObject*)userdata3)->instance;
+                Material* param3 = ScriptController::getInstance()->getObjectPointer<Material>(3, "Material", false);
 
                 // Get parameter 4 off the stack.
                 bool param4 = (luaL_checkint(state, 4) != 0);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)MeshBatch::create(*param1, param2, param3, param4);
-                object->owns = false;
-                luaL_getmetatable(state, "MeshBatch");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)MeshBatch::create(*param1, param2, param3, param4);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MeshBatch");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -380,26 +386,20 @@ int lua_MeshBatch_static_create(lua_State* state)
         }
         case 5:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TBOOLEAN &&
                 lua_type(state, 5) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "VertexFormat");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'VertexFormat' for parameter 1.");
-                    lua_error(state);
-                }
-                VertexFormat* param1 = (VertexFormat*)((ScriptController::LuaObject*)userdata1)->instance;
+                VertexFormat* param1 = ScriptController::getInstance()->getObjectPointer<VertexFormat>(1, "VertexFormat", true);
 
                 // Get parameter 2 off the stack.
                 Mesh::PrimitiveType param2 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
 
                 // Get parameter 3 off the stack.
-                const char* param3 = luaL_checkstring(state, 3);
+                const char* param3 = ScriptController::getInstance()->getString(3, false);
 
                 // Get parameter 4 off the stack.
                 bool param4 = (luaL_checkint(state, 4) != 0);
@@ -407,40 +407,36 @@ int lua_MeshBatch_static_create(lua_State* state)
                 // Get parameter 5 off the stack.
                 unsigned int param5 = (unsigned int)luaL_checkunsigned(state, 5);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)MeshBatch::create(*param1, param2, param3, param4, param5);
-                object->owns = false;
-                luaL_getmetatable(state, "MeshBatch");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)MeshBatch::create(*param1, param2, param3, param4, param5);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MeshBatch");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TBOOLEAN &&
                 lua_type(state, 5) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "VertexFormat");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'VertexFormat' for parameter 1.");
-                    lua_error(state);
-                }
-                VertexFormat* param1 = (VertexFormat*)((ScriptController::LuaObject*)userdata1)->instance;
+                VertexFormat* param1 = ScriptController::getInstance()->getObjectPointer<VertexFormat>(1, "VertexFormat", true);
 
                 // Get parameter 2 off the stack.
                 Mesh::PrimitiveType param2 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
 
                 // Get parameter 3 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Material");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Material' for parameter 3.");
-                    lua_error(state);
-                }
-                Material* param3 = (Material*)((ScriptController::LuaObject*)userdata3)->instance;
+                Material* param3 = ScriptController::getInstance()->getObjectPointer<Material>(3, "Material", false);
 
                 // Get parameter 4 off the stack.
                 bool param4 = (luaL_checkint(state, 4) != 0);
@@ -448,11 +444,19 @@ int lua_MeshBatch_static_create(lua_State* state)
                 // Get parameter 5 off the stack.
                 unsigned int param5 = (unsigned int)luaL_checkunsigned(state, 5);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)MeshBatch::create(*param1, param2, param3, param4, param5);
-                object->owns = false;
-                luaL_getmetatable(state, "MeshBatch");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)MeshBatch::create(*param1, param2, param3, param4, param5);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MeshBatch");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -465,27 +469,21 @@ int lua_MeshBatch_static_create(lua_State* state)
         }
         case 6:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TBOOLEAN &&
                 lua_type(state, 5) == LUA_TNUMBER &&
                 lua_type(state, 6) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "VertexFormat");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'VertexFormat' for parameter 1.");
-                    lua_error(state);
-                }
-                VertexFormat* param1 = (VertexFormat*)((ScriptController::LuaObject*)userdata1)->instance;
+                VertexFormat* param1 = ScriptController::getInstance()->getObjectPointer<VertexFormat>(1, "VertexFormat", true);
 
                 // Get parameter 2 off the stack.
                 Mesh::PrimitiveType param2 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
 
                 // Get parameter 3 off the stack.
-                const char* param3 = luaL_checkstring(state, 3);
+                const char* param3 = ScriptController::getInstance()->getString(3, false);
 
                 // Get parameter 4 off the stack.
                 bool param4 = (luaL_checkint(state, 4) != 0);
@@ -496,41 +494,37 @@ int lua_MeshBatch_static_create(lua_State* state)
                 // Get parameter 6 off the stack.
                 unsigned int param6 = (unsigned int)luaL_checkunsigned(state, 6);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)MeshBatch::create(*param1, param2, param3, param4, param5, param6);
-                object->owns = false;
-                luaL_getmetatable(state, "MeshBatch");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)MeshBatch::create(*param1, param2, param3, param4, param5, param6);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MeshBatch");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TBOOLEAN &&
                 lua_type(state, 5) == LUA_TNUMBER &&
                 lua_type(state, 6) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "VertexFormat");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'VertexFormat' for parameter 1.");
-                    lua_error(state);
-                }
-                VertexFormat* param1 = (VertexFormat*)((ScriptController::LuaObject*)userdata1)->instance;
+                VertexFormat* param1 = ScriptController::getInstance()->getObjectPointer<VertexFormat>(1, "VertexFormat", true);
 
                 // Get parameter 2 off the stack.
                 Mesh::PrimitiveType param2 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
 
                 // Get parameter 3 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Material");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Material' for parameter 3.");
-                    lua_error(state);
-                }
-                Material* param3 = (Material*)((ScriptController::LuaObject*)userdata3)->instance;
+                Material* param3 = ScriptController::getInstance()->getObjectPointer<Material>(3, "Material", false);
 
                 // Get parameter 4 off the stack.
                 bool param4 = (luaL_checkint(state, 4) != 0);
@@ -541,11 +535,19 @@ int lua_MeshBatch_static_create(lua_State* state)
                 // Get parameter 6 off the stack.
                 unsigned int param6 = (unsigned int)luaL_checkunsigned(state, 6);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)MeshBatch::create(*param1, param2, param3, param4, param5, param6);
-                object->owns = false;
-                luaL_getmetatable(state, "MeshBatch");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)MeshBatch::create(*param1, param2, param3, param4, param5, param6);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MeshBatch");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }

+ 1 - 1
gameplay/src/lua/lua_MeshBatch.h

@@ -8,7 +8,7 @@ namespace gameplay
 int lua_MeshBatch__gc(lua_State* state);
 int lua_MeshBatch_begin(lua_State* state);
 int lua_MeshBatch_draw(lua_State* state);
-int lua_MeshBatch_end(lua_State* state);
+int lua_MeshBatch_finish(lua_State* state);
 int lua_MeshBatch_getCapacity(lua_State* state);
 int lua_MeshBatch_getMaterial(lua_State* state);
 int lua_MeshBatch_setCapacity(lua_State* state);

+ 20 - 12
gameplay/src/lua/lua_MeshPart.cpp

@@ -44,7 +44,7 @@ int lua_MeshPart__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "MeshPart");
                 luaL_argcheck(state, userdata != NULL, 1, "'MeshPart' expected.");
@@ -84,14 +84,22 @@ int lua_MeshPart_getIndexBuffer(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshPart* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new GLuint(instance->getIndexBuffer());
-                object->owns = true;
-                luaL_getmetatable(state, "GLuint");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)new GLuint(instance->getIndexBuffer());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "GLuint");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -122,7 +130,7 @@ int lua_MeshPart_getIndexCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshPart* instance = getInstance(state);
                 unsigned int result = instance->getIndexCount();
@@ -159,7 +167,7 @@ int lua_MeshPart_getIndexFormat(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshPart* instance = getInstance(state);
                 Mesh::IndexFormat result = instance->getIndexFormat();
@@ -196,7 +204,7 @@ int lua_MeshPart_getMeshIndex(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshPart* instance = getInstance(state);
                 unsigned int result = instance->getMeshIndex();
@@ -233,7 +241,7 @@ int lua_MeshPart_getPrimitiveType(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshPart* instance = getInstance(state);
                 Mesh::PrimitiveType result = instance->getPrimitiveType();
@@ -270,7 +278,7 @@ int lua_MeshPart_isDynamic(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshPart* instance = getInstance(state);
                 bool result = instance->isDynamic();

+ 98 - 68
gameplay/src/lua/lua_MeshSkin.cpp

@@ -49,14 +49,22 @@ int lua_MeshSkin_getBindShape(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshSkin* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)&(instance->getBindShape());
-                object->owns = false;
-                luaL_getmetatable(state, "Matrix");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)&(instance->getBindShape());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Matrix");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -87,33 +95,49 @@ int lua_MeshSkin_getJoint(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
                 unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
 
                 MeshSkin* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getJoint(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Joint");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getJoint(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Joint");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 MeshSkin* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getJoint(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Joint");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getJoint(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Joint");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -144,7 +168,7 @@ int lua_MeshSkin_getJointCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshSkin* instance = getInstance(state);
                 unsigned int result = instance->getJointCount();
@@ -181,17 +205,11 @@ int lua_MeshSkin_getJointIndex(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Joint");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Joint' for parameter 2.");
-                    lua_error(state);
-                }
-                Joint* param1 = (Joint*)((ScriptController::LuaObject*)userdata2)->instance;
+                Joint* param1 = ScriptController::getInstance()->getObjectPointer<Joint>(2, "Joint", false);
 
                 MeshSkin* instance = getInstance(state);
                 int result = instance->getJointIndex(param1);
@@ -228,14 +246,22 @@ int lua_MeshSkin_getMatrixPalette(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshSkin* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getMatrixPalette();
-                object->owns = false;
-                luaL_getmetatable(state, "Vector4");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getMatrixPalette();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Vector4");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -266,7 +292,7 @@ int lua_MeshSkin_getMatrixPaletteSize(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshSkin* instance = getInstance(state);
                 unsigned int result = instance->getMatrixPaletteSize();
@@ -303,14 +329,22 @@ int lua_MeshSkin_getModel(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshSkin* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getModel();
-                object->owns = false;
-                luaL_getmetatable(state, "Model");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getModel();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Model");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -341,14 +375,22 @@ int lua_MeshSkin_getRootJoint(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 MeshSkin* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getRootJoint();
-                object->owns = false;
-                luaL_getmetatable(state, "Joint");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getRootJoint();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Joint");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -379,7 +421,7 @@ int lua_MeshSkin_setBindShape(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA))
             {
                 // Get parameter 1 off the stack.
@@ -417,17 +459,11 @@ int lua_MeshSkin_setRootJoint(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Joint");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Joint' for parameter 2.");
-                    lua_error(state);
-                }
-                Joint* param1 = (Joint*)((ScriptController::LuaObject*)userdata2)->instance;
+                Joint* param1 = ScriptController::getInstance()->getObjectPointer<Joint>(2, "Joint", false);
 
                 MeshSkin* instance = getInstance(state);
                 instance->setRootJoint(param1);
@@ -461,18 +497,12 @@ int lua_MeshSkin_transformChanged(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Transform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Transform' for parameter 2.");
-                    lua_error(state);
-                }
-                Transform* param1 = (Transform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Transform* param1 = ScriptController::getInstance()->getObjectPointer<Transform>(2, "Transform", false);
 
                 // Get parameter 2 off the stack.
                 long param2 = (long)luaL_checklong(state, 3);

+ 188 - 118
gameplay/src/lua/lua_Model.cpp

@@ -53,7 +53,7 @@ int lua_Model__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Model");
                 luaL_argcheck(state, userdata != NULL, 1, "'Model' expected.");
@@ -93,7 +93,7 @@ int lua_Model_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Model* instance = getInstance(state);
                 instance->addRef();
@@ -127,7 +127,7 @@ int lua_Model_draw(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Model* instance = getInstance(state);
                 instance->draw();
@@ -143,7 +143,7 @@ int lua_Model_draw(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
@@ -181,14 +181,22 @@ int lua_Model_getMaterial(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Model* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getMaterial();
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getMaterial();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -201,18 +209,26 @@ int lua_Model_getMaterial(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
                 int param1 = (int)luaL_checkint(state, 2);
 
                 Model* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getMaterial(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getMaterial(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -243,14 +259,22 @@ int lua_Model_getMesh(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Model* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getMesh();
-                object->owns = false;
-                luaL_getmetatable(state, "Mesh");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getMesh();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Mesh");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -281,7 +305,7 @@ int lua_Model_getMeshPartCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Model* instance = getInstance(state);
                 unsigned int result = instance->getMeshPartCount();
@@ -318,14 +342,22 @@ int lua_Model_getNode(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Model* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getNode();
-                object->owns = false;
-                luaL_getmetatable(state, "Node");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getNode();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Node");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -356,7 +388,7 @@ int lua_Model_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Model* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -393,14 +425,22 @@ int lua_Model_getSkin(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Model* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getSkin();
-                object->owns = false;
-                luaL_getmetatable(state, "MeshSkin");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getSkin();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MeshSkin");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -431,7 +471,7 @@ int lua_Model_hasMaterial(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -472,7 +512,7 @@ int lua_Model_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Model* instance = getInstance(state);
                 instance->release();
@@ -506,35 +546,37 @@ int lua_Model_setMaterial(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Material");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Material' for parameter 2.");
-                    lua_error(state);
-                }
-                Material* param1 = (Material*)((ScriptController::LuaObject*)userdata2)->instance;
+                Material* param1 = ScriptController::getInstance()->getObjectPointer<Material>(2, "Material", false);
 
                 Model* instance = getInstance(state);
                 instance->setMaterial(param1);
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Model* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->setMaterial(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->setMaterial(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -547,18 +589,12 @@ int lua_Model_setMaterial(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Material");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Material' for parameter 2.");
-                    lua_error(state);
-                }
-                Material* param1 = (Material*)((ScriptController::LuaObject*)userdata2)->instance;
+                Material* param1 = ScriptController::getInstance()->getObjectPointer<Material>(2, "Material", false);
 
                 // Get parameter 2 off the stack.
                 int param2 = (int)luaL_checkint(state, 3);
@@ -568,41 +604,57 @@ int lua_Model_setMaterial(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
-                const char* param2 = luaL_checkstring(state, 3);
+                const char* param2 = ScriptController::getInstance()->getString(3, false);
 
                 Model* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->setMaterial(param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->setMaterial(param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
                 int param2 = (int)luaL_checkint(state, 3);
 
                 Model* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->setMaterial(param1, param2);
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->setMaterial(param1, param2);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -615,26 +667,34 @@ int lua_Model_setMaterial(lua_State* state)
         }
         case 4:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING &&
-                lua_type(state, 4) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
+                (lua_type(state, 4) == LUA_TSTRING || lua_type(state, 4) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
-                const char* param2 = luaL_checkstring(state, 3);
+                const char* param2 = ScriptController::getInstance()->getString(3, false);
 
                 // Get parameter 3 off the stack.
-                const char* param3 = luaL_checkstring(state, 4);
+                const char* param3 = ScriptController::getInstance()->getString(4, false);
 
                 Model* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->setMaterial(param1, param2, param3);
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->setMaterial(param1, param2, param3);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -647,30 +707,38 @@ int lua_Model_setMaterial(lua_State* state)
         }
         case 5:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING &&
-                lua_type(state, 4) == LUA_TSTRING &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
+                (lua_type(state, 4) == LUA_TSTRING || lua_type(state, 4) == LUA_TNIL) &&
                 lua_type(state, 5) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
-                const char* param2 = luaL_checkstring(state, 3);
+                const char* param2 = ScriptController::getInstance()->getString(3, false);
 
                 // Get parameter 3 off the stack.
-                const char* param3 = luaL_checkstring(state, 4);
+                const char* param3 = ScriptController::getInstance()->getString(4, false);
 
                 // Get parameter 4 off the stack.
                 int param4 = (int)luaL_checkint(state, 5);
 
                 Model* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->setMaterial(param1, param2, param3, param4);
-                object->owns = false;
-                luaL_getmetatable(state, "Material");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->setMaterial(param1, param2, param3, param4);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Material");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -701,22 +769,24 @@ int lua_Model_static_create(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Mesh");
-                if (!userdata1)
+                Mesh* param1 = ScriptController::getInstance()->getObjectPointer<Mesh>(1, "Mesh", false);
+
+                void* returnPtr = (void*)Model::create(param1);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Mesh' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Model");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Mesh* param1 = (Mesh*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)Model::create(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Model");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }

+ 1 - 1
gameplay/src/lua/lua_Mouse.cpp

@@ -38,7 +38,7 @@ int lua_Mouse__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Mouse");
                 luaL_argcheck(state, userdata != NULL, 1, "'Mouse' expected.");

文件差异内容过多而无法显示
+ 379 - 243
gameplay/src/lua/lua_Node.cpp


+ 56 - 68
gameplay/src/lua/lua_NodeCloneContext.cpp

@@ -42,7 +42,7 @@ int lua_NodeCloneContext__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "NodeCloneContext");
                 luaL_argcheck(state, userdata != NULL, 1, "'NodeCloneContext' expected.");
@@ -82,11 +82,19 @@ int lua_NodeCloneContext__init(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)new NodeCloneContext();
-            object->owns = true;
-            luaL_getmetatable(state, "NodeCloneContext");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)new NodeCloneContext();
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = true;
+                luaL_getmetatable(state, "NodeCloneContext");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;
@@ -111,24 +119,26 @@ int lua_NodeCloneContext_findClonedAnimation(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Animation");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Animation' for parameter 2.");
-                    lua_error(state);
-                }
-                Animation* param1 = (Animation*)((ScriptController::LuaObject*)userdata2)->instance;
+                Animation* param1 = ScriptController::getInstance()->getObjectPointer<Animation>(2, "Animation", false);
 
                 NodeCloneContext* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->findClonedAnimation(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Animation");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->findClonedAnimation(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Animation");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -159,24 +169,26 @@ int lua_NodeCloneContext_findClonedNode(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Node");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Node' for parameter 2.");
-                    lua_error(state);
-                }
-                Node* param1 = (Node*)((ScriptController::LuaObject*)userdata2)->instance;
+                Node* param1 = ScriptController::getInstance()->getObjectPointer<Node>(2, "Node", false);
 
                 NodeCloneContext* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->findClonedNode(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "Node");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->findClonedNode(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Node");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -207,27 +219,15 @@ int lua_NodeCloneContext_registerClonedAnimation(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Animation");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Animation' for parameter 2.");
-                    lua_error(state);
-                }
-                Animation* param1 = (Animation*)((ScriptController::LuaObject*)userdata2)->instance;
+                Animation* param1 = ScriptController::getInstance()->getObjectPointer<Animation>(2, "Animation", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Animation");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Animation' for parameter 3.");
-                    lua_error(state);
-                }
-                Animation* param2 = (Animation*)((ScriptController::LuaObject*)userdata3)->instance;
+                Animation* param2 = ScriptController::getInstance()->getObjectPointer<Animation>(3, "Animation", false);
 
                 NodeCloneContext* instance = getInstance(state);
                 instance->registerClonedAnimation(param1, param2);
@@ -261,27 +261,15 @@ int lua_NodeCloneContext_registerClonedNode(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Node");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Node' for parameter 2.");
-                    lua_error(state);
-                }
-                Node* param1 = (Node*)((ScriptController::LuaObject*)userdata2)->instance;
+                Node* param1 = ScriptController::getInstance()->getObjectPointer<Node>(2, "Node", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Node");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Node' for parameter 3.");
-                    lua_error(state);
-                }
-                Node* param2 = (Node*)((ScriptController::LuaObject*)userdata3)->instance;
+                Node* param2 = ScriptController::getInstance()->getObjectPointer<Node>(3, "Node", false);
 
                 NodeCloneContext* instance = getInstance(state);
                 instance->registerClonedNode(param1, param2);

文件差异内容过多而无法显示
+ 283 - 247
gameplay/src/lua/lua_ParticleEmitter.cpp


+ 80 - 60
gameplay/src/lua/lua_Pass.cpp

@@ -51,7 +51,7 @@ int lua_Pass__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "Pass");
                 luaL_argcheck(state, userdata != NULL, 1, "'Pass' expected.");
@@ -91,7 +91,7 @@ int lua_Pass_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Pass* instance = getInstance(state);
                 instance->addRef();
@@ -125,7 +125,7 @@ int lua_Pass_bind(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Pass* instance = getInstance(state);
                 instance->bind();
@@ -159,14 +159,22 @@ int lua_Pass_getEffect(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Pass* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getEffect();
-                object->owns = false;
-                luaL_getmetatable(state, "Effect");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getEffect();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Effect");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -197,7 +205,7 @@ int lua_Pass_getId(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Pass* instance = getInstance(state);
                 const char* result = instance->getId();
@@ -234,18 +242,26 @@ int lua_Pass_getParameter(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 Pass* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getParameter(param1);
-                object->owns = false;
-                luaL_getmetatable(state, "MaterialParameter");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getParameter(param1);
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MaterialParameter");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -276,7 +292,7 @@ int lua_Pass_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Pass* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -313,14 +329,22 @@ int lua_Pass_getStateBlock(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Pass* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getStateBlock();
-                object->owns = false;
-                luaL_getmetatable(state, "RenderStateStateBlock");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getStateBlock();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "RenderStateStateBlock");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -351,14 +375,22 @@ int lua_Pass_getVertexAttributeBinding(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Pass* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getVertexAttributeBinding();
-                object->owns = false;
-                luaL_getmetatable(state, "VertexAttributeBinding");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getVertexAttributeBinding();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "VertexAttributeBinding");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -389,7 +421,7 @@ int lua_Pass_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Pass* instance = getInstance(state);
                 instance->release();
@@ -423,12 +455,12 @@ int lua_Pass_setParameterAutoBinding(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
                 RenderState::AutoBinding param2 = (RenderState::AutoBinding)lua_enumFromString_RenderStateAutoBinding(luaL_checkstring(state, 3));
@@ -438,15 +470,15 @@ int lua_Pass_setParameterAutoBinding(lua_State* state)
                 
                 return 0;
             }
-            else if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TSTRING)
+            else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = luaL_checkstring(state, 2);
+                const char* param1 = ScriptController::getInstance()->getString(2, false);
 
                 // Get parameter 2 off the stack.
-                const char* param2 = luaL_checkstring(state, 3);
+                const char* param2 = ScriptController::getInstance()->getString(3, false);
 
                 Pass* instance = getInstance(state);
                 instance->setParameterAutoBinding(param1, param2);
@@ -480,17 +512,11 @@ int lua_Pass_setStateBlock(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "RenderStateStateBlock");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'RenderState::StateBlock' for parameter 2.");
-                    lua_error(state);
-                }
-                RenderState::StateBlock* param1 = (RenderState::StateBlock*)((ScriptController::LuaObject*)userdata2)->instance;
+                RenderState::StateBlock* param1 = ScriptController::getInstance()->getObjectPointer<RenderState::StateBlock>(2, "RenderStateStateBlock", false);
 
                 Pass* instance = getInstance(state);
                 instance->setStateBlock(param1);
@@ -524,17 +550,11 @@ int lua_Pass_setVertexAttributeBinding(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "VertexAttributeBinding");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'VertexAttributeBinding' for parameter 2.");
-                    lua_error(state);
-                }
-                VertexAttributeBinding* param1 = (VertexAttributeBinding*)((ScriptController::LuaObject*)userdata2)->instance;
+                VertexAttributeBinding* param1 = ScriptController::getInstance()->getObjectPointer<VertexAttributeBinding>(2, "VertexAttributeBinding", false);
 
                 Pass* instance = getInstance(state);
                 instance->setVertexAttributeBinding(param1);
@@ -568,7 +588,7 @@ int lua_Pass_unbind(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 Pass* instance = getInstance(state);
                 instance->unbind();

+ 96 - 150
gameplay/src/lua/lua_PhysicsCharacter.cpp

@@ -63,17 +63,11 @@ int lua_PhysicsCharacter_addCollisionListener(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "PhysicsCollisionObjectCollisionListener");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject::CollisionListener' for parameter 2.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject::CollisionListener* param1 = (PhysicsCollisionObject::CollisionListener*)((ScriptController::LuaObject*)userdata2)->instance;
+                PhysicsCollisionObject::CollisionListener* param1 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
 
                 PhysicsCharacter* instance = getInstance(state);
                 instance->addCollisionListener(param1);
@@ -89,27 +83,15 @@ int lua_PhysicsCharacter_addCollisionListener(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "PhysicsCollisionObjectCollisionListener");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject::CollisionListener' for parameter 2.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject::CollisionListener* param1 = (PhysicsCollisionObject::CollisionListener*)((ScriptController::LuaObject*)userdata2)->instance;
+                PhysicsCollisionObject::CollisionListener* param1 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "PhysicsCollisionObject");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject' for parameter 3.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject* param2 = (PhysicsCollisionObject*)((ScriptController::LuaObject*)userdata3)->instance;
+                PhysicsCollisionObject* param2 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject>(3, "PhysicsCollisionObject", false);
 
                 PhysicsCharacter* instance = getInstance(state);
                 instance->addCollisionListener(param1, param2);
@@ -143,17 +125,11 @@ int lua_PhysicsCharacter_collidesWith(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "PhysicsCollisionObject");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject' for parameter 2.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject* param1 = (PhysicsCollisionObject*)((ScriptController::LuaObject*)userdata2)->instance;
+                PhysicsCollisionObject* param1 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject>(2, "PhysicsCollisionObject", false);
 
                 PhysicsCharacter* instance = getInstance(state);
                 bool result = instance->collidesWith(param1);
@@ -190,14 +166,22 @@ int lua_PhysicsCharacter_getCollisionShape(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCharacter* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getCollisionShape();
-                object->owns = false;
-                luaL_getmetatable(state, "PhysicsCollisionShape");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getCollisionShape();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "PhysicsCollisionShape");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -228,14 +212,22 @@ int lua_PhysicsCharacter_getCurrentVelocity(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCharacter* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new Vector3(instance->getCurrentVelocity());
-                object->owns = true;
-                luaL_getmetatable(state, "Vector3");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)new Vector3(instance->getCurrentVelocity());
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "Vector3");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -266,7 +258,7 @@ int lua_PhysicsCharacter_getMaxSlopeAngle(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCharacter* instance = getInstance(state);
                 float result = instance->getMaxSlopeAngle();
@@ -303,7 +295,7 @@ int lua_PhysicsCharacter_getMaxStepHeight(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCharacter* instance = getInstance(state);
                 float result = instance->getMaxStepHeight();
@@ -340,14 +332,22 @@ int lua_PhysicsCharacter_getNode(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCharacter* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getNode();
-                object->owns = false;
-                luaL_getmetatable(state, "Node");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getNode();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Node");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -378,7 +378,7 @@ int lua_PhysicsCharacter_getShapeType(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCharacter* instance = getInstance(state);
                 PhysicsCollisionShape::Type result = instance->getShapeType();
@@ -415,7 +415,7 @@ int lua_PhysicsCharacter_getType(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCharacter* instance = getInstance(state);
                 PhysicsCollisionObject::Type result = instance->getType();
@@ -452,7 +452,7 @@ int lua_PhysicsCharacter_isDynamic(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCharacter* instance = getInstance(state);
                 bool result = instance->isDynamic();
@@ -489,7 +489,7 @@ int lua_PhysicsCharacter_isEnabled(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCharacter* instance = getInstance(state);
                 bool result = instance->isEnabled();
@@ -526,7 +526,7 @@ int lua_PhysicsCharacter_isKinematic(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCharacter* instance = getInstance(state);
                 bool result = instance->isKinematic();
@@ -563,7 +563,7 @@ int lua_PhysicsCharacter_isPhysicsEnabled(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCharacter* instance = getInstance(state);
                 bool result = instance->isPhysicsEnabled();
@@ -600,7 +600,7 @@ int lua_PhysicsCharacter_jump(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -638,17 +638,11 @@ int lua_PhysicsCharacter_removeCollisionListener(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "PhysicsCollisionObjectCollisionListener");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject::CollisionListener' for parameter 2.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject::CollisionListener* param1 = (PhysicsCollisionObject::CollisionListener*)((ScriptController::LuaObject*)userdata2)->instance;
+                PhysicsCollisionObject::CollisionListener* param1 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
 
                 PhysicsCharacter* instance = getInstance(state);
                 instance->removeCollisionListener(param1);
@@ -664,27 +658,15 @@ int lua_PhysicsCharacter_removeCollisionListener(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "PhysicsCollisionObjectCollisionListener");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject::CollisionListener' for parameter 2.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject::CollisionListener* param1 = (PhysicsCollisionObject::CollisionListener*)((ScriptController::LuaObject*)userdata2)->instance;
+                PhysicsCollisionObject::CollisionListener* param1 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "PhysicsCollisionObject");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject' for parameter 3.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject* param2 = (PhysicsCollisionObject*)((ScriptController::LuaObject*)userdata3)->instance;
+                PhysicsCollisionObject* param2 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject>(3, "PhysicsCollisionObject", false);
 
                 PhysicsCharacter* instance = getInstance(state);
                 instance->removeCollisionListener(param1, param2);
@@ -718,17 +700,11 @@ int lua_PhysicsCharacter_rotate(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Quaternion");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Quaternion' for parameter 2.");
-                    lua_error(state);
-                }
-                Quaternion* param1 = (Quaternion*)((ScriptController::LuaObject*)userdata2)->instance;
+                Quaternion* param1 = ScriptController::getInstance()->getObjectPointer<Quaternion>(2, "Quaternion", true);
 
                 PhysicsCharacter* instance = getInstance(state);
                 instance->rotate(*param1);
@@ -744,18 +720,12 @@ int lua_PhysicsCharacter_rotate(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 // Get parameter 2 off the stack.
                 float param2 = (float)luaL_checknumber(state, 3);
@@ -792,7 +762,7 @@ int lua_PhysicsCharacter_setEnabled(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
@@ -830,7 +800,7 @@ int lua_PhysicsCharacter_setForwardVelocity(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCharacter* instance = getInstance(state);
                 instance->setForwardVelocity();
@@ -846,7 +816,7 @@ int lua_PhysicsCharacter_setForwardVelocity(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -884,7 +854,7 @@ int lua_PhysicsCharacter_setMaxSlopeAngle(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -922,7 +892,7 @@ int lua_PhysicsCharacter_setMaxStepHeight(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -960,7 +930,7 @@ int lua_PhysicsCharacter_setPhysicsEnabled(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
@@ -998,7 +968,7 @@ int lua_PhysicsCharacter_setRightVelocity(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCharacter* instance = getInstance(state);
                 instance->setRightVelocity();
@@ -1014,7 +984,7 @@ int lua_PhysicsCharacter_setRightVelocity(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -1052,17 +1022,11 @@ int lua_PhysicsCharacter_setRotation(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Quaternion");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Quaternion' for parameter 2.");
-                    lua_error(state);
-                }
-                Quaternion* param1 = (Quaternion*)((ScriptController::LuaObject*)userdata2)->instance;
+                Quaternion* param1 = ScriptController::getInstance()->getObjectPointer<Quaternion>(2, "Quaternion", true);
 
                 PhysicsCharacter* instance = getInstance(state);
                 instance->setRotation(*param1);
@@ -1078,18 +1042,12 @@ int lua_PhysicsCharacter_setRotation(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 // Get parameter 2 off the stack.
                 float param2 = (float)luaL_checknumber(state, 3);
@@ -1126,17 +1084,11 @@ int lua_PhysicsCharacter_setVelocity(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 PhysicsCharacter* instance = getInstance(state);
                 instance->setVelocity(*param1);
@@ -1170,18 +1122,12 @@ int lua_PhysicsCharacter_transformChanged(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Transform");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Transform' for parameter 2.");
-                    lua_error(state);
-                }
-                Transform* param1 = (Transform*)((ScriptController::LuaObject*)userdata2)->instance;
+                Transform* param1 = ScriptController::getInstance()->getObjectPointer<Transform>(2, "Transform", false);
 
                 // Get parameter 2 off the stack.
                 long param2 = (long)luaL_checklong(state, 3);

+ 54 - 80
gameplay/src/lua/lua_PhysicsCollisionObject.cpp

@@ -49,7 +49,7 @@ int lua_PhysicsCollisionObject__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "PhysicsCollisionObject");
                 luaL_argcheck(state, userdata != NULL, 1, "'PhysicsCollisionObject' expected.");
@@ -89,17 +89,11 @@ int lua_PhysicsCollisionObject_addCollisionListener(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "PhysicsCollisionObjectCollisionListener");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject::CollisionListener' for parameter 2.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject::CollisionListener* param1 = (PhysicsCollisionObject::CollisionListener*)((ScriptController::LuaObject*)userdata2)->instance;
+                PhysicsCollisionObject::CollisionListener* param1 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
 
                 PhysicsCollisionObject* instance = getInstance(state);
                 instance->addCollisionListener(param1);
@@ -115,27 +109,15 @@ int lua_PhysicsCollisionObject_addCollisionListener(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "PhysicsCollisionObjectCollisionListener");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject::CollisionListener' for parameter 2.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject::CollisionListener* param1 = (PhysicsCollisionObject::CollisionListener*)((ScriptController::LuaObject*)userdata2)->instance;
+                PhysicsCollisionObject::CollisionListener* param1 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "PhysicsCollisionObject");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject' for parameter 3.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject* param2 = (PhysicsCollisionObject*)((ScriptController::LuaObject*)userdata3)->instance;
+                PhysicsCollisionObject* param2 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject>(3, "PhysicsCollisionObject", false);
 
                 PhysicsCollisionObject* instance = getInstance(state);
                 instance->addCollisionListener(param1, param2);
@@ -169,17 +151,11 @@ int lua_PhysicsCollisionObject_collidesWith(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "PhysicsCollisionObject");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject' for parameter 2.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject* param1 = (PhysicsCollisionObject*)((ScriptController::LuaObject*)userdata2)->instance;
+                PhysicsCollisionObject* param1 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject>(2, "PhysicsCollisionObject", false);
 
                 PhysicsCollisionObject* instance = getInstance(state);
                 bool result = instance->collidesWith(param1);
@@ -216,14 +192,22 @@ int lua_PhysicsCollisionObject_getCollisionShape(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCollisionObject* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getCollisionShape();
-                object->owns = false;
-                luaL_getmetatable(state, "PhysicsCollisionShape");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getCollisionShape();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "PhysicsCollisionShape");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -254,14 +238,22 @@ int lua_PhysicsCollisionObject_getNode(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCollisionObject* instance = getInstance(state);
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)instance->getNode();
-                object->owns = false;
-                luaL_getmetatable(state, "Node");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)instance->getNode();
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Node");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -292,7 +284,7 @@ int lua_PhysicsCollisionObject_getShapeType(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCollisionObject* instance = getInstance(state);
                 PhysicsCollisionShape::Type result = instance->getShapeType();
@@ -329,7 +321,7 @@ int lua_PhysicsCollisionObject_getType(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCollisionObject* instance = getInstance(state);
                 PhysicsCollisionObject::Type result = instance->getType();
@@ -366,7 +358,7 @@ int lua_PhysicsCollisionObject_isDynamic(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCollisionObject* instance = getInstance(state);
                 bool result = instance->isDynamic();
@@ -403,7 +395,7 @@ int lua_PhysicsCollisionObject_isEnabled(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCollisionObject* instance = getInstance(state);
                 bool result = instance->isEnabled();
@@ -440,7 +432,7 @@ int lua_PhysicsCollisionObject_isKinematic(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCollisionObject* instance = getInstance(state);
                 bool result = instance->isKinematic();
@@ -477,17 +469,11 @@ int lua_PhysicsCollisionObject_removeCollisionListener(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "PhysicsCollisionObjectCollisionListener");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject::CollisionListener' for parameter 2.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject::CollisionListener* param1 = (PhysicsCollisionObject::CollisionListener*)((ScriptController::LuaObject*)userdata2)->instance;
+                PhysicsCollisionObject::CollisionListener* param1 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
 
                 PhysicsCollisionObject* instance = getInstance(state);
                 instance->removeCollisionListener(param1);
@@ -503,27 +489,15 @@ int lua_PhysicsCollisionObject_removeCollisionListener(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "PhysicsCollisionObjectCollisionListener");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject::CollisionListener' for parameter 2.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject::CollisionListener* param1 = (PhysicsCollisionObject::CollisionListener*)((ScriptController::LuaObject*)userdata2)->instance;
+                PhysicsCollisionObject::CollisionListener* param1 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "PhysicsCollisionObject");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject' for parameter 3.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject* param2 = (PhysicsCollisionObject*)((ScriptController::LuaObject*)userdata3)->instance;
+                PhysicsCollisionObject* param2 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject>(3, "PhysicsCollisionObject", false);
 
                 PhysicsCollisionObject* instance = getInstance(state);
                 instance->removeCollisionListener(param1, param2);
@@ -557,7 +531,7 @@ int lua_PhysicsCollisionObject_setEnabled(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.

+ 19 - 55
gameplay/src/lua/lua_PhysicsCollisionObjectCollisionListener.cpp

@@ -40,7 +40,7 @@ int lua_PhysicsCollisionObjectCollisionListener__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "PhysicsCollisionObjectCollisionListener");
                 luaL_argcheck(state, userdata != NULL, 1, "'PhysicsCollisionObjectCollisionListener' expected.");
@@ -80,21 +80,15 @@ int lua_PhysicsCollisionObjectCollisionListener_collisionEvent(lua_State* state)
     {
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
                 PhysicsCollisionObject::CollisionListener::EventType param1 = (PhysicsCollisionObject::CollisionListener::EventType)lua_enumFromString_PhysicsCollisionObjectCollisionListenerEventType(luaL_checkstring(state, 2));
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "PhysicsCollisionObjectCollisionPair");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject::CollisionPair' for parameter 3.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject::CollisionPair* param2 = (PhysicsCollisionObject::CollisionPair*)((ScriptController::LuaObject*)userdata3)->instance;
+                PhysicsCollisionObject::CollisionPair* param2 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject::CollisionPair>(3, "PhysicsCollisionObjectCollisionPair", true);
 
                 PhysicsCollisionObject::CollisionListener* instance = getInstance(state);
                 instance->collisionEvent(param1, *param2);
@@ -110,31 +104,19 @@ int lua_PhysicsCollisionObjectCollisionListener_collisionEvent(lua_State* state)
         }
         case 4:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
-                lua_type(state, 4) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
+                (lua_type(state, 4) == LUA_TUSERDATA || lua_type(state, 4) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
                 PhysicsCollisionObject::CollisionListener::EventType param1 = (PhysicsCollisionObject::CollisionListener::EventType)lua_enumFromString_PhysicsCollisionObjectCollisionListenerEventType(luaL_checkstring(state, 2));
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "PhysicsCollisionObjectCollisionPair");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject::CollisionPair' for parameter 3.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject::CollisionPair* param2 = (PhysicsCollisionObject::CollisionPair*)((ScriptController::LuaObject*)userdata3)->instance;
+                PhysicsCollisionObject::CollisionPair* param2 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject::CollisionPair>(3, "PhysicsCollisionObjectCollisionPair", true);
 
                 // Get parameter 3 off the stack.
-                void* userdata4 = ScriptController::getInstance()->getObjectPointer(4, "Vector3");
-                if (!userdata4)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 4.");
-                    lua_error(state);
-                }
-                Vector3* param3 = (Vector3*)((ScriptController::LuaObject*)userdata4)->instance;
+                Vector3* param3 = ScriptController::getInstance()->getObjectPointer<Vector3>(4, "Vector3", true);
 
                 PhysicsCollisionObject::CollisionListener* instance = getInstance(state);
                 instance->collisionEvent(param1, *param2, *param3);
@@ -150,41 +132,23 @@ int lua_PhysicsCollisionObjectCollisionListener_collisionEvent(lua_State* state)
         }
         case 5:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TSTRING &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
-                lua_type(state, 4) == LUA_TUSERDATA &&
-                lua_type(state, 5) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
+                (lua_type(state, 4) == LUA_TUSERDATA || lua_type(state, 4) == LUA_TNIL) &&
+                (lua_type(state, 5) == LUA_TUSERDATA || lua_type(state, 5) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
                 PhysicsCollisionObject::CollisionListener::EventType param1 = (PhysicsCollisionObject::CollisionListener::EventType)lua_enumFromString_PhysicsCollisionObjectCollisionListenerEventType(luaL_checkstring(state, 2));
 
                 // Get parameter 2 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "PhysicsCollisionObjectCollisionPair");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject::CollisionPair' for parameter 3.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject::CollisionPair* param2 = (PhysicsCollisionObject::CollisionPair*)((ScriptController::LuaObject*)userdata3)->instance;
+                PhysicsCollisionObject::CollisionPair* param2 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject::CollisionPair>(3, "PhysicsCollisionObjectCollisionPair", true);
 
                 // Get parameter 3 off the stack.
-                void* userdata4 = ScriptController::getInstance()->getObjectPointer(4, "Vector3");
-                if (!userdata4)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 4.");
-                    lua_error(state);
-                }
-                Vector3* param3 = (Vector3*)((ScriptController::LuaObject*)userdata4)->instance;
+                Vector3* param3 = ScriptController::getInstance()->getObjectPointer<Vector3>(4, "Vector3", true);
 
                 // Get parameter 4 off the stack.
-                void* userdata5 = ScriptController::getInstance()->getObjectPointer(5, "Vector3");
-                if (!userdata5)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 5.");
-                    lua_error(state);
-                }
-                Vector3* param4 = (Vector3*)((ScriptController::LuaObject*)userdata5)->instance;
+                Vector3* param4 = ScriptController::getInstance()->getObjectPointer<Vector3>(5, "Vector3", true);
 
                 PhysicsCollisionObject::CollisionListener* instance = getInstance(state);
                 instance->collisionEvent(param1, *param2, *param3, *param4);

+ 45 - 45
gameplay/src/lua/lua_PhysicsCollisionObjectCollisionPair.cpp

@@ -41,7 +41,7 @@ int lua_PhysicsCollisionObjectCollisionPair__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "PhysicsCollisionObjectCollisionPair");
                 luaL_argcheck(state, userdata != NULL, 1, "'PhysicsCollisionObjectCollisionPair' expected.");
@@ -81,32 +81,28 @@ int lua_PhysicsCollisionObjectCollisionPair__init(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "PhysicsCollisionObject");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject' for parameter 1.");
-                    lua_error(state);
-                }
-                PhysicsCollisionObject* param1 = (PhysicsCollisionObject*)((ScriptController::LuaObject*)userdata1)->instance;
+                PhysicsCollisionObject* param1 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject>(1, "PhysicsCollisionObject", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "PhysicsCollisionObject");
-                if (!userdata2)
+                PhysicsCollisionObject* param2 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject>(2, "PhysicsCollisionObject", false);
+
+                void* returnPtr = (void*)new PhysicsCollisionObject::CollisionPair(param1, param2);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject' for parameter 2.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "PhysicsCollisionObjectCollisionPair");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                PhysicsCollisionObject* param2 = (PhysicsCollisionObject*)((ScriptController::LuaObject*)userdata2)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new PhysicsCollisionObject::CollisionPair(param1, param2);
-                object->owns = true;
-                luaL_getmetatable(state, "PhysicsCollisionObjectCollisionPair");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -140,24 +136,26 @@ int lua_PhysicsCollisionObjectCollisionPair_objectA(lua_State* state)
     if (lua_gettop(state) == 2)
     {
         // Get parameter 2 off the stack.
-        void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "PhysicsCollisionObject");
-        if (!userdata2)
-        {
-            lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject' for parameter 2.");
-            lua_error(state);
-        }
-        PhysicsCollisionObject* param2 = (PhysicsCollisionObject*)((ScriptController::LuaObject*)userdata2)->instance;
+        PhysicsCollisionObject* param2 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject>(2, "PhysicsCollisionObject", false);
 
         instance->objectA = param2;
         return 0;
     }
     else
     {
-        ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-        object->instance = (void*)instance->objectA;
-        object->owns = false;
-        luaL_getmetatable(state, "PhysicsCollisionObject");
-        lua_setmetatable(state, -2);
+        void* returnPtr = (void*)instance->objectA;
+        if (returnPtr)
+        {
+            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+            object->instance = returnPtr;
+            object->owns = false;
+            luaL_getmetatable(state, "PhysicsCollisionObject");
+            lua_setmetatable(state, -2);
+        }
+        else
+        {
+            lua_pushnil(state);
+        }
 
         return 1;
     }
@@ -176,24 +174,26 @@ int lua_PhysicsCollisionObjectCollisionPair_objectB(lua_State* state)
     if (lua_gettop(state) == 2)
     {
         // Get parameter 2 off the stack.
-        void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "PhysicsCollisionObject");
-        if (!userdata2)
-        {
-            lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionObject' for parameter 2.");
-            lua_error(state);
-        }
-        PhysicsCollisionObject* param2 = (PhysicsCollisionObject*)((ScriptController::LuaObject*)userdata2)->instance;
+        PhysicsCollisionObject* param2 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionObject>(2, "PhysicsCollisionObject", false);
 
         instance->objectB = param2;
         return 0;
     }
     else
     {
-        ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-        object->instance = (void*)instance->objectB;
-        object->owns = false;
-        luaL_getmetatable(state, "PhysicsCollisionObject");
-        lua_setmetatable(state, -2);
+        void* returnPtr = (void*)instance->objectB;
+        if (returnPtr)
+        {
+            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+            object->instance = returnPtr;
+            object->owns = false;
+            luaL_getmetatable(state, "PhysicsCollisionObject");
+            lua_setmetatable(state, -2);
+        }
+        else
+        {
+            lua_pushnil(state);
+        }
 
         return 1;
     }

+ 203 - 157
gameplay/src/lua/lua_PhysicsCollisionShape.cpp

@@ -50,7 +50,7 @@ int lua_PhysicsCollisionShape__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "PhysicsCollisionShape");
                 luaL_argcheck(state, userdata != NULL, 1, "'PhysicsCollisionShape' expected.");
@@ -90,7 +90,7 @@ int lua_PhysicsCollisionShape_addRef(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCollisionShape* instance = getInstance(state);
                 instance->addRef();
@@ -124,7 +124,7 @@ int lua_PhysicsCollisionShape_getRefCount(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCollisionShape* instance = getInstance(state);
                 unsigned int result = instance->getRefCount();
@@ -161,7 +161,7 @@ int lua_PhysicsCollisionShape_getType(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCollisionShape* instance = getInstance(state);
                 PhysicsCollisionShape::Type result = instance->getType();
@@ -198,7 +198,7 @@ int lua_PhysicsCollisionShape_release(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsCollisionShape* instance = getInstance(state);
                 instance->release();
@@ -232,33 +232,43 @@ int lua_PhysicsCollisionShape_static_box(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::box());
-            object->owns = true;
-            luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::box());
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = true;
+                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;
         }
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Vector3");
-                if (!userdata1)
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(1, "Vector3", true);
+
+                void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::box(*param1));
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::box(*param1));
-                object->owns = true;
-                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -271,32 +281,28 @@ int lua_PhysicsCollisionShape_static_box(lua_State* state)
         }
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Vector3");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 1.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata1)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(1, "Vector3", true);
 
                 // Get parameter 2 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
+
+                void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::box(*param1, *param2));
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::box(*param1, *param2));
-                object->owns = true;
-                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -309,36 +315,32 @@ int lua_PhysicsCollisionShape_static_box(lua_State* state)
         }
         case 3:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Vector3");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 1.");
-                    lua_error(state);
-                }
-                Vector3* param1 = (Vector3*)((ScriptController::LuaObject*)userdata1)->instance;
+                Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(1, "Vector3", true);
 
                 // Get parameter 2 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 // Get parameter 3 off the stack.
                 bool param3 = (luaL_checkint(state, 3) != 0);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::box(*param1, *param2, param3));
-                object->owns = true;
-                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::box(*param1, *param2, param3));
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -369,11 +371,19 @@ int lua_PhysicsCollisionShape_static_capsule(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::capsule());
-            object->owns = true;
-            luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::capsule());
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = true;
+                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;
@@ -389,11 +399,19 @@ int lua_PhysicsCollisionShape_static_capsule(lua_State* state)
                 // Get parameter 2 off the stack.
                 float param2 = (float)luaL_checknumber(state, 2);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::capsule(param1, param2));
-                object->owns = true;
-                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::capsule(param1, param2));
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -408,7 +426,7 @@ int lua_PhysicsCollisionShape_static_capsule(lua_State* state)
         {
             if (lua_type(state, 1) == LUA_TNUMBER &&
                 lua_type(state, 2) == LUA_TNUMBER &&
-                lua_type(state, 3) == LUA_TUSERDATA)
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
                 float param1 = (float)luaL_checknumber(state, 1);
@@ -417,19 +435,21 @@ int lua_PhysicsCollisionShape_static_capsule(lua_State* state)
                 float param2 = (float)luaL_checknumber(state, 2);
 
                 // Get parameter 3 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector3");
-                if (!userdata3)
+                Vector3* param3 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", true);
+
+                void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::capsule(param1, param2, *param3));
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 3.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Vector3* param3 = (Vector3*)((ScriptController::LuaObject*)userdata3)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::capsule(param1, param2, *param3));
-                object->owns = true;
-                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -444,7 +464,7 @@ int lua_PhysicsCollisionShape_static_capsule(lua_State* state)
         {
             if (lua_type(state, 1) == LUA_TNUMBER &&
                 lua_type(state, 2) == LUA_TNUMBER &&
-                lua_type(state, 3) == LUA_TUSERDATA &&
+                (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
                 lua_type(state, 4) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
@@ -454,22 +474,24 @@ int lua_PhysicsCollisionShape_static_capsule(lua_State* state)
                 float param2 = (float)luaL_checknumber(state, 2);
 
                 // Get parameter 3 off the stack.
-                void* userdata3 = ScriptController::getInstance()->getObjectPointer(3, "Vector3");
-                if (!userdata3)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 3.");
-                    lua_error(state);
-                }
-                Vector3* param3 = (Vector3*)((ScriptController::LuaObject*)userdata3)->instance;
+                Vector3* param3 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", true);
 
                 // Get parameter 4 off the stack.
                 bool param4 = (luaL_checkint(state, 4) != 0);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::capsule(param1, param2, *param3, param4));
-                object->owns = true;
-                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::capsule(param1, param2, *param3, param4));
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -500,22 +522,24 @@ int lua_PhysicsCollisionShape_static_heightfield(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Image");
-                if (!userdata1)
+                Image* param1 = ScriptController::getInstance()->getObjectPointer<Image>(1, "Image", false);
+
+                void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::heightfield(param1));
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Image' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Image* param1 = (Image*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::heightfield(param1));
-                object->owns = true;
-                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -546,22 +570,24 @@ int lua_PhysicsCollisionShape_static_mesh(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Mesh");
-                if (!userdata1)
+                Mesh* param1 = ScriptController::getInstance()->getObjectPointer<Mesh>(1, "Mesh", false);
+
+                void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::mesh(param1));
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Mesh' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Mesh* param1 = (Mesh*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::mesh(param1));
-                object->owns = true;
-                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -592,11 +618,19 @@ int lua_PhysicsCollisionShape_static_sphere(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::sphere());
-            object->owns = true;
-            luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::sphere());
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = true;
+                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;
@@ -608,11 +642,19 @@ int lua_PhysicsCollisionShape_static_sphere(lua_State* state)
                 // Get parameter 1 off the stack.
                 float param1 = (float)luaL_checknumber(state, 1);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::sphere(param1));
-                object->owns = true;
-                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::sphere(param1));
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }
@@ -626,25 +668,27 @@ int lua_PhysicsCollisionShape_static_sphere(lua_State* state)
         case 2:
         {
             if (lua_type(state, 1) == LUA_TNUMBER &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
                 float param1 = (float)luaL_checknumber(state, 1);
 
                 // Get parameter 2 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
+
+                void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::sphere(param1, *param2));
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::sphere(param1, *param2));
-                object->owns = true;
-                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -658,29 +702,31 @@ int lua_PhysicsCollisionShape_static_sphere(lua_State* state)
         case 3:
         {
             if (lua_type(state, 1) == LUA_TNUMBER &&
-                lua_type(state, 2) == LUA_TUSERDATA &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
                 lua_type(state, 3) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
                 float param1 = (float)luaL_checknumber(state, 1);
 
                 // Get parameter 2 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
-                }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
 
                 // Get parameter 3 off the stack.
                 bool param3 = (luaL_checkint(state, 3) != 0);
 
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::sphere(param1, *param2, param3));
-                object->owns = true;
-                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-                lua_setmetatable(state, -2);
+                void* returnPtr = (void*)new PhysicsCollisionShape::Definition(PhysicsCollisionShape::sphere(param1, *param2, param3));
+                if (returnPtr)
+                {
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
 
                 return 1;
             }

+ 28 - 18
gameplay/src/lua/lua_PhysicsCollisionShapeDefinition.cpp

@@ -39,7 +39,7 @@ int lua_PhysicsCollisionShapeDefinition__gc(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 void* userdata = luaL_checkudata(state, 1, "PhysicsCollisionShapeDefinition");
                 luaL_argcheck(state, userdata != NULL, 1, "'PhysicsCollisionShapeDefinition' expected.");
@@ -79,33 +79,43 @@ int lua_PhysicsCollisionShapeDefinition__init(lua_State* state)
     {
         case 0:
         {
-            ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-            object->instance = (void*)new PhysicsCollisionShape::Definition();
-            object->owns = true;
-            luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-            lua_setmetatable(state, -2);
+            void* returnPtr = (void*)new PhysicsCollisionShape::Definition();
+            if (returnPtr)
+            {
+                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                object->instance = returnPtr;
+                object->owns = true;
+                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
 
             return 1;
             break;
         }
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "PhysicsCollisionShapeDefinition");
-                if (!userdata1)
+                PhysicsCollisionShape::Definition* param1 = ScriptController::getInstance()->getObjectPointer<PhysicsCollisionShape::Definition>(1, "PhysicsCollisionShapeDefinition", true);
+
+                void* returnPtr = (void*)new PhysicsCollisionShape::Definition(*param1);
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'PhysicsCollisionShape::Definition' for parameter 1.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                PhysicsCollisionShape::Definition* param1 = (PhysicsCollisionShape::Definition*)((ScriptController::LuaObject*)userdata1)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new PhysicsCollisionShape::Definition(*param1);
-                object->owns = true;
-                luaL_getmetatable(state, "PhysicsCollisionShapeDefinition");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }

+ 52 - 64
gameplay/src/lua/lua_PhysicsConstraint.cpp

@@ -48,7 +48,7 @@ int lua_PhysicsConstraint_getBreakingImpulse(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsConstraint* instance = getInstance(state);
                 float result = instance->getBreakingImpulse();
@@ -85,7 +85,7 @@ int lua_PhysicsConstraint_isEnabled(lua_State* state)
     {
         case 1:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
             {
                 PhysicsConstraint* instance = getInstance(state);
                 bool result = instance->isEnabled();
@@ -122,7 +122,7 @@ int lua_PhysicsConstraint_setBreakingImpulse(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
@@ -160,7 +160,7 @@ int lua_PhysicsConstraint_setEnabled(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
                 lua_type(state, 2) == LUA_TBOOLEAN)
             {
                 // Get parameter 1 off the stack.
@@ -198,32 +198,28 @@ int lua_PhysicsConstraint_static_centerOfMassMidpoint(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Node");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Node' for parameter 1.");
-                    lua_error(state);
-                }
-                Node* param1 = (Node*)((ScriptController::LuaObject*)userdata1)->instance;
+                Node* param1 = ScriptController::getInstance()->getObjectPointer<Node>(1, "Node", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Node");
-                if (!userdata2)
+                Node* param2 = ScriptController::getInstance()->getObjectPointer<Node>(2, "Node", false);
+
+                void* returnPtr = (void*)new Vector3(PhysicsConstraint::centerOfMassMidpoint(param1, param2));
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Node' for parameter 2.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "Vector3");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Node* param2 = (Node*)((ScriptController::LuaObject*)userdata2)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new Vector3(PhysicsConstraint::centerOfMassMidpoint(param1, param2));
-                object->owns = true;
-                luaL_getmetatable(state, "Vector3");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -254,32 +250,28 @@ int lua_PhysicsConstraint_static_getRotationOffset(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Node");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Node' for parameter 1.");
-                    lua_error(state);
-                }
-                Node* param1 = (Node*)((ScriptController::LuaObject*)userdata1)->instance;
+                Node* param1 = ScriptController::getInstance()->getObjectPointer<Node>(1, "Node", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
+
+                void* returnPtr = (void*)new Quaternion(PhysicsConstraint::getRotationOffset(param1, *param2));
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "Quaternion");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new Quaternion(PhysicsConstraint::getRotationOffset(param1, *param2));
-                object->owns = true;
-                luaL_getmetatable(state, "Quaternion");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }
@@ -310,32 +302,28 @@ int lua_PhysicsConstraint_static_getTranslationOffset(lua_State* state)
     {
         case 2:
         {
-            if (lua_type(state, 1) == LUA_TUSERDATA &&
-                lua_type(state, 2) == LUA_TUSERDATA)
+            if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                void* userdata1 = ScriptController::getInstance()->getObjectPointer(1, "Node");
-                if (!userdata1)
-                {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Node' for parameter 1.");
-                    lua_error(state);
-                }
-                Node* param1 = (Node*)((ScriptController::LuaObject*)userdata1)->instance;
+                Node* param1 = ScriptController::getInstance()->getObjectPointer<Node>(1, "Node", false);
 
                 // Get parameter 2 off the stack.
-                void* userdata2 = ScriptController::getInstance()->getObjectPointer(2, "Vector3");
-                if (!userdata2)
+                Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
+
+                void* returnPtr = (void*)new Vector3(PhysicsConstraint::getTranslationOffset(param1, *param2));
+                if (returnPtr)
                 {
-                    lua_pushstring(state, "Failed to retrieve a valid object pointer of type 'Vector3' for parameter 2.");
-                    lua_error(state);
+                    ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = true;
+                    luaL_getmetatable(state, "Vector3");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
                 }
-                Vector3* param2 = (Vector3*)((ScriptController::LuaObject*)userdata2)->instance;
-
-                ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
-                object->instance = (void*)new Vector3(PhysicsConstraint::getTranslationOffset(param1, *param2));
-                object->owns = true;
-                luaL_getmetatable(state, "Vector3");
-                lua_setmetatable(state, -2);
 
                 return 1;
             }

部分文件因为文件数量过多而无法显示