lua_ScriptTargetEventRegistryEvent.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_ScriptTargetEventRegistryEvent.h"
  4. #include "Base.h"
  5. #include "ScriptController.h"
  6. #include "ScriptTarget.h"
  7. namespace gameplay
  8. {
  9. void luaRegister_ScriptTargetEventRegistryEvent()
  10. {
  11. const luaL_Reg lua_members[] =
  12. {
  13. {"args", lua_ScriptTargetEventRegistryEvent_args},
  14. {"name", lua_ScriptTargetEventRegistryEvent_name},
  15. {"registry", lua_ScriptTargetEventRegistryEvent_registry},
  16. {NULL, NULL}
  17. };
  18. const luaL_Reg* lua_statics = NULL;
  19. std::vector<std::string> scopePath;
  20. scopePath.push_back("ScriptTarget");
  21. scopePath.push_back("EventRegistry");
  22. gameplay::ScriptUtil::registerClass("ScriptTargetEventRegistryEvent", lua_members, lua_ScriptTargetEventRegistryEvent__init, lua_ScriptTargetEventRegistryEvent__gc, lua_statics, scopePath);
  23. }
  24. static ScriptTarget::EventRegistry::Event* getInstance(lua_State* state)
  25. {
  26. void* userdata = luaL_checkudata(state, 1, "ScriptTargetEventRegistryEvent");
  27. luaL_argcheck(state, userdata != NULL, 1, "'ScriptTargetEventRegistryEvent' expected.");
  28. return (ScriptTarget::EventRegistry::Event*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  29. }
  30. int lua_ScriptTargetEventRegistryEvent__gc(lua_State* state)
  31. {
  32. // Get the number of parameters.
  33. int paramCount = lua_gettop(state);
  34. // Attempt to match the parameters to a valid binding.
  35. switch (paramCount)
  36. {
  37. case 1:
  38. {
  39. if ((lua_type(state, 1) == LUA_TUSERDATA))
  40. {
  41. void* userdata = luaL_checkudata(state, 1, "ScriptTargetEventRegistryEvent");
  42. luaL_argcheck(state, userdata != NULL, 1, "'ScriptTargetEventRegistryEvent' expected.");
  43. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  44. if (object->owns)
  45. {
  46. ScriptTarget::EventRegistry::Event* instance = (ScriptTarget::EventRegistry::Event*)object->instance;
  47. SAFE_DELETE(instance);
  48. }
  49. return 0;
  50. }
  51. lua_pushstring(state, "lua_ScriptTargetEventRegistryEvent__gc - Failed to match the given parameters to a valid function signature.");
  52. lua_error(state);
  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_ScriptTargetEventRegistryEvent__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 ScriptTarget::EventRegistry::Event();
  74. if (returnPtr)
  75. {
  76. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  77. object->instance = returnPtr;
  78. object->owns = true;
  79. luaL_getmetatable(state, "ScriptTargetEventRegistryEvent");
  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. int lua_ScriptTargetEventRegistryEvent_args(lua_State* state)
  99. {
  100. // Validate the number of parameters.
  101. if (lua_gettop(state) > 2)
  102. {
  103. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  104. lua_error(state);
  105. }
  106. ScriptTarget::EventRegistry::Event* instance = getInstance(state);
  107. if (lua_gettop(state) == 2)
  108. {
  109. // Get parameter 2 off the stack.
  110. std::string param2 = gameplay::ScriptUtil::getString(2, true);
  111. instance->args = param2;
  112. return 0;
  113. }
  114. else
  115. {
  116. std::string result = instance->args;
  117. // Push the return value onto the stack.
  118. lua_pushstring(state, result.c_str());
  119. return 1;
  120. }
  121. }
  122. int lua_ScriptTargetEventRegistryEvent_name(lua_State* state)
  123. {
  124. // Validate the number of parameters.
  125. if (lua_gettop(state) > 2)
  126. {
  127. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  128. lua_error(state);
  129. }
  130. ScriptTarget::EventRegistry::Event* instance = getInstance(state);
  131. if (lua_gettop(state) == 2)
  132. {
  133. // Get parameter 2 off the stack.
  134. std::string param2 = gameplay::ScriptUtil::getString(2, true);
  135. instance->name = param2;
  136. return 0;
  137. }
  138. else
  139. {
  140. std::string result = instance->name;
  141. // Push the return value onto the stack.
  142. lua_pushstring(state, result.c_str());
  143. return 1;
  144. }
  145. }
  146. int lua_ScriptTargetEventRegistryEvent_registry(lua_State* state)
  147. {
  148. // Validate the number of parameters.
  149. if (lua_gettop(state) > 2)
  150. {
  151. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  152. lua_error(state);
  153. }
  154. ScriptTarget::EventRegistry::Event* instance = getInstance(state);
  155. if (lua_gettop(state) == 2)
  156. {
  157. // Get parameter 2 off the stack.
  158. GP_WARN("Attempting to get parameter 2 with unrecognized type classgameplay_1_1_script_target_1_1_event_registry as an unsigned integer.");
  159. classgameplay_1_1_script_target_1_1_event_registry* param2 = (classgameplay_1_1_script_target_1_1_event_registry)luaL_checkunsigned(state, 2);
  160. memcpy(instance->registry, param2, sizeof() * classgameplay_1_1_script_target_1_1_event_registry);
  161. return 0;
  162. }
  163. else
  164. {
  165. classgameplay_1_1_script_target_1_1_event_registry* result = instance->registry;
  166. // Push the return value onto the stack.
  167. lua_pushlightuserdata(state, result);
  168. return 1;
  169. }
  170. }
  171. }