lua_ScreenDisplayer.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_ScreenDisplayer.h"
  4. #include "Base.h"
  5. #include "ScreenDisplayer.h"
  6. namespace gameplay
  7. {
  8. void luaRegister_ScreenDisplayer()
  9. {
  10. const luaL_Reg lua_members[] =
  11. {
  12. {NULL, NULL}
  13. };
  14. const luaL_Reg lua_statics[] =
  15. {
  16. {"finish", lua_ScreenDisplayer_static_finish},
  17. {"start", lua_ScreenDisplayer_static_start},
  18. {NULL, NULL}
  19. };
  20. std::vector<std::string> scopePath;
  21. gameplay::ScriptUtil::registerClass("ScreenDisplayer", lua_members, lua_ScreenDisplayer__init, lua_ScreenDisplayer__gc, lua_statics, scopePath);
  22. }
  23. static ScreenDisplayer* getInstance(lua_State* state)
  24. {
  25. void* userdata = luaL_checkudata(state, 1, "ScreenDisplayer");
  26. luaL_argcheck(state, userdata != NULL, 1, "'ScreenDisplayer' expected.");
  27. return (ScreenDisplayer*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  28. }
  29. int lua_ScreenDisplayer__gc(lua_State* state)
  30. {
  31. // Get the number of parameters.
  32. int paramCount = lua_gettop(state);
  33. // Attempt to match the parameters to a valid binding.
  34. switch (paramCount)
  35. {
  36. case 1:
  37. {
  38. if ((lua_type(state, 1) == LUA_TUSERDATA))
  39. {
  40. void* userdata = luaL_checkudata(state, 1, "ScreenDisplayer");
  41. luaL_argcheck(state, userdata != NULL, 1, "'ScreenDisplayer' expected.");
  42. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  43. if (object->owns)
  44. {
  45. ScreenDisplayer* instance = (ScreenDisplayer*)object->instance;
  46. SAFE_DELETE(instance);
  47. }
  48. return 0;
  49. }
  50. lua_pushstring(state, "lua_ScreenDisplayer__gc - Failed to match the given parameters to a valid function signature.");
  51. lua_error(state);
  52. break;
  53. }
  54. default:
  55. {
  56. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  57. lua_error(state);
  58. break;
  59. }
  60. }
  61. return 0;
  62. }
  63. int lua_ScreenDisplayer__init(lua_State* state)
  64. {
  65. // Get the number of parameters.
  66. int paramCount = lua_gettop(state);
  67. // Attempt to match the parameters to a valid binding.
  68. switch (paramCount)
  69. {
  70. case 0:
  71. {
  72. void* returnPtr = (void*)new ScreenDisplayer();
  73. if (returnPtr)
  74. {
  75. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  76. object->instance = returnPtr;
  77. object->owns = true;
  78. luaL_getmetatable(state, "ScreenDisplayer");
  79. lua_setmetatable(state, -2);
  80. }
  81. else
  82. {
  83. lua_pushnil(state);
  84. }
  85. return 1;
  86. break;
  87. }
  88. default:
  89. {
  90. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  91. lua_error(state);
  92. break;
  93. }
  94. }
  95. return 0;
  96. }
  97. int lua_ScreenDisplayer_static_finish(lua_State* state)
  98. {
  99. // Get the number of parameters.
  100. int paramCount = lua_gettop(state);
  101. // Attempt to match the parameters to a valid binding.
  102. switch (paramCount)
  103. {
  104. case 0:
  105. {
  106. ScreenDisplayer::finish();
  107. return 0;
  108. break;
  109. }
  110. default:
  111. {
  112. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  113. lua_error(state);
  114. break;
  115. }
  116. }
  117. return 0;
  118. }
  119. int lua_ScreenDisplayer_static_start(lua_State* state)
  120. {
  121. // Get the number of parameters.
  122. int paramCount = lua_gettop(state);
  123. // Attempt to match the parameters to a valid binding.
  124. switch (paramCount)
  125. {
  126. case 2:
  127. {
  128. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  129. lua_type(state, 2) == LUA_TNUMBER)
  130. {
  131. // Get parameter 1 off the stack.
  132. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  133. // Get parameter 2 off the stack.
  134. unsigned long param2 = (unsigned long)luaL_checkunsigned(state, 2);
  135. ScreenDisplayer::start(param1, param2);
  136. return 0;
  137. }
  138. lua_pushstring(state, "lua_ScreenDisplayer_static_start - Failed to match the given parameters to a valid function signature.");
  139. lua_error(state);
  140. break;
  141. }
  142. default:
  143. {
  144. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  145. lua_error(state);
  146. break;
  147. }
  148. }
  149. return 0;
  150. }
  151. }