DataSource.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include "precompiled.h"
  2. #include "DataSource.h"
  3. #include <Rocket/Core/Log.h>
  4. namespace Rocket {
  5. namespace Core {
  6. namespace Lua {
  7. typedef LuaDataSource DataSource;
  8. int DataSourceNotifyRowAdd(lua_State* L, DataSource* obj)
  9. {
  10. LUACHECKOBJ(obj);
  11. const char* table_name = luaL_checkstring(L,1);
  12. int first_row_added = luaL_checkint(L,2);
  13. int num_rows_added = luaL_checkint(L,3);
  14. obj->NotifyRowAdd(table_name,first_row_added,num_rows_added);
  15. return 0;
  16. }
  17. int DataSourceNotifyRowRemove(lua_State* L, DataSource* obj)
  18. {
  19. LUACHECKOBJ(obj);
  20. const char* table_name = luaL_checkstring(L,1);
  21. int first_row_removed = luaL_checkint(L,2);
  22. int num_rows_removed = luaL_checkint(L,3);
  23. obj->NotifyRowRemove(table_name,first_row_removed,num_rows_removed);
  24. return 0;
  25. }
  26. int DataSourceNotifyRowChange(lua_State* L, DataSource* obj)
  27. {
  28. LUACHECKOBJ(obj);
  29. const char* table_name = luaL_checkstring(L,1);
  30. if(lua_gettop(L) < 2)
  31. {
  32. obj->NotifyRowChange(table_name);
  33. }
  34. else
  35. {
  36. int first_row_changed = luaL_checkint(L,2);
  37. int num_rows_changed = luaL_checkint(L,3);
  38. obj->NotifyRowChange(table_name,first_row_changed,num_rows_changed);
  39. }
  40. return 0;
  41. }
  42. int DataSourceSetAttrGetNumRows(lua_State* L)
  43. {
  44. DataSource* obj = LuaType<DataSource>::check(L,1);
  45. LUACHECKOBJ(obj);
  46. if(lua_type(L,2) == LUA_TFUNCTION)
  47. {
  48. lua_pushvalue(L,2); //copy of the function, so it is for sure at the top of the stack
  49. obj->getNumRowsRef = lua_ref(L,true);
  50. }
  51. else
  52. Log::Message(Log::LT_WARNING, "Lua: Must assign DataSource.GetNumRows as a function, value received was of %s type", lua_typename(L,2));
  53. return 0;
  54. }
  55. int DataSourceSetAttrGetRow(lua_State* L)
  56. {
  57. DataSource* obj = LuaType<DataSource>::check(L,1);
  58. LUACHECKOBJ(obj);
  59. if(lua_type(L,2) == LUA_TFUNCTION)
  60. {
  61. lua_pushvalue(L,2); //copy of the functions, so it is for sure at the top of the stack
  62. obj->getRowRef = lua_ref(L,true);
  63. }
  64. else
  65. Log::Message(Log::LT_WARNING, "Lua: Must assign DataSource.GetRow as a function, value received was of %s type", lua_typename(L,2));
  66. return 0;
  67. }
  68. RegType<DataSource> DataSourceMethods[] =
  69. {
  70. LUAMETHOD(DataSource,NotifyRowAdd)
  71. LUAMETHOD(DataSource,NotifyRowRemove)
  72. LUAMETHOD(DataSource,NotifyRowChange)
  73. { NULL, NULL },
  74. };
  75. luaL_reg DataSourceGetters[] =
  76. {
  77. { NULL, NULL },
  78. };
  79. luaL_reg DataSourceSetters[] =
  80. {
  81. LUASETTER(DataSource,GetNumRows)
  82. LUASETTER(DataSource,GetRow)
  83. { NULL, NULL },
  84. };
  85. }
  86. }
  87. }