lua_SceneRenderer.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_SceneRenderer.h"
  4. #include "Base.h"
  5. #include "SceneRenderer.h"
  6. namespace gameplay
  7. {
  8. void luaRegister_SceneRenderer()
  9. {
  10. const luaL_Reg lua_members[] =
  11. {
  12. {"render", lua_SceneRenderer_render},
  13. {NULL, NULL}
  14. };
  15. const luaL_Reg* lua_statics = NULL;
  16. std::vector<std::string> scopePath;
  17. gameplay::ScriptUtil::registerClass("SceneRenderer", lua_members, NULL, lua_SceneRenderer__gc, lua_statics, scopePath);
  18. }
  19. static SceneRenderer* getInstance(lua_State* state)
  20. {
  21. void* userdata = luaL_checkudata(state, 1, "SceneRenderer");
  22. luaL_argcheck(state, userdata != NULL, 1, "'SceneRenderer' expected.");
  23. return (SceneRenderer*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  24. }
  25. int lua_SceneRenderer__gc(lua_State* state)
  26. {
  27. // Get the number of parameters.
  28. int paramCount = lua_gettop(state);
  29. // Attempt to match the parameters to a valid binding.
  30. switch (paramCount)
  31. {
  32. case 1:
  33. {
  34. if ((lua_type(state, 1) == LUA_TUSERDATA))
  35. {
  36. void* userdata = luaL_checkudata(state, 1, "SceneRenderer");
  37. luaL_argcheck(state, userdata != NULL, 1, "'SceneRenderer' expected.");
  38. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  39. if (object->owns)
  40. {
  41. SceneRenderer* instance = (SceneRenderer*)object->instance;
  42. SAFE_DELETE(instance);
  43. }
  44. return 0;
  45. }
  46. lua_pushstring(state, "lua_SceneRenderer__gc - Failed to match the given parameters to a valid function signature.");
  47. lua_error(state);
  48. break;
  49. }
  50. default:
  51. {
  52. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  53. lua_error(state);
  54. break;
  55. }
  56. }
  57. return 0;
  58. }
  59. int lua_SceneRenderer_render(lua_State* state)
  60. {
  61. // Get the number of parameters.
  62. int paramCount = lua_gettop(state);
  63. // Attempt to match the parameters to a valid binding.
  64. switch (paramCount)
  65. {
  66. case 2:
  67. {
  68. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  69. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  70. {
  71. // Get parameter 1 off the stack.
  72. bool param1Valid;
  73. gameplay::ScriptUtil::LuaArray<VisibleSet> param1 = gameplay::ScriptUtil::getObjectPointer<VisibleSet>(2, "VisibleSet", false, &param1Valid);
  74. if (!param1Valid)
  75. {
  76. lua_pushstring(state, "Failed to convert parameter 1 to type 'VisibleSet'.");
  77. lua_error(state);
  78. }
  79. SceneRenderer* instance = getInstance(state);
  80. unsigned int result = instance->render(param1);
  81. // Push the return value onto the stack.
  82. lua_pushunsigned(state, result);
  83. return 1;
  84. }
  85. lua_pushstring(state, "lua_SceneRenderer_render - Failed to match the given parameters to a valid function signature.");
  86. lua_error(state);
  87. break;
  88. }
  89. case 3:
  90. {
  91. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  92. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
  93. lua_type(state, 3) == LUA_TBOOLEAN)
  94. {
  95. // Get parameter 1 off the stack.
  96. bool param1Valid;
  97. gameplay::ScriptUtil::LuaArray<VisibleSet> param1 = gameplay::ScriptUtil::getObjectPointer<VisibleSet>(2, "VisibleSet", false, &param1Valid);
  98. if (!param1Valid)
  99. {
  100. lua_pushstring(state, "Failed to convert parameter 1 to type 'VisibleSet'.");
  101. lua_error(state);
  102. }
  103. // Get parameter 2 off the stack.
  104. bool param2 = gameplay::ScriptUtil::luaCheckBool(state, 3);
  105. SceneRenderer* instance = getInstance(state);
  106. unsigned int result = instance->render(param1, param2);
  107. // Push the return value onto the stack.
  108. lua_pushunsigned(state, result);
  109. return 1;
  110. }
  111. lua_pushstring(state, "lua_SceneRenderer_render - Failed to match the given parameters to a valid function signature.");
  112. lua_error(state);
  113. break;
  114. }
  115. default:
  116. {
  117. lua_pushstring(state, "Invalid number of parameters (expected 2 or 3).");
  118. lua_error(state);
  119. break;
  120. }
  121. }
  122. return 0;
  123. }
  124. }