ElementFormControlSelect.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "precompiled.h"
  2. #include "ElementFormControlSelect.h"
  3. #include <Rocket/Controls/ElementFormControlSelect.h>
  4. #include <Rocket/Controls/ElementFormControl.h>
  5. #include <Rocket/Core/Element.h>
  6. using Rocket::Controls::ElementFormControlSelect;
  7. using Rocket::Controls::ElementFormControl;
  8. namespace Rocket {
  9. namespace Core {
  10. namespace Lua {
  11. //inherits from ElementFormControl which inherits from Element
  12. //methods
  13. int ElementFormControlSelectAdd(lua_State* L, ElementFormControlSelect* obj)
  14. {
  15. const char* rml = luaL_checkstring(L,1);
  16. const char* value = luaL_checkstring(L,2);
  17. int before = -1; //default
  18. if(lua_gettop(L) >= 3)
  19. before = luaL_checkint(L,3);
  20. int index = obj->Add(rml,value,before);
  21. lua_pushinteger(L,index);
  22. return 1;
  23. }
  24. int ElementFormControlSelectRemove(lua_State* L, ElementFormControlSelect* obj)
  25. {
  26. int index = luaL_checkint(L,1);
  27. obj->Remove(index);
  28. return 0;
  29. }
  30. int ElementFormControlSelectGetOption(lua_State* L, ElementFormControlSelect* obj)
  31. {
  32. int index = luaL_checkint(L,1);
  33. Rocket::Controls::SelectOption* opt = obj->GetOption(index);
  34. lua_newtable(L);
  35. LuaType<Element>::push(L,opt->GetElement(),false);
  36. lua_setfield(L,-2,"element");
  37. lua_pushstring(L,opt->GetValue().CString());
  38. lua_setfield(L,-2,"value");
  39. return 1;
  40. }
  41. //getters
  42. int ElementFormControlSelectGetAttroptions(lua_State* L)
  43. {
  44. ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
  45. LUACHECKOBJ(obj);
  46. int numOptions = obj->GetNumOptions();
  47. //local variables for the loop
  48. Rocket::Controls::SelectOption* opt;
  49. Element* ele;
  50. String value;
  51. lua_newtable(L);
  52. int retindex = lua_gettop(L);
  53. for(int index = 0; index < numOptions; index++)
  54. {
  55. opt = obj->GetOption(index);
  56. if(opt == NULL) continue;
  57. ele = opt->GetElement();
  58. value = opt->GetValue();
  59. lua_newtable(L);
  60. LuaType<Element>::push(L,ele,false);
  61. lua_setfield(L,-2,"element");
  62. lua_pushstring(L,value.CString());
  63. lua_setfield(L,-2,"value");
  64. lua_rawseti(L,retindex,index); //sets the table that is being returned's 'index' to be the table with element and value
  65. lua_pop(L,1); //pops the table with element,value from the stack
  66. }
  67. return 1;
  68. }
  69. int ElementFormControlSelectGetAttrselection(lua_State* L)
  70. {
  71. ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
  72. LUACHECKOBJ(obj);
  73. int selection = obj->GetSelection();
  74. lua_pushinteger(L,selection);
  75. return 1;
  76. }
  77. //setter
  78. int ElementFormControlSelectSetAttrselection(lua_State* L)
  79. {
  80. ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
  81. LUACHECKOBJ(obj);
  82. int selection = luaL_checkint(L,2);
  83. obj->SetSelection(selection);
  84. return 0;
  85. }
  86. RegType<ElementFormControlSelect> ElementFormControlSelectMethods[] =
  87. {
  88. LUAMETHOD(ElementFormControlSelect,Add)
  89. LUAMETHOD(ElementFormControlSelect,Remove)
  90. LUAMETHOD(ElementFormControlSelect,GetOption)
  91. { NULL, NULL },
  92. };
  93. luaL_reg ElementFormControlSelectGetters[] =
  94. {
  95. LUAGETTER(ElementFormControlSelect,options)
  96. LUAGETTER(ElementFormControlSelect,selection)
  97. { NULL, NULL },
  98. };
  99. luaL_reg ElementFormControlSelectSetters[] =
  100. {
  101. LUASETTER(ElementFormControlSelect,selection)
  102. { NULL, NULL },
  103. };
  104. /*
  105. template<> const char* GetTClassName<ElementFormControlSelect>() { return "ElementFormControlSelect"; }
  106. template<> RegType<ElementFormControlSelect>* GetMethodTable<ElementFormControlSelect>() { return ElementFormControlSelectMethods; }
  107. template<> luaL_reg* GetAttrTable<ElementFormControlSelect>() { return ElementFormControlSelectGetters; }
  108. template<> luaL_reg* SetAttrTable<ElementFormControlSelect>() { return ElementFormControlSelectSetters; }
  109. */
  110. }
  111. }
  112. }