ElementStyle.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include "precompiled.h"
  2. #include <Rocket/Core/Lua/LuaType.h>
  3. #include <Rocket/Core/Lua/lua.hpp>
  4. #include "ElementStyle.h"
  5. #include <ElementStyle.h>
  6. namespace Rocket {
  7. namespace Core {
  8. namespace Lua {
  9. int ElementStyle__index(lua_State* L)
  10. {
  11. /*the table obj and the missing key are currently on the stack(index 1 & 2) as defined by the Lua language*/
  12. int keytype = lua_type(L,2);
  13. if(keytype == LUA_TSTRING) //if we are trying to access a string, then we will assume that it is a property
  14. {
  15. ElementStyle* es = LuaType<ElementStyle>::check(L,1);
  16. if(es == NULL)
  17. {
  18. lua_pushnil(L);
  19. return 1;
  20. }
  21. const Property* prop = es->GetProperty(lua_tostring(L,2));
  22. if(prop == NULL)
  23. {
  24. lua_pushnil(L);
  25. return 1;
  26. }
  27. else
  28. {
  29. lua_pushstring(L,prop->ToString().CString());
  30. return 1;
  31. }
  32. }
  33. else //if it wasn't trying to get a string
  34. {
  35. lua_settop(L,2);
  36. return LuaType<ElementStyle>::index(L);
  37. }
  38. }
  39. int ElementStyle__newindex(lua_State* L)
  40. {
  41. //[1] = obj, [2] = key, [3] = value
  42. ElementStyle* es = LuaType<ElementStyle>::check(L,1);
  43. if(es == NULL)
  44. {
  45. lua_pushnil(L);
  46. return 1;
  47. }
  48. int keytype = lua_type(L,2);
  49. int valuetype = lua_type(L,3);
  50. if(keytype == LUA_TSTRING )
  51. {
  52. const char* key = lua_tostring(L,2);
  53. if(valuetype == LUA_TSTRING)
  54. {
  55. const char* value = lua_tostring(L,3);
  56. lua_pushboolean(L,es->SetProperty(key,value));
  57. return 1;
  58. }
  59. else if (valuetype == LUA_TNIL)
  60. {
  61. es->RemoveProperty(key);
  62. return 0;
  63. }
  64. }
  65. //everything else returns when it needs to, so we are safe to pass it
  66. //on if needed
  67. lua_settop(L,3);
  68. return LuaType<ElementStyle>::newindex(L);
  69. }
  70. int ElementStyleGetTable(lua_State* L, ElementStyle* obj)
  71. {
  72. int index = 0;
  73. String key,sval;
  74. const Property* value;
  75. PseudoClassList pseudo;
  76. lua_newtable(L);
  77. while(obj->IterateProperties(index,pseudo,key,value))
  78. {
  79. lua_pushstring(L,key.CString());
  80. value->definition->GetValue(sval,*value);
  81. lua_pushstring(L,sval.CString());
  82. lua_settable(L,-3);
  83. }
  84. return 1;
  85. }
  86. RegType<ElementStyle> ElementStyleMethods[] =
  87. {
  88. LUAMETHOD(ElementStyle,GetTable)
  89. { NULL, NULL },
  90. };
  91. luaL_reg ElementStyleGetters[] =
  92. {
  93. { NULL, NULL },
  94. };
  95. luaL_reg ElementStyleSetters[] =
  96. {
  97. { NULL, NULL },
  98. };
  99. /*
  100. template<> const char* GetTClassName<ElementStyle>() { return "ElementStyle"; }
  101. template<> RegType<ElementStyle>* GetMethodTable<ElementStyle>() { return ElementStyleMethods; }
  102. template<> luaL_reg* GetAttrTable<ElementStyle>() { return ElementStyleGetters; }
  103. template<> luaL_reg* SetAttrTable<ElementStyle>() { return ElementStyleSetters; }
  104. */
  105. }
  106. }
  107. }