Browse Source

Made ElementStyle in to ElementStyleProxy.

This made it more consistent with all of the other proxy tables, and removed the exposure of ElementStyle to the .dll
Nate Starkey 13 years ago
parent
commit
8fdb904cd2

+ 2 - 2
Build/RocketCoreLua.vcproj

@@ -283,11 +283,11 @@
 					>
 					>
 				</File>
 				</File>
 				<File
 				<File
-					RelativePath="..\Source\Core\Lua\ElementStyle.cpp"
+					RelativePath="..\Source\Core\Lua\ElementStyleProxy.cpp"
 					>
 					>
 				</File>
 				</File>
 				<File
 				<File
-					RelativePath="..\Source\Core\Lua\ElementStyle.h"
+					RelativePath="..\Source\Core\Lua\ElementStyleProxy.h"
 					>
 					>
 				</File>
 				</File>
 				<File
 				<File

+ 1 - 1
Source/Core/ElementStyle.h

@@ -39,7 +39,7 @@ namespace Core {
 	@author Lloyd Weehuizen
 	@author Lloyd Weehuizen
  */
  */
 
 
-class ROCKETCORE_API ElementStyle
+class ElementStyle
 {
 {
 public:
 public:
 	/// Constructor
 	/// Constructor

+ 17 - 2
Source/Core/Lua/Element.cpp

@@ -27,7 +27,7 @@
  
  
 #include "precompiled.h"
 #include "precompiled.h"
 #include "Element.h"
 #include "Element.h"
-#include <../Source/Core/ElementStyle.h>
+#include "ElementStyleProxy.h"
 #include "LuaEventListener.h"
 #include "LuaEventListener.h"
 #include "ElementAttributesProxy.h"
 #include "ElementAttributesProxy.h"
 #include "ElementChildNodesProxy.h"
 #include "ElementChildNodesProxy.h"
@@ -427,6 +427,7 @@ int ElementGetAttrowner_document(lua_State* L)
 int ElementGetAttrparent_node(lua_State* L)
 int ElementGetAttrparent_node(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
     Element* parent = ele->GetParentNode();
     Element* parent = ele->GetParentNode();
     if(parent == NULL)
     if(parent == NULL)
         lua_pushnil(L);
         lua_pushnil(L);
@@ -438,6 +439,7 @@ int ElementGetAttrparent_node(lua_State* L)
 int ElementGetAttrprevious_sibling(lua_State* L)
 int ElementGetAttrprevious_sibling(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
     Element* sibling = ele->GetPreviousSibling();
     Element* sibling = ele->GetPreviousSibling();
     if(sibling == NULL)
     if(sibling == NULL)
         lua_pushnil(L);
         lua_pushnil(L);
@@ -449,6 +451,7 @@ int ElementGetAttrprevious_sibling(lua_State* L)
 int ElementGetAttrscroll_height(lua_State* L)
 int ElementGetAttrscroll_height(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
     lua_pushnumber(L,ele->GetScrollHeight());
     lua_pushnumber(L,ele->GetScrollHeight());
     return 1;
     return 1;
 }
 }
@@ -456,6 +459,7 @@ int ElementGetAttrscroll_height(lua_State* L)
 int ElementGetAttrscroll_left(lua_State* L)
 int ElementGetAttrscroll_left(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
     lua_pushnumber(L,ele->GetScrollLeft());
     lua_pushnumber(L,ele->GetScrollLeft());
     return 1;
     return 1;
 }
 }
@@ -463,6 +467,7 @@ int ElementGetAttrscroll_left(lua_State* L)
 int ElementGetAttrscroll_top(lua_State* L)
 int ElementGetAttrscroll_top(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
     lua_pushnumber(L,ele->GetScrollTop());
     lua_pushnumber(L,ele->GetScrollTop());
     return 1;
     return 1;
 }
 }
@@ -470,6 +475,7 @@ int ElementGetAttrscroll_top(lua_State* L)
 int ElementGetAttrscroll_width(lua_State* L)
 int ElementGetAttrscroll_width(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
     lua_pushnumber(L,ele->GetScrollWidth());
     lua_pushnumber(L,ele->GetScrollWidth());
     return 1;
     return 1;
 }
 }
@@ -477,13 +483,17 @@ int ElementGetAttrscroll_width(lua_State* L)
 int ElementGetAttrstyle(lua_State* L)
 int ElementGetAttrstyle(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
-    LuaType<ElementStyle>::push(L,ele->GetStyle(),false);
+    LUACHECKOBJ(ele);
+    ElementStyleProxy* prox = new ElementStyleProxy();
+    prox->owner = ele;
+    LuaType<ElementStyleProxy>::push(L,prox,true);
     return 1;
     return 1;
 }
 }
 
 
 int ElementGetAttrtag_name(lua_State* L)
 int ElementGetAttrtag_name(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
     lua_pushstring(L,ele->GetTagName().CString());
     lua_pushstring(L,ele->GetTagName().CString());
     return 0;
     return 0;
 }
 }
@@ -493,6 +503,7 @@ int ElementGetAttrtag_name(lua_State* L)
 int ElementSetAttrclass_name(lua_State* L)
 int ElementSetAttrclass_name(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
     const char* name = luaL_checkstring(L,2);
     const char* name = luaL_checkstring(L,2);
     ele->SetClassNames(name);
     ele->SetClassNames(name);
     return 0;
     return 0;
@@ -501,6 +512,7 @@ int ElementSetAttrclass_name(lua_State* L)
 int ElementSetAttrid(lua_State* L)
 int ElementSetAttrid(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
     const char* id = luaL_checkstring(L,2);
     const char* id = luaL_checkstring(L,2);
     ele->SetId(id);
     ele->SetId(id);
     return 0;
     return 0;
@@ -509,6 +521,7 @@ int ElementSetAttrid(lua_State* L)
 int ElementSetAttrinner_rml(lua_State* L)
 int ElementSetAttrinner_rml(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
     const char* rml = luaL_checkstring(L,2);
     const char* rml = luaL_checkstring(L,2);
     ele->SetInnerRML(rml);
     ele->SetInnerRML(rml);
     return 0;
     return 0;
@@ -517,6 +530,7 @@ int ElementSetAttrinner_rml(lua_State* L)
 int ElementSetAttrscroll_left(lua_State* L)
 int ElementSetAttrscroll_left(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
     float scroll = (float)luaL_checknumber(L,2);
     float scroll = (float)luaL_checknumber(L,2);
     ele->SetScrollLeft(scroll);
     ele->SetScrollLeft(scroll);
     return 0;
     return 0;
@@ -525,6 +539,7 @@ int ElementSetAttrscroll_left(lua_State* L)
 int ElementSetAttrscroll_top(lua_State* L)
 int ElementSetAttrscroll_top(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
     float scroll = (float)luaL_checknumber(L,2);
     float scroll = (float)luaL_checknumber(L,2);
     ele->SetScrollTop(scroll);
     ele->SetScrollTop(scroll);
     return 0;
     return 0;

+ 28 - 44
Source/Core/Lua/ElementStyle.cpp → Source/Core/Lua/ElementStyleProxy.cpp

@@ -28,67 +28,51 @@
 #include "precompiled.h"
 #include "precompiled.h"
 #include <Rocket/Core/Lua/LuaType.h>
 #include <Rocket/Core/Lua/LuaType.h>
 #include <Rocket/Core/Lua/lua.hpp>
 #include <Rocket/Core/Lua/lua.hpp>
-#include "ElementStyle.h"
-#include <../Source/Core/ElementStyle.h>
+#include "ElementStyleProxy.h"
 
 
 namespace Rocket {
 namespace Rocket {
 namespace Core {
 namespace Core {
 namespace Lua {
 namespace Lua {
-template<> void ExtraInit<ElementStyle>(lua_State* L, int metatable_index)
+template<> void ExtraInit<ElementStyleProxy>(lua_State* L, int metatable_index)
 {
 {
-    lua_pushcfunction(L,ElementStyle__index);
+    lua_pushcfunction(L,ElementStyleProxy__index);
     lua_setfield(L,metatable_index,"__index");
     lua_setfield(L,metatable_index,"__index");
 
 
-    lua_pushcfunction(L,ElementStyle__newindex);
+    lua_pushcfunction(L,ElementStyleProxy__newindex);
     lua_setfield(L,metatable_index,"__newindex");
     lua_setfield(L,metatable_index,"__newindex");
 
 
-    lua_pushcfunction(L,ElementStyle__pairs);
+    lua_pushcfunction(L,ElementStyleProxy__pairs);
     lua_setfield(L,metatable_index,"__pairs");
     lua_setfield(L,metatable_index,"__pairs");
 
 
-    lua_pushcfunction(L,ElementStyle__ipairs);
+    lua_pushcfunction(L,ElementStyleProxy__ipairs);
     lua_setfield(L,metatable_index,"__ipairs");
     lua_setfield(L,metatable_index,"__ipairs");
 }
 }
 
 
-int ElementStyle__index(lua_State* L)
+int ElementStyleProxy__index(lua_State* L)
 {
 {
     /*the table obj and the missing key are currently on the stack(index 1 & 2) as defined by the Lua language*/
     /*the table obj and the missing key are currently on the stack(index 1 & 2) as defined by the Lua language*/
     int keytype = lua_type(L,2);
     int keytype = lua_type(L,2);
     if(keytype == LUA_TSTRING) //if we are trying to access a string, then we will assume that it is a property
     if(keytype == LUA_TSTRING) //if we are trying to access a string, then we will assume that it is a property
     {
     {
-        ElementStyle* es = LuaType<ElementStyle>::check(L,1);
-        if(es == NULL)
-        {
-            lua_pushnil(L);
-            return 1;
-        }
-        const Property* prop = es->GetProperty(lua_tostring(L,2));
-        if(prop == NULL)
-        {
-            lua_pushnil(L);
-            return 1;
-        }
-        else
-        {
-            lua_pushstring(L,prop->ToString().CString());
-            return 1;
-        }
+        ElementStyleProxy* es = LuaType<ElementStyleProxy>::check(L,1);
+        LUACHECKOBJ(es);
+        const Property* prop = es->owner->GetProperty(lua_tostring(L,2));
+        LUACHECKOBJ(prop)
+        lua_pushstring(L,prop->ToString().CString());
+        return 1;
     }
     }
     else //if it wasn't trying to get a string
     else //if it wasn't trying to get a string
     {
     {
         lua_settop(L,2);
         lua_settop(L,2);
-        return LuaType<ElementStyle>::index(L);
+        return LuaType<ElementStyleProxy>::index(L);
     }
     }
 }
 }
 
 
-int ElementStyle__newindex(lua_State* L)
+int ElementStyleProxy__newindex(lua_State* L)
 {
 {
     //[1] = obj, [2] = key, [3] = value
     //[1] = obj, [2] = key, [3] = value
-    ElementStyle* es = LuaType<ElementStyle>::check(L,1);
-    if(es == NULL)
-    {
-        lua_pushnil(L);
-        return 1;
-    }
+    ElementStyleProxy* es = LuaType<ElementStyleProxy>::check(L,1);
+    LUACHECKOBJ(es);
     int keytype = lua_type(L,2);
     int keytype = lua_type(L,2);
     int valuetype = lua_type(L,3);
     int valuetype = lua_type(L,3);
     if(keytype == LUA_TSTRING )
     if(keytype == LUA_TSTRING )
@@ -97,12 +81,12 @@ int ElementStyle__newindex(lua_State* L)
         if(valuetype == LUA_TSTRING)
         if(valuetype == LUA_TSTRING)
         {
         {
             const char* value = lua_tostring(L,3);
             const char* value = lua_tostring(L,3);
-            lua_pushboolean(L,es->SetProperty(key,value));
+            lua_pushboolean(L,es->owner->SetProperty(key,value));
             return 1; 
             return 1; 
         }
         }
         else if (valuetype == LUA_TNIL)
         else if (valuetype == LUA_TNIL)
         {
         {
-            es->RemoveProperty(key);
+            es->owner->RemoveProperty(key);
             return 0;
             return 0;
         }
         }
     }
     }
@@ -110,14 +94,14 @@ int ElementStyle__newindex(lua_State* L)
     //on if needed
     //on if needed
 
 
     lua_settop(L,3);
     lua_settop(L,3);
-    return LuaType<ElementStyle>::newindex(L);
+    return LuaType<ElementStyleProxy>::newindex(L);
 
 
 }
 }
 
 
 //[1] is the object, [2] is the last used key, [3] is the userdata
 //[1] is the object, [2] is the last used key, [3] is the userdata
-int ElementStyle__pairs(lua_State* L)
+int ElementStyleProxy__pairs(lua_State* L)
 {
 {
-    ElementStyle* obj = LuaType<ElementStyle>::check(L,1);
+    ElementStyleProxy* obj = LuaType<ElementStyleProxy>::check(L,1);
     LUACHECKOBJ(obj);
     LUACHECKOBJ(obj);
     int* pindex = (int*)lua_touserdata(L,3);
     int* pindex = (int*)lua_touserdata(L,3);
     if((*pindex) == -1)
     if((*pindex) == -1)
@@ -126,7 +110,7 @@ int ElementStyle__pairs(lua_State* L)
     String key,val;
     String key,val;
     const Property* prop;
     const Property* prop;
     PseudoClassList pseudo;
     PseudoClassList pseudo;
-    if(obj->IterateProperties((*pindex),pseudo,key,prop))
+    if(obj->owner->IterateProperties((*pindex),pseudo,key,prop))
     {
     {
         prop->definition->GetValue(val,*prop);
         prop->definition->GetValue(val,*prop);
         lua_pushstring(L,key.CString());
         lua_pushstring(L,key.CString());
@@ -141,29 +125,29 @@ int ElementStyle__pairs(lua_State* L)
 }
 }
 
 
 //only indexed by string
 //only indexed by string
-int ElementStyle__ipairs(lua_State* L)
+int ElementStyleProxy__ipairs(lua_State* L)
 {
 {
     lua_pushnil(L);
     lua_pushnil(L);
     lua_pushnil(L);
     lua_pushnil(L);
     return 2;
     return 2;
 }
 }
 
 
-RegType<ElementStyle> ElementStyleMethods[] = 
+RegType<ElementStyleProxy> ElementStyleProxyMethods[] = 
 {
 {
     { NULL, NULL },
     { NULL, NULL },
 };
 };
 
 
-luaL_reg ElementStyleGetters[] = 
+luaL_reg ElementStyleProxyGetters[] = 
 {
 {
     { NULL, NULL },
     { NULL, NULL },
 };
 };
 
 
-luaL_reg ElementStyleSetters[] = 
+luaL_reg ElementStyleProxySetters[] = 
 {
 {
     { NULL, NULL },
     { NULL, NULL },
 };
 };
 
 
-LUACORETYPEDEFINE(ElementStyle,false)
+LUACORETYPEDEFINE(ElementStyleProxy,false)
 }
 }
 }
 }
 }
 }

+ 13 - 12
Source/Core/Lua/ElementStyle.h → Source/Core/Lua/ElementStyleProxy.h

@@ -25,27 +25,28 @@
  *
  *
  */
  */
  
  
-#ifndef ROCKETCORELUAELEMENTSTYLE_H
-#define ROCKETCORELUAELEMENTSTYLE_H
+#ifndef ROCKETCORELUAELEMENTSTYLEPROXY_H
+#define ROCKETCORELUAELEMENTSTYLEPROXY_H
 
 
 #include <Rocket/Core/Lua/LuaType.h>
 #include <Rocket/Core/Lua/LuaType.h>
 #include <Rocket/Core/Lua/lua.hpp>
 #include <Rocket/Core/Lua/lua.hpp>
-#include <../Source/Core/ElementStyle.h>
 
 
 namespace Rocket {
 namespace Rocket {
 namespace Core {
 namespace Core {
 namespace Lua {
 namespace Lua {
-template<> void ExtraInit<ElementStyle>(lua_State* L, int metatable_index);
-int ElementStyle__index(lua_State* L);
-int ElementStyle__newindex(lua_State* L);
-int ElementStyle__pairs(lua_State* L);
-int ElementStyle__ipairs(lua_State* L);
+struct ElementStyleProxy { Element* owner; };
 
 
-extern RegType<ElementStyle> ElementStyleMethods[];
-extern luaL_reg ElementStyleGetters[];
-extern luaL_reg ElementStyleSetters[];
+template<> void ExtraInit<ElementStyleProxy>(lua_State* L, int metatable_index);
+int ElementStyleProxy__index(lua_State* L);
+int ElementStyleProxy__newindex(lua_State* L);
+int ElementStyleProxy__pairs(lua_State* L);
+int ElementStyleProxy__ipairs(lua_State* L);
 
 
-LUACORETYPEDECLARE(ElementStyle)
+extern RegType<ElementStyleProxy> ElementStyleProxyMethods[];
+extern luaL_reg ElementStyleProxyGetters[];
+extern luaL_reg ElementStyleProxySetters[];
+
+LUACORETYPEDECLARE(ElementStyleProxy)
 }
 }
 }
 }
 }
 }

+ 2 - 3
Source/Core/Lua/Interpreter.cpp

@@ -35,14 +35,13 @@
 #include <Rocket/Core/Factory.h>
 #include <Rocket/Core/Factory.h>
 #include "LuaEventListenerInstancer.h"
 #include "LuaEventListenerInstancer.h"
 #include "Rocket.h"
 #include "Rocket.h"
-#include <../Source/Core/ElementStyle.h>
 //the types I made
 //the types I made
 #include "ContextDocumentsProxy.h"
 #include "ContextDocumentsProxy.h"
 #include "EventParametersProxy.h"
 #include "EventParametersProxy.h"
 #include "ElementAttributesProxy.h"
 #include "ElementAttributesProxy.h"
 #include "Log.h"
 #include "Log.h"
 #include "Element.h"
 #include "Element.h"
-#include "ElementStyle.h"
+#include "ElementStyleProxy.h"
 #include "Document.h"
 #include "Document.h"
 #include "Colourb.h"
 #include "Colourb.h"
 #include "Colourf.h"
 #include "Colourf.h"
@@ -80,7 +79,7 @@ void Interpreter::RegisterCoreTypes(lua_State* L)
     LuaType<Colourf>::Register(L);
     LuaType<Colourf>::Register(L);
     LuaType<Colourb>::Register(L);
     LuaType<Colourb>::Register(L);
     LuaType<Log>::Register(L);
     LuaType<Log>::Register(L);
-    LuaType<ElementStyle>::Register(L);
+    LuaType<ElementStyleProxy>::Register(L);
     LuaType<Element>::Register(L);
     LuaType<Element>::Register(L);
         //things that inherit from Element
         //things that inherit from Element
         LuaType<Document>::Register(L);
         LuaType<Document>::Register(L);