lua_Logger.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Logger.h"
  4. #include "Base.h"
  5. #include "Game.h"
  6. #include "Logger.h"
  7. #include "ScriptController.h"
  8. #include "lua_LoggerLevel.h"
  9. namespace gameplay
  10. {
  11. void luaRegister_Logger()
  12. {
  13. const luaL_Reg* lua_members = NULL;
  14. const luaL_Reg lua_statics[] =
  15. {
  16. {"isEnabled", lua_Logger_static_isEnabled},
  17. {"log", lua_Logger_static_log},
  18. {"set", lua_Logger_static_set},
  19. {"setEnabled", lua_Logger_static_setEnabled},
  20. {NULL, NULL}
  21. };
  22. std::vector<std::string> scopePath;
  23. ScriptUtil::registerClass("Logger", lua_members, NULL, NULL, lua_statics, scopePath);
  24. }
  25. static Logger* getInstance(lua_State* state)
  26. {
  27. void* userdata = luaL_checkudata(state, 1, "Logger");
  28. luaL_argcheck(state, userdata != NULL, 1, "'Logger' expected.");
  29. return (Logger*)((ScriptUtil::LuaObject*)userdata)->instance;
  30. }
  31. int lua_Logger_static_isEnabled(lua_State* state)
  32. {
  33. // Get the number of parameters.
  34. int paramCount = lua_gettop(state);
  35. // Attempt to match the parameters to a valid binding.
  36. switch (paramCount)
  37. {
  38. case 1:
  39. {
  40. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  41. {
  42. // Get parameter 1 off the stack.
  43. Logger::Level param1 = (Logger::Level)lua_enumFromString_LoggerLevel(luaL_checkstring(state, 1));
  44. bool result = Logger::isEnabled(param1);
  45. // Push the return value onto the stack.
  46. lua_pushboolean(state, result);
  47. return 1;
  48. }
  49. else
  50. {
  51. lua_pushstring(state, "lua_Logger_static_isEnabled - Failed to match the given parameters to a valid function signature.");
  52. lua_error(state);
  53. }
  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. int lua_Logger_static_log(lua_State* state)
  66. {
  67. // Get the number of parameters.
  68. int paramCount = lua_gettop(state);
  69. // Attempt to match the parameters to a valid binding.
  70. switch (paramCount)
  71. {
  72. case 2:
  73. {
  74. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  75. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  76. {
  77. // Get parameter 1 off the stack.
  78. Logger::Level param1 = (Logger::Level)lua_enumFromString_LoggerLevel(luaL_checkstring(state, 1));
  79. // Get parameter 2 off the stack.
  80. ScriptUtil::LuaArray<const char> param2 = ScriptUtil::getString(2, false);
  81. Logger::log(param1, param2);
  82. return 0;
  83. }
  84. else
  85. {
  86. lua_pushstring(state, "lua_Logger_static_log - Failed to match the given parameters to a valid function signature.");
  87. lua_error(state);
  88. }
  89. break;
  90. }
  91. default:
  92. {
  93. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  94. lua_error(state);
  95. break;
  96. }
  97. }
  98. return 0;
  99. }
  100. int lua_Logger_static_set(lua_State* state)
  101. {
  102. // Get the number of parameters.
  103. int paramCount = lua_gettop(state);
  104. // Attempt to match the parameters to a valid binding.
  105. switch (paramCount)
  106. {
  107. case 2:
  108. {
  109. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  110. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  111. {
  112. // Get parameter 1 off the stack.
  113. Logger::Level param1 = (Logger::Level)lua_enumFromString_LoggerLevel(luaL_checkstring(state, 1));
  114. // Get parameter 2 off the stack.
  115. ScriptUtil::LuaArray<const char> param2 = ScriptUtil::getString(2, false);
  116. Logger::set(param1, param2);
  117. return 0;
  118. }
  119. else
  120. {
  121. lua_pushstring(state, "lua_Logger_static_set - Failed to match the given parameters to a valid function signature.");
  122. lua_error(state);
  123. }
  124. break;
  125. }
  126. default:
  127. {
  128. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  129. lua_error(state);
  130. break;
  131. }
  132. }
  133. return 0;
  134. }
  135. int lua_Logger_static_setEnabled(lua_State* state)
  136. {
  137. // Get the number of parameters.
  138. int paramCount = lua_gettop(state);
  139. // Attempt to match the parameters to a valid binding.
  140. switch (paramCount)
  141. {
  142. case 2:
  143. {
  144. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  145. lua_type(state, 2) == LUA_TBOOLEAN)
  146. {
  147. // Get parameter 1 off the stack.
  148. Logger::Level param1 = (Logger::Level)lua_enumFromString_LoggerLevel(luaL_checkstring(state, 1));
  149. // Get parameter 2 off the stack.
  150. bool param2 = ScriptUtil::luaCheckBool(state, 2);
  151. Logger::setEnabled(param1, param2);
  152. return 0;
  153. }
  154. else
  155. {
  156. lua_pushstring(state, "lua_Logger_static_setEnabled - Failed to match the given parameters to a valid function signature.");
  157. lua_error(state);
  158. }
  159. break;
  160. }
  161. default:
  162. {
  163. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  164. lua_error(state);
  165. break;
  166. }
  167. }
  168. return 0;
  169. }
  170. }