RmlUiContextsProxy.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "RmlUiContextsProxy.h"
  2. #include "Pairs.h"
  3. #include <RmlUi/Core/Context.h>
  4. #include <RmlUi/Core/Core.h>
  5. namespace Rml {
  6. namespace Lua {
  7. template <>
  8. void ExtraInit<RmlUiContextsProxy>(lua_State* L, int metatable_index)
  9. {
  10. lua_pushcfunction(L, RmlUiContextsProxy__index);
  11. lua_setfield(L, metatable_index, "__index");
  12. lua_pushcfunction(L, RmlUiContextsProxy__pairs);
  13. lua_setfield(L, metatable_index, "__pairs");
  14. }
  15. int RmlUiContextsProxy__index(lua_State* L)
  16. {
  17. /*the table obj and the missing key are currently on the stack(index 1 & 2) as defined by the Lua language*/
  18. int keytype = lua_type(L, 2);
  19. if (keytype == LUA_TSTRING || keytype == LUA_TNUMBER) // only valid key types
  20. {
  21. RmlUiContextsProxy* obj = LuaType<RmlUiContextsProxy>::check(L, 1);
  22. RMLUI_CHECK_OBJ(obj);
  23. if (keytype == LUA_TSTRING)
  24. {
  25. const char* key = lua_tostring(L, 2);
  26. LuaType<Context>::push(L, GetContext(key));
  27. }
  28. else
  29. {
  30. int key = (int)luaL_checkinteger(L, 2);
  31. LuaType<Context>::push(L, GetContext(key - 1));
  32. }
  33. return 1;
  34. }
  35. else
  36. return LuaType<RmlUiContextsProxy>::index(L);
  37. }
  38. int RmlUiContextsProxy__pairs(lua_State* L)
  39. {
  40. return MakeIntPairs(L);
  41. }
  42. RegType<RmlUiContextsProxy> RmlUiContextsProxyMethods[] = {
  43. {nullptr, nullptr},
  44. };
  45. luaL_Reg RmlUiContextsProxyGetters[] = {
  46. {nullptr, nullptr},
  47. };
  48. luaL_Reg RmlUiContextsProxySetters[] = {
  49. {nullptr, nullptr},
  50. };
  51. RMLUI_LUATYPE_DEFINE(RmlUiContextsProxy)
  52. } // namespace Lua
  53. } // namespace Rml