lua_Ref.cpp 3.4 KB

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