ElementStyle.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include "precompiled.h"
  2. #include "LuaType.h"
  3. #include "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. LUACHECKOBJ(obj);
  73. int index = 0;
  74. String key,sval;
  75. const Property* value;
  76. PseudoClassList pseudo;
  77. lua_newtable(L);
  78. while(obj->IterateProperties(index,pseudo,key,value))
  79. {
  80. lua_pushstring(L,key.CString());
  81. value->definition->GetValue(sval,*value);
  82. lua_pushstring(L,sval.CString());
  83. lua_settable(L,-3);
  84. }
  85. return 1;
  86. }
  87. RegType<ElementStyle> ElementStyleMethods[] =
  88. {
  89. LUAMETHOD(ElementStyle,GetTable)
  90. { NULL, NULL },
  91. };
  92. luaL_reg ElementStyleGetters[] =
  93. {
  94. { NULL, NULL },
  95. };
  96. luaL_reg ElementStyleSetters[] =
  97. {
  98. { NULL, NULL },
  99. };
  100. /*
  101. template<> const char* GetTClassName<ElementStyle>() { return "ElementStyle"; }
  102. template<> RegType<ElementStyle>* GetMethodTable<ElementStyle>() { return ElementStyleMethods; }
  103. template<> luaL_reg* GetAttrTable<ElementStyle>() { return ElementStyleGetters; }
  104. template<> luaL_reg* SetAttrTable<ElementStyle>() { return ElementStyleSetters; }
  105. */
  106. }
  107. }
  108. }