lua_Platform.cpp 3.6 KB

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