SelectOptionsProxy.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "precompiled.h"
  2. #include "SelectOptionsProxy.h"
  3. #include <Rocket/Core/Element.h>
  4. namespace Rocket {
  5. namespace Core {
  6. namespace Lua {
  7. int SelectOptionsProxy__index(lua_State* L)
  8. {
  9. /*the table obj and the missing key are currently on the stack(index 1 & 2) as defined by the Lua language*/
  10. int keytype = lua_type(L,2);
  11. if(keytype == LUA_TNUMBER) //only valid key types
  12. {
  13. SelectOptionsProxy* proxy = LuaType<SelectOptionsProxy>::check(L,1);
  14. LUACHECKOBJ(proxy);
  15. int index = luaL_checkint(L,2);
  16. Rocket::Controls::SelectOption* opt = proxy->owner->GetOption(index);
  17. LUACHECKOBJ(opt);
  18. lua_newtable(L);
  19. LuaType<Element>::push(L,opt->GetElement(),false);
  20. lua_setfield(L,-2,"element");
  21. lua_pushstring(L,opt->GetValue().CString());
  22. lua_setfield(L,-2,"value");
  23. return 1;
  24. }
  25. else
  26. return LuaType<SelectOptionsProxy>::index(L);
  27. }
  28. //method
  29. int SelectOptionsProxyGetTable(lua_State* L, SelectOptionsProxy* obj)
  30. {
  31. int numOptions = obj->owner->GetNumOptions();
  32. //local variables for the loop
  33. Rocket::Controls::SelectOption* opt;
  34. Element* ele;
  35. String value;
  36. lua_newtable(L); //table to return
  37. int retindex = lua_gettop(L);
  38. for(int index = 0; index < numOptions; index++)
  39. {
  40. opt = obj->owner->GetOption(index);
  41. if(opt == NULL) continue;
  42. ele = opt->GetElement();
  43. value = opt->GetValue();
  44. lua_newtable(L);
  45. LuaType<Element>::push(L,ele,false);
  46. lua_setfield(L,-2,"element");
  47. lua_pushstring(L,value.CString());
  48. lua_setfield(L,-2,"value");
  49. lua_rawseti(L,retindex,index); //sets the table that is being returned's 'index' to be the table with element and value
  50. }
  51. return 1;
  52. }
  53. RegType<SelectOptionsProxy> SelectOptionsProxyMethods[] =
  54. {
  55. LUAMETHOD(SelectOptionsProxy,GetTable)
  56. { NULL, NULL },
  57. };
  58. luaL_reg SelectOptionsProxyGetters[] =
  59. {
  60. { NULL, NULL },
  61. };
  62. luaL_reg SelectOptionsProxySetters[] =
  63. {
  64. { NULL, NULL },
  65. };
  66. }
  67. }
  68. }