ElementAttributesProxy.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "precompiled.h"
  2. #include "ElementAttributesProxy.h"
  3. #include <Rocket/Core/Variant.h>
  4. #include "Utilities.h"
  5. namespace Rocket {
  6. namespace Core {
  7. namespace Lua {
  8. int ElementAttributesProxy__index(lua_State* L)
  9. {
  10. /*the table obj and the missing key are currently on the stack(index 1 & 2) as defined by the Lua language*/
  11. int keytype = lua_type(L,2);
  12. if(keytype == LUA_TSTRING) //only valid key types
  13. {
  14. ElementAttributesProxy* obj = LuaType<ElementAttributesProxy>::check(L,1);
  15. LUACHECKOBJ(obj);
  16. const char* key = lua_tostring(L,2);
  17. Variant* attr = obj->owner->GetAttribute(key);
  18. PushVariant(L,attr); //Utilities.h
  19. return 1;
  20. }
  21. else
  22. return LuaType<ElementAttributesProxy>::index(L);
  23. }
  24. //method
  25. int ElementAttributesProxyGetTable(lua_State* L, ElementAttributesProxy* obj)
  26. {
  27. int index;
  28. String key;
  29. Variant* var;
  30. lua_newtable(L);
  31. int tbl = lua_gettop(L);
  32. while(obj->owner->IterateAttributes(index,key,var))
  33. {
  34. lua_pushstring(L,key.CString());
  35. PushVariant(L,var);
  36. lua_settable(L,tbl);
  37. }
  38. return 1;
  39. }
  40. RegType<ElementAttributesProxy> ElementAttributesProxyMethods[] =
  41. {
  42. LUAMETHOD(ElementAttributesProxy,GetTable)
  43. { NULL, NULL },
  44. };
  45. luaL_reg ElementAttributesProxyGetters[] =
  46. {
  47. { NULL, NULL },
  48. };
  49. luaL_reg ElementAttributesProxySetters[] =
  50. {
  51. { NULL, NULL },
  52. };
  53. }
  54. }
  55. }