2
0

lua_SceneLoader.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_SceneLoader.h"
  4. #include "AudioSource.h"
  5. #include "Base.h"
  6. #include "Bundle.h"
  7. #include "Game.h"
  8. #include "SceneLoader.h"
  9. namespace gameplay
  10. {
  11. void luaRegister_SceneLoader()
  12. {
  13. const luaL_Reg lua_members[] =
  14. {
  15. {NULL, NULL}
  16. };
  17. const luaL_Reg* lua_statics = NULL;
  18. std::vector<std::string> scopePath;
  19. ScriptUtil::registerClass("SceneLoader", lua_members, lua_SceneLoader__init, lua_SceneLoader__gc, lua_statics, scopePath);
  20. }
  21. static SceneLoader* getInstance(lua_State* state)
  22. {
  23. void* userdata = luaL_checkudata(state, 1, "SceneLoader");
  24. luaL_argcheck(state, userdata != NULL, 1, "'SceneLoader' expected.");
  25. return (SceneLoader*)((ScriptUtil::LuaObject*)userdata)->instance;
  26. }
  27. int lua_SceneLoader__gc(lua_State* state)
  28. {
  29. // Get the number of parameters.
  30. int paramCount = lua_gettop(state);
  31. // Attempt to match the parameters to a valid binding.
  32. switch (paramCount)
  33. {
  34. case 1:
  35. {
  36. if ((lua_type(state, 1) == LUA_TUSERDATA))
  37. {
  38. void* userdata = luaL_checkudata(state, 1, "SceneLoader");
  39. luaL_argcheck(state, userdata != NULL, 1, "'SceneLoader' expected.");
  40. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  41. if (object->owns)
  42. {
  43. SceneLoader* instance = (SceneLoader*)object->instance;
  44. SAFE_DELETE(instance);
  45. }
  46. return 0;
  47. }
  48. else
  49. {
  50. lua_pushstring(state, "lua_SceneLoader__gc - Failed to match the given parameters to a valid function signature.");
  51. lua_error(state);
  52. }
  53. break;
  54. }
  55. default:
  56. {
  57. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  58. lua_error(state);
  59. break;
  60. }
  61. }
  62. return 0;
  63. }
  64. int lua_SceneLoader__init(lua_State* state)
  65. {
  66. // Get the number of parameters.
  67. int paramCount = lua_gettop(state);
  68. // Attempt to match the parameters to a valid binding.
  69. switch (paramCount)
  70. {
  71. case 0:
  72. {
  73. void* returnPtr = (void*)new SceneLoader();
  74. if (returnPtr)
  75. {
  76. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  77. object->instance = returnPtr;
  78. object->owns = true;
  79. luaL_getmetatable(state, "SceneLoader");
  80. lua_setmetatable(state, -2);
  81. }
  82. else
  83. {
  84. lua_pushnil(state);
  85. }
  86. return 1;
  87. break;
  88. }
  89. default:
  90. {
  91. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  92. lua_error(state);
  93. break;
  94. }
  95. }
  96. return 0;
  97. }
  98. }