SelectOptionsProxy.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "SelectOptionsProxy.h"
  2. #include "../Pairs.h"
  3. #include <RmlUi/Core/Element.h>
  4. namespace Rml {
  5. namespace Lua {
  6. int SelectOptionsProxy__index(lua_State* L)
  7. {
  8. /*the table obj and the missing key are currently on the stack(index 1 & 2) as defined by the Lua language*/
  9. int keytype = lua_type(L, 2);
  10. if (keytype == LUA_TNUMBER) // only valid key types
  11. {
  12. SelectOptionsProxy* proxy = LuaType<SelectOptionsProxy>::check(L, 1);
  13. RMLUI_CHECK_OBJ(proxy);
  14. int index = (int)luaL_checkinteger(L, 2);
  15. Element* opt = proxy->owner->GetOption(index - 1);
  16. RMLUI_CHECK_OBJ(opt);
  17. lua_newtable(L);
  18. LuaType<Element>::push(L, opt, false);
  19. lua_setfield(L, -2, "element");
  20. lua_pushstring(L, opt->GetAttribute("value", String()).c_str());
  21. lua_setfield(L, -2, "value");
  22. return 1;
  23. }
  24. else
  25. return LuaType<SelectOptionsProxy>::index(L);
  26. }
  27. int SelectOptionsProxy__pairs(lua_State* L)
  28. {
  29. return MakeIntPairs(L);
  30. }
  31. RegType<SelectOptionsProxy> SelectOptionsProxyMethods[] = {
  32. {nullptr, nullptr},
  33. };
  34. luaL_Reg SelectOptionsProxyGetters[] = {
  35. {nullptr, nullptr},
  36. };
  37. luaL_Reg SelectOptionsProxySetters[] = {
  38. {nullptr, nullptr},
  39. };
  40. template <>
  41. void ExtraInit<SelectOptionsProxy>(lua_State* L, int metatable_index)
  42. {
  43. lua_pushcfunction(L, SelectOptionsProxy__index);
  44. lua_setfield(L, metatable_index, "__index");
  45. lua_pushcfunction(L, SelectOptionsProxy__pairs);
  46. lua_setfield(L, metatable_index, "__pairs");
  47. }
  48. RMLUI_LUATYPE_DEFINE(SelectOptionsProxy)
  49. } // namespace Lua
  50. } // namespace Rml