DataFormatter.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "precompiled.h"
  2. #include "DataFormatter.h"
  3. namespace Rocket {
  4. namespace Core {
  5. namespace Lua {
  6. //method
  7. int DataFormatternew(lua_State* L)
  8. {
  9. DataFormatter* df;
  10. int ref = LUA_NOREF;
  11. int top = lua_gettop(L);
  12. if(top == 0)
  13. df = new DataFormatter();
  14. else if (top > 0) //at least one element means at least a name
  15. {
  16. if(top > 1) //if a function as well
  17. {
  18. if(lua_type(L,2) != LUA_TFUNCTION)
  19. {
  20. Log::Message(Log::LT_ERROR, "Lua: In DataFormatter.new, the second argument MUST be a function (or not exist). You passed in a %s.", lua_typename(L,lua_type(L,2)));
  21. }
  22. else //if it is a function
  23. {
  24. LuaDataFormatter::PushDataFormatterFunctionTable(L);
  25. lua_pushvalue(L,2); //re-push the function so it is on the top of the stack
  26. ref = luaL_ref(L,-2);
  27. lua_pop(L,1); //pop the function table
  28. }
  29. }
  30. df = new DataFormatter(luaL_checkstring(L,1));
  31. df->ref_FormatData = ref; //will either be valid or LUA_NOREF
  32. }
  33. LuaType<DataFormatter>::push(L,df,true);
  34. return 1;
  35. }
  36. //setter
  37. int DataFormatterSetAttrFormatData(lua_State* L)
  38. {
  39. DataFormatter* obj = LuaType<DataFormatter>::check(L,1);
  40. LUACHECKOBJ(obj);
  41. int ref = LUA_NOREF;
  42. if(lua_type(L,2) != LUA_TFUNCTION)
  43. {
  44. Log::Message(Log::LT_ERROR, "Lua: Setting DataFormatter.FormatData, the value must be a function. You passed in a %s.", lua_typename(L,lua_type(L,2)));
  45. }
  46. else //if it is a function
  47. {
  48. LuaDataFormatter::PushDataFormatterFunctionTable(L);
  49. lua_pushvalue(L,2); //re-push the function so it is on the top of the stack
  50. ref = luaL_ref(L,-2);
  51. lua_pop(L,1); //pop the function table
  52. }
  53. obj->ref_FormatData = ref;
  54. return 0;
  55. }
  56. RegType<DataFormatter> DataFormatterMethods[] =
  57. {
  58. { NULL, NULL },
  59. };
  60. luaL_reg DataFormatterGetters[] =
  61. {
  62. { NULL, NULL },
  63. };
  64. luaL_reg DataFormatterSetters[] =
  65. {
  66. LUASETTER(DataFormatter,FormatData)
  67. { NULL, NULL },
  68. };
  69. }
  70. }
  71. }