Log.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "precompiled.h"
  2. #include "Log.h"
  3. #include <Rocket/Core/Log.h>
  4. namespace Rocket {
  5. namespace Core {
  6. namespace Lua {
  7. template<> void LuaType<Log>::extra_init(lua_State* L, int metatable_index)
  8. {
  9. //due to they way that LuaType::Register is made, we know that the method table is at the index
  10. //directly below the metatable
  11. int method_index = metatable_index - 1;
  12. lua_pushcfunction(L,Log__call);
  13. lua_setfield(L,metatable_index, "__call");
  14. //construct the "logtype" table, so that we can use the Rocket::Core::Log::Type enum like Log.logtype.always in Lua for Log::LT_ALWAYS
  15. lua_newtable(L);
  16. int logtype = lua_gettop(L);
  17. lua_pushvalue(L,-1); //copy of the new table, so that the logtype index will stay valid
  18. lua_setfield(L,method_index,"logtype");
  19. lua_pushinteger(L,(int)Log::LT_ALWAYS);
  20. lua_setfield(L,logtype,"always");
  21. lua_pushinteger(L,(int)Log::LT_ERROR);
  22. lua_setfield(L,logtype,"error");
  23. lua_pushinteger(L,(int)Log::LT_WARNING);
  24. lua_setfield(L,logtype,"warning");
  25. lua_pushinteger(L,(int)Log::LT_INFO);
  26. lua_setfield(L,logtype,"info");
  27. lua_pushinteger(L,(int)Log::LT_DEBUG);
  28. lua_setfield(L,logtype,"debug");
  29. lua_pop(L,1); //pop the logtype table
  30. return;
  31. }
  32. int Log__call(lua_State* L)
  33. {
  34. Log::Type type = Log::Type((int)luaL_checkinteger(L,1));
  35. const char* str = luaL_checkstring(L,2);
  36. Log::Message(type, str);
  37. return 0;
  38. }
  39. RegType<Log> LogMethods[] =
  40. {
  41. { NULL, NULL },
  42. };
  43. luaL_reg LogGetters[] =
  44. {
  45. { NULL, NULL },
  46. };
  47. luaL_reg LogSetters[] =
  48. {
  49. { NULL, NULL },
  50. };
  51. template<> const char* GetTClassName<Log>() { return "Log"; }
  52. template<> RegType<Log>* GetMethodTable<Log>() { return LogMethods; }
  53. template<> luaL_reg* GetAttrTable<Log>() { return LogGetters; }
  54. template<> luaL_reg* SetAttrTable<Log>() { return LogSetters; }
  55. }
  56. }
  57. }