lua_ThemeStyle.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_ThemeStyle.h"
  4. #include "ThemeStyle.h"
  5. namespace gameplay
  6. {
  7. void luaRegister_ThemeStyle()
  8. {
  9. const luaL_Reg lua_members[] =
  10. {
  11. {"getTheme", lua_ThemeStyle_getTheme},
  12. {NULL, NULL}
  13. };
  14. const luaL_Reg* lua_statics = NULL;
  15. std::vector<std::string> scopePath;
  16. scopePath.push_back("Theme");
  17. gameplay::ScriptUtil::registerClass("ThemeStyle", lua_members, NULL, NULL, lua_statics, scopePath);
  18. }
  19. static Theme::Style* getInstance(lua_State* state)
  20. {
  21. void* userdata = luaL_checkudata(state, 1, "ThemeStyle");
  22. luaL_argcheck(state, userdata != NULL, 1, "'ThemeStyle' expected.");
  23. return (Theme::Style*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  24. }
  25. int lua_ThemeStyle_getTheme(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. Theme::Style* instance = getInstance(state);
  37. void* returnPtr = (void*)instance->getTheme();
  38. if (returnPtr)
  39. {
  40. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  41. object->instance = returnPtr;
  42. object->owns = false;
  43. luaL_getmetatable(state, "Theme");
  44. lua_setmetatable(state, -2);
  45. }
  46. else
  47. {
  48. lua_pushnil(state);
  49. }
  50. return 1;
  51. }
  52. lua_pushstring(state, "lua_ThemeStyle_getTheme - Failed to match the given parameters to a valid function signature.");
  53. lua_error(state);
  54. break;
  55. }
  56. default:
  57. {
  58. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  59. lua_error(state);
  60. break;
  61. }
  62. }
  63. return 0;
  64. }
  65. }