lua_Mouse.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Mouse.h"
  4. #include "Mouse.h"
  5. namespace gameplay
  6. {
  7. void luaRegister_Mouse()
  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. ScriptUtil::registerClass("Mouse", lua_members, NULL, lua_Mouse__gc, lua_statics, scopePath);
  16. }
  17. static Mouse* getInstance(lua_State* state)
  18. {
  19. void* userdata = luaL_checkudata(state, 1, "Mouse");
  20. luaL_argcheck(state, userdata != NULL, 1, "'Mouse' expected.");
  21. return (Mouse*)((ScriptUtil::LuaObject*)userdata)->instance;
  22. }
  23. int lua_Mouse__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, "Mouse");
  35. luaL_argcheck(state, userdata != NULL, 1, "'Mouse' expected.");
  36. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  37. if (object->owns)
  38. {
  39. Mouse* instance = (Mouse*)object->instance;
  40. SAFE_DELETE(instance);
  41. }
  42. return 0;
  43. }
  44. else
  45. {
  46. lua_pushstring(state, "lua_Mouse__gc - Failed to match the given parameters to a valid function signature.");
  47. lua_error(state);
  48. }
  49. break;
  50. }
  51. default:
  52. {
  53. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  54. lua_error(state);
  55. break;
  56. }
  57. }
  58. return 0;
  59. }
  60. }