lua_Keyboard.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Keyboard.h"
  4. #include "Keyboard.h"
  5. namespace gameplay
  6. {
  7. void luaRegister_Keyboard()
  8. {
  9. const luaL_Reg lua_members[] =
  10. {
  11. {NULL, NULL}
  12. };
  13. const luaL_Reg* lua_statics = NULL;
  14. std::vector<std::string> scopePath;
  15. gameplay::ScriptUtil::registerClass("Keyboard", lua_members, NULL, lua_Keyboard__gc, lua_statics, scopePath);
  16. }
  17. static Keyboard* getInstance(lua_State* state)
  18. {
  19. void* userdata = luaL_checkudata(state, 1, "Keyboard");
  20. luaL_argcheck(state, userdata != NULL, 1, "'Keyboard' expected.");
  21. return (Keyboard*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  22. }
  23. int lua_Keyboard__gc(lua_State* state)
  24. {
  25. // Get the number of parameters.
  26. int paramCount = lua_gettop(state);
  27. // Attempt to match the parameters to a valid binding.
  28. switch (paramCount)
  29. {
  30. case 1:
  31. {
  32. if ((lua_type(state, 1) == LUA_TUSERDATA))
  33. {
  34. void* userdata = luaL_checkudata(state, 1, "Keyboard");
  35. luaL_argcheck(state, userdata != NULL, 1, "'Keyboard' expected.");
  36. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  37. if (object->owns)
  38. {
  39. Keyboard* instance = (Keyboard*)object->instance;
  40. SAFE_DELETE(instance);
  41. }
  42. return 0;
  43. }
  44. lua_pushstring(state, "lua_Keyboard__gc - Failed to match the given parameters to a valid function signature.");
  45. lua_error(state);
  46. break;
  47. }
  48. default:
  49. {
  50. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  51. lua_error(state);
  52. break;
  53. }
  54. }
  55. return 0;
  56. }
  57. }