Browse Source

Added another proxy table, this time for Element.child_nodes.

Made some javadoc-type documentation for the files in Include/Rocket/*/Lua

Changed some names, removed some commented out code.
Nate Starkey 13 years ago
parent
commit
012103ebf2

+ 0 - 4
Build/RocketControlsLua.vcproj

@@ -304,10 +304,6 @@
 				</File>
 				</File>
 			</Filter>
 			</Filter>
 		</Filter>
 		</Filter>
-		<File
-			RelativePath="..\Source\Controls\Lua\As.h"
-			>
-		</File>
 		<File
 		<File
 			RelativePath="..\Source\Controls\Lua\Controls.cpp"
 			RelativePath="..\Source\Controls\Lua\Controls.cpp"
 			>
 			>

+ 12 - 12
Build/RocketCoreLua.vcproj

@@ -41,7 +41,7 @@
 			<Tool
 			<Tool
 				Name="VCCLCompilerTool"
 				Name="VCCLCompilerTool"
 				Optimization="0"
 				Optimization="0"
-				AdditionalIncludeDirectories="&quot;$(SolutionDir)..\Include&quot;;&quot;$(SolutionDir)..\Source\Core&quot;;&quot;$(SolutionDir)..\Dependencies\lua\src&quot;;&quot;$(SolutionDir)..\Source\Controls\Lua&quot;"
+				AdditionalIncludeDirectories="&quot;$(SolutionDir)..\Include&quot;;&quot;$(SolutionDir)..\Source\Core&quot;;&quot;$(SolutionDir)..\Dependencies\lua\src&quot;"
 				PreprocessorDefinitions="_WIN32,_DEBUG,RocketLua_EXPORTS"
 				PreprocessorDefinitions="_WIN32,_DEBUG,RocketLua_EXPORTS"
 				MinimalRebuild="true"
 				MinimalRebuild="true"
 				BasicRuntimeChecks="3"
 				BasicRuntimeChecks="3"
@@ -63,7 +63,7 @@
 			<Tool
 			<Tool
 				Name="VCLinkerTool"
 				Name="VCLinkerTool"
 				LinkLibraryDependencies="false"
 				LinkLibraryDependencies="false"
-				AdditionalDependencies="lua51.lib RocketCore_d.lib RocketControls_d.lib"
+				AdditionalDependencies="lua51.lib RocketCore_d.lib"
 				ShowProgress="0"
 				ShowProgress="0"
 				OutputFile="..\bin\$(ProjectName)_d.dll"
 				OutputFile="..\bin\$(ProjectName)_d.dll"
 				AdditionalLibraryDirectories="$(SolutionDir)..\bin"
 				AdditionalLibraryDirectories="$(SolutionDir)..\bin"
@@ -124,7 +124,7 @@
 				InlineFunctionExpansion="0"
 				InlineFunctionExpansion="0"
 				EnableIntrinsicFunctions="true"
 				EnableIntrinsicFunctions="true"
 				WholeProgramOptimization="true"
 				WholeProgramOptimization="true"
-				AdditionalIncludeDirectories="&quot;$(SolutionDir)..\Include&quot;;&quot;$(SolutionDir)..\Source\Core&quot;;&quot;$(SolutionDir)..\Dependencies\lua\src&quot;;&quot;$(SolutionDir)..\Source\Controls\Lua&quot;"
+				AdditionalIncludeDirectories="&quot;$(SolutionDir)..\Include&quot;;&quot;$(SolutionDir)..\Source\Core&quot;;&quot;$(SolutionDir)..\Dependencies\lua\src&quot;"
 				PreprocessorDefinitions="_WIN32,NDEBUG,RocketLua_EXPORTS"
 				PreprocessorDefinitions="_WIN32,NDEBUG,RocketLua_EXPORTS"
 				RuntimeLibrary="2"
 				RuntimeLibrary="2"
 				EnableFunctionLevelLinking="true"
 				EnableFunctionLevelLinking="true"
@@ -145,7 +145,7 @@
 			<Tool
 			<Tool
 				Name="VCLinkerTool"
 				Name="VCLinkerTool"
 				LinkLibraryDependencies="true"
 				LinkLibraryDependencies="true"
-				AdditionalDependencies="lua51.lib RocketCore.lib RocketControls.lib"
+				AdditionalDependencies="lua51.lib RocketCore.lib"
 				ShowProgress="0"
 				ShowProgress="0"
 				OutputFile="..\bin\$(ProjectName).dll"
 				OutputFile="..\bin\$(ProjectName).dll"
 				AdditionalLibraryDirectories="$(SolutionDir)..\bin"
 				AdditionalLibraryDirectories="$(SolutionDir)..\bin"
@@ -223,14 +223,6 @@
 				RelativePath="..\Source\Core\Lua\Rocket.h"
 				RelativePath="..\Source\Core\Lua\Rocket.h"
 				>
 				>
 			</File>
 			</File>
-			<File
-				RelativePath="..\Source\Core\Lua\RocketLua.cpp"
-				>
-			</File>
-			<File
-				RelativePath="..\Source\Core\Lua\RocketLua.h"
-				>
-			</File>
 			<File
 			<File
 				RelativePath="..\Source\Core\Lua\Utilities.cpp"
 				RelativePath="..\Source\Core\Lua\Utilities.cpp"
 				>
 				>
@@ -258,6 +250,14 @@
 					RelativePath="..\Source\Core\Lua\ElementAttributesProxy.h"
 					RelativePath="..\Source\Core\Lua\ElementAttributesProxy.h"
 					>
 					>
 				</File>
 				</File>
+				<File
+					RelativePath="..\Source\Core\Lua\ElementChildNodesProxy.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\Source\Core\Lua\ElementChildNodesProxy.h"
+					>
+				</File>
 				<File
 				<File
 					RelativePath="..\Source\Core\Lua\ElementInstancer.cpp"
 					RelativePath="..\Source\Core\Lua\ElementInstancer.cpp"
 					>
 					>

+ 6 - 6
Include/Rocket/Controls/Lua/Controls.h

@@ -33,13 +33,13 @@
 namespace Rocket {
 namespace Rocket {
 namespace Controls {
 namespace Controls {
 namespace Lua {
 namespace Lua {
-
-//This will define all of the types from RocketControls for Lua. There is not a
-//corresponding function for types of RocketCore, because they are defined automatically
-//when the Interpreter starts.
-ROCKETLUA_API void RegisterTypes(lua_State* L);
+/** Doxygen doesn't like to get the namespace, so the full name is
+@c Rocket::Controls::Lua::RegisterTypes.
+This will define all of the types from RocketControls for Lua. 
+@sa Rocket::Core::Lua::Interpreter::RegisterCoreTypes(lua_State*)
+@relatesalso Rocket::Core::Lua::Interpreter*/
+void ROCKETLUA_API RegisterTypes(lua_State* L);
 }
 }
 }
 }
 }
 }
-
 #endif
 #endif

+ 56 - 27
Include/Rocket/Core/Lua/Interpreter.h

@@ -27,10 +27,7 @@
  
  
 #ifndef ROCKETCORELUAINTERPRETER_H
 #ifndef ROCKETCORELUAINTERPRETER_H
 #define ROCKETCORELUAINTERPRETER_H 
 #define ROCKETCORELUAINTERPRETER_H 
-/*
-    This initializes the lua interpreter, and has functions to load the scripts
-    A glorified namespace, but I want the lua_State to be unchangeable
-*/
+
 #include "Header.h"
 #include "Header.h"
 #include <Rocket/Core/Lua/lua.hpp>
 #include <Rocket/Core/Lua/lua.hpp>
 #include <Rocket/Core/Plugin.h>
 #include <Rocket/Core/Plugin.h>
@@ -39,50 +36,82 @@ namespace Rocket {
 namespace Core {
 namespace Core {
 namespace Lua {
 namespace Lua {
 
 
+/**
+    This initializes the Lua interpreter, and has functions to load the scripts or
+    call functions that exist in Lua.
+
+    @author Nathan Starkey
+*/
 class ROCKETLUA_API Interpreter : public Plugin
 class ROCKETLUA_API Interpreter : public Plugin
 {
 {
 public:
 public:
-    //Somewhat misleading name if you are used to the Lua meaning of Load, but this function calls
-    //luaL_loadfile and then lua_pcall, reporting the errors (if any)
+    /** This function calls luaL_loadfile and then lua_pcall, reporting the errors (if any)
+    @param[in] file Fully qualified file name to execute.
+    @remark Somewhat misleading name if you are used to the Lua meaning of "load file". It behaves
+    exactly as luaL_dofile does.            */
     static void LoadFile(const Rocket::Core::String& file);
     static void LoadFile(const Rocket::Core::String& file);
-    //Calls lua_dostring and reports the errors. The first parameter is the string to execute, the
-    //second parameter is the name, which will show up in the console/error log
+    /** Calls lua_dostring and reports the errors.
+    @param[in] code String to execute
+    @param[in] name Name for the code that will show up in the Log  */
     static void DoString(const Rocket::Core::String& code, const Rocket::Core::String& name = "");
     static void DoString(const Rocket::Core::String& code, const Rocket::Core::String& name = "");
-    //Same as DoString, except does NOT call pcall on it. It will leave the compiled (but not executed) string
-    //on top of the stack. It is just like luaL_loadstring, but you get to specify the name
+    /** Same as DoString, except does NOT call pcall on it. It will leave the compiled (but not executed) string
+    on top of the stack. It behaves exactly like luaL_loadstring, but you get to specify the name
+    @param[in] code String to compile
+    @param[in] name Name for the code that will show up in the Log    */
     static void LoadString(const Rocket::Core::String& code, const Rocket::Core::String& name = "");
     static void LoadString(const Rocket::Core::String& code, const Rocket::Core::String& name = "");
 
 
-    //clears all of the items on the stack, and pushes the function from funRef on top of the stack. Only use
-    //this if you used lua_ref instead of luaL_ref
+    /** Clears all of the items on the stack, and pushes the function from funRef on top of the stack. Only use
+    this if you used lua_ref instead of luaL_ref
+    @param[in] funRef Lua reference that you would recieve from calling lua_ref   */
     static void BeginCall(int funRef);
     static void BeginCall(int funRef);
-    /*  Before you call this, your stack should look like:
-    [0] function to call
-    [1...top] parameters to pass to the function (if any)
-    Or, in words, make sure to push the function on the stack before the parameters. After this function, the params and function will
-    be popped off, and 'res' number of items will be pushed.
-    */
+    /** Uses lua_pcall on a function, which executes the function with params number of parameters and pushes
+    res number of return values on to the stack.
+    @pre Before you call this, your stack should look like:
+    [1] function to call; 
+    [2...top] parameters to pass to the function (if any).
+    Or, in words, make sure to push the function on the stack before the parameters.
+    @post After this function, the params and function will be popped off, and 'res' 
+    number of items will be pushed.     */
     static bool ExecuteCall(int params = 0, int res = 0);
     static bool ExecuteCall(int params = 0, int res = 0);
-    //removes 'res' number of items from the stack
+    /** removes 'res' number of items from the stack
+    @param[in] res Number of results to remove from the stack.   */
     static void EndCall(int res = 0);
     static void EndCall(int res = 0);
 
 
-    //This lacks a SetLuaState for a reason. If you have to use your own Lua binding, then use this lua_State; it will
-    //already have all of the libraries loaded, and all of the types defined
+    /** This will populate the global Lua table with all of the Lua core types by calling LuaType<T>::Register
+    @param[in] L The lua_State to use to register the types
+    @remark This is called automatically inside of Interpreter::Startup(), so you do not have to 
+    call this function upon initialization of the Interpreter. If you are using RocketControlsLua, then you
+    \em will need to call Rocket::Controls::Lua::RegisterTypes(lua_State*)     */
+    static void RegisterCoreTypes(lua_State* L);
+
+    /** 
+    @return The lua_State that the Interpreter created in Interpreter::Startup()
+    @remark This class lacks a SetLuaState for a reason. If you have to use a seperate Lua binding and want to keep the types
+    from libRocket, then use this lua_State; it will already have all of the libraries loaded, and all of the types defined.
+    Alternatively, you can call RegisterCoreTypes(lua_State*) with your own Lua state if you need them defined in it. */
     static lua_State* GetLuaState();
     static lua_State* GetLuaState();
 
 
-    //Creates the plugin
+    /** Creates the plugin. 
+    @remark Call this function only once. Only call it more than once if you call Interpreter::Shutdown() and need to have this
+    exist again. Internally, it calls Interpreter::Startup() and registers the "body" tag to generate a LuaDocument
+    rather than a Rocket::Core::ElementDocument    */
     static void Initialise();
     static void Initialise();
-    //removes the plugin
+    /** Stops the plugin by calling lua_close        */
 	static void Shutdown();
 	static void Shutdown();
     
     
-    //From Plugin
+    /** @sa Rocket::Core::Plugin::GetEventClasses */
     virtual int GetEventClasses();
     virtual int GetEventClasses();
+    /** @sa Rocket::Core::Plugin::OnInitialise */
     virtual void OnInitialise();
     virtual void OnInitialise();
+    /** Currently does nothing. You must call Interpreter::Shutdown yourself at the appropriate time.
+    @sa Rocket::Core::Plugin::OnShutdown    */
     virtual void OnShutdown();
     virtual void OnShutdown();
 private:
 private:
-    //This will populate the global Lua table with all of the Lua types and some global functions
-    static inline void RegisterEverything(lua_State* L);
-    void Startup(); //loads default libs
+    /** Creates a lua_State for @var _L and calls luaL_openlibs, then calls Interpreter::RegisterCoreTypes(lua_State*)
+    @remark called by Interpreter::Initialise()    */
+    void Startup();
 
 
+    /** Lua state that Interpreter::Initialise() creates.    */
     static lua_State* _L;
     static lua_State* _L;
 };
 };
 }
 }

+ 54 - 51
Include/Rocket/Core/Lua/LuaType.h

@@ -28,10 +28,6 @@
 #ifndef ROCKETCORELUALUATYPE_H
 #ifndef ROCKETCORELUALUATYPE_H
 #define ROCKETCORELUALUATYPE_H
 #define ROCKETCORELUALUATYPE_H
 
 
-
-/*
-    This is mostly the definition of the Lua userdata that we give to the user
-*/
 #include <Rocket/Core/Lua/Header.h>
 #include <Rocket/Core/Lua/Header.h>
 #include <Rocket/Core/Lua/lua.hpp>
 #include <Rocket/Core/Lua/lua.hpp>
 
 
@@ -56,15 +52,11 @@
 #define CHECK_BOOL(L,narg) (lua_toboolean((L),(narg)) > 0 ? true : false )
 #define CHECK_BOOL(L,narg) (lua_toboolean((L),(narg)) > 0 ? true : false )
 #define LUACHECKOBJ(obj) if((obj) == NULL) { lua_pushnil(L); return 1; }
 #define LUACHECKOBJ(obj) if((obj) == NULL) { lua_pushnil(L); return 1; }
 
 
-//put this in the type.cpp file
-    /*
-#define LUATYPEDEFINE(type) \
-    template<> inline const char* GetTClassName<type>() { return #type; } \
-    template<> inline RegType<type>* GetMethodTable<type>() { return type##Methods; } \
-    template<> inline luaL_reg* GetAttrTable<type>() { return type##Getters; } \
-    template<> inline luaL_reg* SetAttrTable<type>() { return type##Setters; } \
-*/
- //put this in the type.cpp file
+ /** Used to remove repetitive typing at the cost of flexibility. When you use this, you @em must have 
+ functions with the same name as defined in the macro. For example, if you used @c Element as type, you would
+ have to have functions named @c ElementMethods, @c ElementGetters, @c ElementSetters that return the appropriate
+ types.
+ @param is_reference_counted true if the type inherits from Rocket::Core::ReferenceCountable, false otherwise*/
 #define LUATYPEDEFINE(type,is_ref_counted) \
 #define LUATYPEDEFINE(type,is_ref_counted) \
     template<> const char* Rocket::Core::Lua::GetTClassName<type>() { return #type; } \
     template<> const char* Rocket::Core::Lua::GetTClassName<type>() { return #type; } \
     template<> Rocket::Core::Lua::RegType<type>* Rocket::Core::Lua::GetMethodTable<type>() { return type##Methods; } \
     template<> Rocket::Core::Lua::RegType<type>* Rocket::Core::Lua::GetMethodTable<type>() { return type##Methods; } \
@@ -72,15 +64,10 @@
     template<> luaL_reg* Rocket::Core::Lua::SetAttrTable<type>() { return type##Setters; } \
     template<> luaL_reg* Rocket::Core::Lua::SetAttrTable<type>() { return type##Setters; } \
     template<> bool Rocket::Core::Lua::IsReferenceCounted<type>() { return (is_ref_counted); } \
     template<> bool Rocket::Core::Lua::IsReferenceCounted<type>() { return (is_ref_counted); } \
 
 
-//put this in the type.h file. Not used at the moment
-    /*
-#define LUATYPEDECLARE(type) \
-    template<> const char* GetTClassName<type>(); \
-    template<> RegType<type>* GetMethodTable<type>(); \
-    template<> luaL_reg* GetAttrTable<type>(); \
-    template<> luaL_reg* SetAttrTable<type>(); \
-*/
-//put this in the type.h file
+/** Used to remove repetitive typing at the cost of flexibility. It creates function prototypes for
+getting the name of the type, method tables, and if it is reference counted.
+When you use this, you either must also use
+the LUATYPEDEFINE macro, or make sure that the function signatures are @em exact.*/
 #define LUATYPEDECLARE(type) \
 #define LUATYPEDECLARE(type) \
     template<> ROCKETLUA_API const char* Rocket::Core::Lua::GetTClassName<type>(); \
     template<> ROCKETLUA_API const char* Rocket::Core::Lua::GetTClassName<type>(); \
     template<> ROCKETLUA_API Rocket::Core::Lua::RegType<type>* Rocket::Core::Lua::GetMethodTable<type>(); \
     template<> ROCKETLUA_API Rocket::Core::Lua::RegType<type>* Rocket::Core::Lua::GetMethodTable<type>(); \
@@ -99,61 +86,77 @@ struct ROCKETLUA_API RegType
     int (*ftnptr)(lua_State*,T*);
     int (*ftnptr)(lua_State*,T*);
 };
 };
 
 
-//this is for all of the methods available from Lua that call to the C functions
+/** For all of the methods available from Lua that call to the C functions. */
 template<typename T> ROCKETLUA_API RegType<T>* GetMethodTable();
 template<typename T> ROCKETLUA_API RegType<T>* GetMethodTable();
-//this is for all of the function that 'get' an attribute/property
+/** For all of the function that 'get' an attribute/property */
 template<typename T> ROCKETLUA_API luaL_reg* GetAttrTable();
 template<typename T> ROCKETLUA_API luaL_reg* GetAttrTable();
-//this is for all of the functions that 'set' an attribute/property
+/** For all of the functions that 'set' an attribute/property  */
 template<typename T> ROCKETLUA_API luaL_reg* SetAttrTable();
 template<typename T> ROCKETLUA_API luaL_reg* SetAttrTable();
-//String representation of the class
+/** String representation of the class */
 template<typename T> ROCKETLUA_API const char* GetTClassName();
 template<typename T> ROCKETLUA_API const char* GetTClassName();
-//bool for if it is reference counted
+/** bool for if it is reference counted */
 template<typename T> ROCKETLUA_API bool IsReferenceCounted();
 template<typename T> ROCKETLUA_API bool IsReferenceCounted();
-//gets called from the LuaType<T>::Register function, right before _regfunctions.
-//If you want to inherit from another class, in the function you would want
-//to call _regfunctions<superclass>, where method is metatable_index - 1. Anything
-//that has the same name in the subclass will be overwrite whatever had the 
-//same name in the superclass.
+/** gets called from the LuaType<T>::Register function, right before @c _regfunctions.
+If you want to inherit from another class, in the function you would want
+to call @c _regfunctions<superclass>, where method is metatable_index - 1. Anything
+that has the same name in the subclass will be overwrite whatever had the 
+same name in the superclass.    */
 template<typename T> ROCKETLUA_API void ExtraInit(lua_State* L, int metatable_index);
 template<typename T> ROCKETLUA_API void ExtraInit(lua_State* L, int metatable_index);
-//template<typename T> void ExtraInit(lua_State* L, int metatable_index) { return; }
 
 
+/**
+    This is mostly the definition of the Lua userdata that C++ gives to the user, plus
+    some helper functions.
+
+    @author Nathan Starkey
+*/
 template<typename T>
 template<typename T>
 class ROCKETLUA_API LuaType
 class ROCKETLUA_API LuaType
 {
 {
 public:
 public:
     typedef int (*ftnptr)(lua_State* L, T* ptr);
     typedef int (*ftnptr)(lua_State* L, T* ptr);
+    /** replacement for luaL_reg that uses a different function pointer signature, but similar syntax */
     typedef struct { const char* name; ftnptr func; } RegType;
     typedef struct { const char* name; ftnptr func; } RegType;
 
 
+    /** Registers the type T as a type in the Lua global namespace by creating a
+     metatable with the same name as the class, setting the metatmethods, and adding the 
+     functions from _regfunctions */
     static inline void Register(lua_State *L);
     static inline void Register(lua_State *L);
+    /** Pushes on to the Lua stack a userdata representing a pointer of T
+    @param obj[in] The object to push to the stack
+    @param gc[in] If the obj should be deleted or decrease reference count upon the garbage collection
+    metamethod being called from the object in Lua
+    @return Position on the stack where the userdata resides   */
     static inline int push(lua_State *L, T* obj, bool gc=false);
     static inline int push(lua_State *L, T* obj, bool gc=false);
+    /** Statically casts the item at the position on the Lua stack
+    @param narg[in] Position of the item to cast on the Lua stack
+    @return A pointer to an object of type T or @c NULL   */
     static inline T* check(lua_State* L, int narg);
     static inline T* check(lua_State* L, int narg);
 
 
-    //for calling a C closure with upvalues
+    /** For calling a C closure with upvalues. Used by the functions defined by RegType
+    @return The value that RegType.func returns   */
     static inline int thunk(lua_State* L);
     static inline int thunk(lua_State* L);
-    //pointer to string
+    /** String representation of the pointer. Called by the __tostring metamethod  */
     static inline void tostring(char* buff, void* obj);
     static inline void tostring(char* buff, void* obj);
     //these are metamethods
     //these are metamethods
-    //.__gc
+    /** The __gc metamethod. If the object was pushed by push(lua_State*,T*,bool) with the third
+    argument as true, it will either decrease the reference count or call delete depending on if
+    the type is reference counted. If the third argument to push was false, then this does nothing.
+    @return 0, since it pushes nothing on to the stack*/
     static inline int gc_T(lua_State* L);
     static inline int gc_T(lua_State* L);
-    //.__tostring
+    /** The __tostring metamethod.
+    @return 1, because it pushes a string representation of the userdata on to the stack  */
     static inline int tostring_T(lua_State* L);
     static inline int tostring_T(lua_State* L);
-    //.__index
+    /** The __index metamethod. Called whenever the user attempts to access a variable that is
+    not in the immediate table. This handles the method calls and calls tofunctions in __getters    */
     static inline int index(lua_State* L);
     static inline int index(lua_State* L);
-    //.__newindex
+    /** The __newindex metamethod. Called when the user attempts to set a variable that is not
+    int the immediate table. This handles the calls to functions in __setters  */
     static inline int newindex(lua_State* L);
     static inline int newindex(lua_State* L);
 	
 	
-    //gets called from the Register function, right before _regfunctions.
-    //If you want to inherit from another class, in the function you would want
-    //to call _regfunctions<superclass>, where method is metatable_index - 1. Anything
-    //that has the same name in the subclass will be overwrite whatever had the 
-    //same name in the superclass.
-    //static inline void extra_init(lua_State* L, int metatable_index);
-    //Registers methods,getters,and setters to the type
+    /** Registers methods,getters,and setters to the type. In Lua, the methods exist in the Type name's 
+    metatable, and the getters exist in __getters and setters in __setters. The reason for __getters and __setters
+    is to have the objects use a 'dot' syntax for properties and a 'colon' syntax for methods.*/
     static inline void _regfunctions(lua_State* L, int meta, int method);
     static inline void _regfunctions(lua_State* L, int meta, int method);
-    //Says if it is a reference counted type. If so, then on push and __gc, do reference counting things
-    //rather than regular new/delete. Note that it is still up to the user to pass "true" to the push function's
-    //third parameter to be able to decrease the reference when Lua garbage collects an object
-    //static inline bool is_reference_counted();
 private:
 private:
     LuaType(); //hide constructor
     LuaType(); //hide constructor
 
 
@@ -164,5 +167,5 @@ private:
 }
 }
 }
 }
 
 
-#include "LuaType.inl" //this feels so dirty, but it is the only way I got it to compile in release
+#include "LuaType.inl" 
 #endif
 #endif

+ 35 - 5
Include/Rocket/Core/Lua/Utilities.h

@@ -39,15 +39,45 @@ namespace Rocket {
 namespace Core {
 namespace Core {
 namespace Lua {
 namespace Lua {
 
 
-//casts the variant to its specific type before pushing it to the stack
+/** casts the variant to its specific type before pushing it to the stack 
+@relates Rocket::Core::Lua::LuaType */
 void ROCKETLUA_API PushVariant(lua_State* L, Variant* var);
 void ROCKETLUA_API PushVariant(lua_State* L, Variant* var);
 
 
-//If there are errors on the top of the stack, this will print those out to the log.
-//L is a Lua state, and if not passed in, will use the Interpreter's state
-//place is a string that will be printed to the log right before the error message seperated by a space. Set
-//this when you would get no information about where the error happens.
+/** If there are errors on the top of the stack, this will print those out to the log.
+@param L A Lua state, and if not passed in, will use the Interpreter's state
+@param place A string that will be printed to the log right before the error message, seperated by a space. Set
+this when you would get no information about where the error happens.
+@relates Rocket::Core::Lua::Interpreter   */
 void ROCKETLUA_API Report(lua_State* L = NULL, const Rocket::Core::String& place = "");
 void ROCKETLUA_API Report(lua_State* L = NULL, const Rocket::Core::String& place = "");
+
+//Helper function, so that the types don't have to define individual functions themselves
+// to fill the Elements.As table
+template<typename ToType>
+int CastFromElementTo(lua_State* L)
+{
+    Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
+    LuaType<ToType>::push(L,(ToType*)ele,false);
+    return 1;
+}
+
+//Adds to the Element.As table the name of the type, and the function to use to cast
+template<typename T>
+void AddTypeToElementAsTable(lua_State* L)
+{
+    int top = lua_gettop(L);
+    lua_getglobal(L,"Element");
+    lua_getfield(L,-1,"As");
+    if(!lua_isnoneornil(L,-1))
+    {
+        lua_pushcfunction(L,CastFromElementTo<T>);
+        lua_setfield(L,-2,GetTClassName<T>());
+    }
+    lua_settop(L,top); //pop "As" and "Element"
 }
 }
 }
 }
 }
 }
+}
+
+
 #endif
 #endif

+ 10 - 2
Source/Controls/Lua/Controls.cpp

@@ -29,6 +29,8 @@
 #include <Rocket/Controls/Lua/Controls.h>
 #include <Rocket/Controls/Lua/Controls.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 <Rocket/Core/Lua/Interpreter.h>
+#include <Rocket/Core/Log.h>
 #include "SelectOptionsProxy.h"
 #include "SelectOptionsProxy.h"
 #include "DataFormatter.h"
 #include "DataFormatter.h"
 #include "DataSource.h"
 #include "DataSource.h"
@@ -52,6 +54,12 @@ namespace Lua {
 //when the Interpreter starts.
 //when the Interpreter starts.
 void RegisterTypes(lua_State* L)
 void RegisterTypes(lua_State* L)
 {
 {
+    if(Rocket::Core::Lua::Interpreter::GetLuaState() == NULL)
+    {
+        Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR,
+            "In Rocket::Controls::Lua::RegisterTypes: Tried to register the \'Controls\' types for Lua without first initializing the Interpreter.");
+        return;
+    }
     LuaType<ElementForm>::Register(L);
     LuaType<ElementForm>::Register(L);
     LuaType<ElementFormControl>::Register(L);
     LuaType<ElementFormControl>::Register(L);
         //Inherits from ElementFormControl
         //Inherits from ElementFormControl
@@ -59,13 +67,13 @@ void RegisterTypes(lua_State* L)
             LuaType<ElementFormControlDataSelect>::Register(L);
             LuaType<ElementFormControlDataSelect>::Register(L);
         LuaType<ElementFormControlInput>::Register(L);
         LuaType<ElementFormControlInput>::Register(L);
         LuaType<ElementFormControlTextArea>::Register(L);
         LuaType<ElementFormControlTextArea>::Register(L);
-    //proxy tables
-    LuaType<SelectOptionsProxy>::Register(L);
     LuaType<DataFormatter>::Register(L);
     LuaType<DataFormatter>::Register(L);
     LuaType<DataSource>::Register(L);
     LuaType<DataSource>::Register(L);
     LuaType<ElementDataGrid>::Register(L);
     LuaType<ElementDataGrid>::Register(L);
     LuaType<ElementDataGridRow>::Register(L);
     LuaType<ElementDataGridRow>::Register(L);
     LuaType<ElementTabSet>::Register(L);
     LuaType<ElementTabSet>::Register(L);
+    //proxy tables
+    LuaType<SelectOptionsProxy>::Register(L);
 }
 }
 
 
 }
 }

+ 2 - 3
Source/Controls/Lua/ElementDataGrid.cpp

@@ -29,14 +29,13 @@
 #include "ElementDataGrid.h"
 #include "ElementDataGrid.h"
 #include <Rocket/Core/Element.h>
 #include <Rocket/Core/Element.h>
 #include <Rocket/Controls/ElementDataGridRow.h>
 #include <Rocket/Controls/ElementDataGridRow.h>
-//#include "Lua/Element.h"
-#include "As.h"
+#include <Rocket/Core/Lua/Utilities.h>
 
 
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementDataGrid>(lua_State* L, int metatable_index)
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementDataGrid>(lua_State* L, int metatable_index)
 {
 {
     Rocket::Core::Lua::ExtraInit<Rocket::Core::Element>(L,metatable_index);
     Rocket::Core::Lua::ExtraInit<Rocket::Core::Element>(L,metatable_index);
     LuaType<Rocket::Core::Element>::_regfunctions(L,metatable_index,metatable_index-1);
     LuaType<Rocket::Core::Element>::_regfunctions(L,metatable_index,metatable_index-1);
-    Rocket::Controls::Lua::AddCastFunctionToElementAsTable<Rocket::Controls::ElementDataGrid>(L);
+    Rocket::Core::Lua::AddTypeToElementAsTable<Rocket::Controls::ElementDataGrid>(L);
 }
 }
 namespace Rocket {
 namespace Rocket {
 namespace Controls {
 namespace Controls {

+ 2 - 2
Source/Controls/Lua/ElementDataGridRow.cpp

@@ -28,13 +28,13 @@
 #include "precompiled.h"
 #include "precompiled.h"
 #include "ElementDataGridRow.h"
 #include "ElementDataGridRow.h"
 #include <Rocket/Controls/ElementDataGrid.h>
 #include <Rocket/Controls/ElementDataGrid.h>
-#include "As.h"
+#include <Rocket/Core/Lua/Utilities.h>
 
 
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementDataGridRow>(lua_State* L, int metatable_index)
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementDataGridRow>(lua_State* L, int metatable_index)
 {
 {
     Rocket::Core::Lua::ExtraInit<Rocket::Core::Element>(L,metatable_index);
     Rocket::Core::Lua::ExtraInit<Rocket::Core::Element>(L,metatable_index);
     LuaType<Rocket::Core::Element>::_regfunctions(L,metatable_index,metatable_index-1);
     LuaType<Rocket::Core::Element>::_regfunctions(L,metatable_index,metatable_index-1);
-    Rocket::Controls::Lua::AddCastFunctionToElementAsTable<Rocket::Controls::ElementDataGridRow>(L);
+    Rocket::Core::Lua::AddTypeToElementAsTable<Rocket::Controls::ElementDataGridRow>(L);
 }
 }
 
 
 namespace Rocket {
 namespace Rocket {

+ 2 - 2
Source/Controls/Lua/ElementForm.cpp

@@ -29,7 +29,7 @@
 #include "ElementForm.h"
 #include "ElementForm.h"
 #include <Rocket/Core/Element.h>
 #include <Rocket/Core/Element.h>
 #include <Rocket/Controls/ElementForm.h>
 #include <Rocket/Controls/ElementForm.h>
-#include "As.h"
+#include <Rocket/Core/Lua/Utilities.h>
 
 
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementForm>(lua_State* L, int metatable_index)
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementForm>(lua_State* L, int metatable_index)
 {
 {
@@ -37,7 +37,7 @@ template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementForm>(lua_
     Rocket::Core::Lua::ExtraInit<Rocket::Core::Element>(L,metatable_index);
     Rocket::Core::Lua::ExtraInit<Rocket::Core::Element>(L,metatable_index);
     LuaType<Rocket::Core::Element>::_regfunctions(L,metatable_index,metatable_index-1);
     LuaType<Rocket::Core::Element>::_regfunctions(L,metatable_index,metatable_index-1);
 
 
-    Rocket::Controls::Lua::AddCastFunctionToElementAsTable<Rocket::Controls::ElementForm>(L);
+    Rocket::Core::Lua::AddTypeToElementAsTable<Rocket::Controls::ElementForm>(L);
 }
 }
 
 
 namespace Rocket {
 namespace Rocket {

+ 2 - 2
Source/Controls/Lua/ElementFormControl.cpp

@@ -30,13 +30,13 @@
 #include <Rocket/Controls/ElementFormControl.h>
 #include <Rocket/Controls/ElementFormControl.h>
 #include <Rocket/Core/Element.h>
 #include <Rocket/Core/Element.h>
 #include "Lua/Element.h"
 #include "Lua/Element.h"
-#include "As.h"
+#include <Rocket/Core/Lua/Utilities.h>
 
 
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControl>(lua_State* L, int metatable_index)
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControl>(lua_State* L, int metatable_index)
 {
 {
     Rocket::Core::Lua::ExtraInit<Rocket::Core::Element>(L,metatable_index);
     Rocket::Core::Lua::ExtraInit<Rocket::Core::Element>(L,metatable_index);
     LuaType<Rocket::Core::Element>::_regfunctions(L,metatable_index,metatable_index-1);
     LuaType<Rocket::Core::Element>::_regfunctions(L,metatable_index,metatable_index-1);
-    Rocket::Controls::Lua::AddCastFunctionToElementAsTable<Rocket::Controls::ElementFormControl>(L);
+    Rocket::Core::Lua::AddTypeToElementAsTable<Rocket::Controls::ElementFormControl>(L);
 }
 }
 
 
 namespace Rocket {
 namespace Rocket {

+ 2 - 2
Source/Controls/Lua/ElementFormControlDataSelect.cpp

@@ -29,7 +29,7 @@
 #include "ElementFormControlDataSelect.h"
 #include "ElementFormControlDataSelect.h"
 #include <Rocket/Controls/ElementFormControlSelect.h>
 #include <Rocket/Controls/ElementFormControlSelect.h>
 #include "ElementFormControlSelect.h"
 #include "ElementFormControlSelect.h"
-#include "As.h"
+#include <Rocket/Core/Lua/Utilities.h>
 
 
 //inherits from ElementFormControl which inherits from Element
 //inherits from ElementFormControl which inherits from Element
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControlDataSelect>(lua_State* L, int metatable_index)
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControlDataSelect>(lua_State* L, int metatable_index)
@@ -38,7 +38,7 @@ template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormContro
     Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControlSelect>(L,metatable_index);
     Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControlSelect>(L,metatable_index);
     //then inherit from ElementFromControlSelect
     //then inherit from ElementFromControlSelect
     LuaType<Rocket::Controls::ElementFormControlSelect>::_regfunctions(L,metatable_index,metatable_index-1);
     LuaType<Rocket::Controls::ElementFormControlSelect>::_regfunctions(L,metatable_index,metatable_index-1);
-    Rocket::Controls::Lua::AddCastFunctionToElementAsTable<Rocket::Controls::ElementFormControlDataSelect>(L);
+    Rocket::Core::Lua::AddTypeToElementAsTable<Rocket::Controls::ElementFormControlDataSelect>(L);
 }
 }
 
 
 namespace Rocket {
 namespace Rocket {

+ 2 - 2
Source/Controls/Lua/ElementFormControlInput.cpp

@@ -29,13 +29,13 @@
 #include "ElementFormControlInput.h"
 #include "ElementFormControlInput.h"
 #include <Rocket/Controls/ElementFormControl.h>
 #include <Rocket/Controls/ElementFormControl.h>
 #include "ElementFormControl.h"
 #include "ElementFormControl.h"
-#include "As.h"
+#include <Rocket/Core/Lua/Utilities.h>
 
 
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControlInput>(lua_State* L, int metatable_index)
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControlInput>(lua_State* L, int metatable_index)
 {
 {
     Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControl>(L,metatable_index);
     Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControl>(L,metatable_index);
     LuaType<Rocket::Controls::ElementFormControl>::_regfunctions(L,metatable_index,metatable_index-1);
     LuaType<Rocket::Controls::ElementFormControl>::_regfunctions(L,metatable_index,metatable_index-1);
-    Rocket::Controls::Lua::AddCastFunctionToElementAsTable<Rocket::Controls::ElementFormControlInput>(L);
+    Rocket::Core::Lua::AddTypeToElementAsTable<Rocket::Controls::ElementFormControlInput>(L);
 }
 }
 namespace Rocket {
 namespace Rocket {
 namespace Controls {
 namespace Controls {

+ 2 - 2
Source/Controls/Lua/ElementFormControlSelect.cpp

@@ -32,7 +32,7 @@
 #include <Rocket/Controls/ElementFormControl.h>
 #include <Rocket/Controls/ElementFormControl.h>
 #include <Rocket/Core/Element.h>
 #include <Rocket/Core/Element.h>
 #include "ElementFormControl.h"
 #include "ElementFormControl.h"
-#include "As.h"
+#include <Rocket/Core/Lua/Utilities.h>
 
 
 
 
 //inherits from ElementFormControl which inherits from Element
 //inherits from ElementFormControl which inherits from Element
@@ -42,7 +42,7 @@ template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormContro
     Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControl>(L,metatable_index);
     Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControl>(L,metatable_index);
     //then inherit from elementformcontrol
     //then inherit from elementformcontrol
     LuaType<Rocket::Controls::ElementFormControl>::_regfunctions(L,metatable_index,metatable_index-1);
     LuaType<Rocket::Controls::ElementFormControl>::_regfunctions(L,metatable_index,metatable_index-1);
-    Rocket::Controls::Lua::AddCastFunctionToElementAsTable<Rocket::Controls::ElementFormControlSelect>(L);
+    Rocket::Core::Lua::AddTypeToElementAsTable<Rocket::Controls::ElementFormControlSelect>(L);
 }
 }
 
 
 namespace Rocket {
 namespace Rocket {

+ 2 - 2
Source/Controls/Lua/ElementFormControlTextArea.cpp

@@ -29,13 +29,13 @@
 #include "ElementFormControlTextArea.h"
 #include "ElementFormControlTextArea.h"
 #include <Rocket/Controls/ElementFormControl.h>
 #include <Rocket/Controls/ElementFormControl.h>
 #include "ElementFormControl.h"
 #include "ElementFormControl.h"
-#include "As.h"
+#include <Rocket/Core/Lua/Utilities.h>
 
 
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControlTextArea>(lua_State* L, int metatable_index)
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControlTextArea>(lua_State* L, int metatable_index)
 {
 {
     Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControl>(L,metatable_index);
     Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementFormControl>(L,metatable_index);
     LuaType<Rocket::Controls::ElementFormControl>::_regfunctions(L,metatable_index,metatable_index-1);
     LuaType<Rocket::Controls::ElementFormControl>::_regfunctions(L,metatable_index,metatable_index-1);
-    Rocket::Controls::Lua::AddCastFunctionToElementAsTable<Rocket::Controls::ElementFormControlTextArea>(L);
+    Rocket::Core::Lua::AddTypeToElementAsTable<Rocket::Controls::ElementFormControlTextArea>(L);
 }
 }
 
 
 namespace Rocket {
 namespace Rocket {

+ 2 - 2
Source/Controls/Lua/ElementTabSet.cpp

@@ -28,14 +28,14 @@
 #include "precompiled.h"
 #include "precompiled.h"
 #include "ElementTabSet.h"
 #include "ElementTabSet.h"
 #include <Rocket/Core/Element.h>
 #include <Rocket/Core/Element.h>
-#include "As.h"
+#include <Rocket/Core/Lua/Utilities.h>
 
 
 //this will be used to "inherit" from Element
 //this will be used to "inherit" from Element
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementTabSet>(lua_State* L, int metatable_index)
 template<> void Rocket::Core::Lua::ExtraInit<Rocket::Controls::ElementTabSet>(lua_State* L, int metatable_index)
 {
 {
     Rocket::Core::Lua::ExtraInit<Rocket::Core::Element>(L,metatable_index);
     Rocket::Core::Lua::ExtraInit<Rocket::Core::Element>(L,metatable_index);
     LuaType<Rocket::Core::Element>::_regfunctions(L,metatable_index,metatable_index-1);
     LuaType<Rocket::Core::Element>::_regfunctions(L,metatable_index,metatable_index-1);
-    Rocket::Controls::Lua::AddCastFunctionToElementAsTable<Rocket::Controls::ElementTabSet>(L);
+    Rocket::Core::Lua::AddTypeToElementAsTable<Rocket::Controls::ElementTabSet>(L);
 }
 }
 
 
 namespace Rocket {
 namespace Rocket {

+ 5 - 53
Source/Core/Lua/Element.cpp

@@ -30,6 +30,7 @@
 #include <ElementStyle.h>
 #include <ElementStyle.h>
 #include "LuaEventListener.h"
 #include "LuaEventListener.h"
 #include "ElementAttributesProxy.h"
 #include "ElementAttributesProxy.h"
+#include "ElementChildNodesProxy.h"
 #include <Rocket/Core/Lua/Utilities.h>
 #include <Rocket/Core/Lua/Utilities.h>
 
 
 
 
@@ -69,7 +70,7 @@ int ElementAddEventListener(lua_State* L, Element* obj)
     int top = lua_gettop(L);
     int top = lua_gettop(L);
     bool capture = false;
     bool capture = false;
     //default false if they didn't pass it in
     //default false if they didn't pass it in
-    if (top > 3)
+    if (top > 2)
 		capture = CHECK_BOOL(L,3);
 		capture = CHECK_BOOL(L,3);
 
 
     const char* event = luaL_checkstring(L,1);
     const char* event = luaL_checkstring(L,1);
@@ -259,42 +260,6 @@ int ElementSetClass(lua_State* L, Element* obj)
     return 0;
     return 0;
 }
 }
 
 
-int ElementAsType(lua_State* L, Element* obj)
-{
-    /*
-    Elementetype type = Elementetype(luaL_checkint(L,1));
-    switch(type)
-    {
-    case TDATAGRID:
-        LuaType<Rocket::Controls::ElementDataGrid>::push(L,(Rocket::Controls::ElementDataGrid*)obj,false);
-        break;
-    case TDATASELECT:
-        LuaType<Rocket::Controls::ElementFormControlDataSelect>::push(L,(Rocket::Controls::ElementFormControlDataSelect*)obj,false);
-        break;
-    case TFORM:
-        LuaType<Rocket::Controls::ElementForm>::push(L,(Rocket::Controls::ElementForm*)obj,false);
-        break;
-    case TINPUT:
-        LuaType<Rocket::Controls::ElementFormControlInput>::push(L,(Rocket::Controls::ElementFormControlInput*)obj,false);
-        break;
-    case TSELECT:
-        LuaType<Rocket::Controls::ElementFormControlSelect>::push(L,(Rocket::Controls::ElementFormControlSelect*)obj,false);
-        break;
-    case TTABSET:
-        LuaType<Rocket::Controls::ElementTabSet>::push(L,(Rocket::Controls::ElementTabSet*)obj,false);
-        break;
-    case TTEXTAREA:
-        LuaType<Rocket::Controls::ElementFormControlTextArea>::push(L,(Rocket::Controls::ElementFormControlTextArea*)obj,false);
-    default:
-        LuaType<Element>::push(L,obj,false);
-        break;
-    }
-    return 1;
-    */
-    return 0;
-}
-
-
 //getters
 //getters
 int ElementGetAttrattributes(lua_State* L)
 int ElementGetAttrattributes(lua_State* L)
 {
 {
@@ -310,21 +275,9 @@ int ElementGetAttrchild_nodes(lua_State* L)
 {
 {
     Element* ele = LuaType<Element>::check(L,1);
     Element* ele = LuaType<Element>::check(L,1);
     LUACHECKOBJ(ele);
     LUACHECKOBJ(ele);
-    if(!ele->HasChildNodes())
-        lua_pushnil(L);
-    else
-    {
-        lua_newtable(L);
-        int index = 0;
-        int num_of_children = ele->GetNumChildren();
-        while(index < num_of_children)
-        {
-            lua_pushinteger(L,index);
-            LuaType<Element>::push(L,ele->GetChild(index),false);
-            lua_settable(L,-3);
-            ++index;
-        }
-    }
+    ElementChildNodesProxy* ecnp = new ElementChildNodesProxy();
+    ecnp->owner = ele;
+    LuaType<ElementChildNodesProxy>::push(L,ecnp,true);
     return 1;
     return 1;
 }
 }
 
 
@@ -601,7 +554,6 @@ RegType<Element> ElementMethods[] =
     LUAMETHOD(Element,ScrollIntoView)
     LUAMETHOD(Element,ScrollIntoView)
     LUAMETHOD(Element,SetAttribute)
     LUAMETHOD(Element,SetAttribute)
     LUAMETHOD(Element,SetClass)
     LUAMETHOD(Element,SetClass)
-    LUAMETHOD(Element,AsType)
     { NULL, NULL },
     { NULL, NULL },
 };
 };
 
 

+ 0 - 1
Source/Core/Lua/Element.h

@@ -190,7 +190,6 @@ luaL_reg ElementGetters[];
 luaL_reg ElementSetters[];
 luaL_reg ElementSetters[];
 
 
 LUATYPEDECLARE(Element)
 LUATYPEDECLARE(Element)
-
 }
 }
 }
 }
 }
 }

+ 98 - 0
Source/Core/Lua/ElementChildNodesProxy.cpp

@@ -0,0 +1,98 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "ElementChildNodesProxy.h"
+#include "Element.h"
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+template<> void ExtraInit<ElementChildNodesProxy>(lua_State* L, int metatable_index)
+{
+    lua_pushcfunction(L,ElementChildNodesProxy__index);
+    lua_setfield(L,metatable_index,"__index");
+}
+
+int ElementChildNodesProxy__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*/
+    int keytype = lua_type(L,2);
+    if(keytype == LUA_TNUMBER) //only valid key types
+    {
+        ElementChildNodesProxy* obj = LuaType<ElementChildNodesProxy>::check(L,1);
+        LUACHECKOBJ(obj);
+        int key = luaL_checkint(L,2);
+        Element* child = obj->owner->GetChild(key);
+        LuaType<Element>::push(L,child,false);
+        return 1;
+    }
+    else
+        return LuaType<ElementChildNodesProxy>::index(L);
+}
+
+//method
+int ElementChildNodesProxyGetTable(lua_State* L, ElementChildNodesProxy* obj)
+{
+    Element* ele = obj->owner;
+    if(!ele->HasChildNodes())
+        lua_pushnil(L);
+    else
+    {
+        lua_newtable(L);
+        int index = 0;
+        int num_of_children = ele->GetNumChildren();
+        while(index < num_of_children)
+        {
+            lua_pushinteger(L,index);
+            LuaType<Element>::push(L,ele->GetChild(index),false);
+            lua_settable(L,-3);
+            ++index;
+        }
+    }
+    return 1;
+}
+
+RegType<ElementChildNodesProxy> ElementChildNodesProxyMethods[] = 
+{
+    LUAMETHOD(ElementChildNodesProxy,GetTable)
+    { NULL, NULL },
+};
+luaL_reg ElementChildNodesProxyGetters[] = 
+{
+    { NULL, NULL },
+};
+luaL_reg ElementChildNodesProxySetters[] = 
+{
+    { NULL, NULL },
+};
+
+LUATYPEDEFINE(ElementChildNodesProxy,true)
+}
+}
+}

+ 27 - 8
Source/Core/Lua/RocketLua.cpp → Source/Core/Lua/ElementChildNodesProxy.h

@@ -25,20 +25,39 @@
  *
  *
  */
  */
  
  
-#include "precompiled.h"
-#include <Rocket/Core/Lua/Interpreter.h>
 
 
+#ifndef ROCKETCORELUAELEMENTCHILDNODESPROXY_H
+#define ROCKETCORELUAELEMENTCHILDNODESPROXY_H
+
+/*
+    This is the object that gets returned from Element.child_nodes, so that the table is not
+    built every single time the function is called.
+    Read-only
+*/
+
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Element.h>
 
 
 namespace Rocket {
 namespace Rocket {
 namespace Core {
 namespace Core {
 namespace Lua {
 namespace Lua {
+//where owner is the Element that we should look up information from
+struct ElementChildNodesProxy { Element* owner;  };
 
 
-void Initialise()
-{
-    Rocket::Core::RegisterPlugin(new Interpreter());
-    
-}
+template<> void ExtraInit<ElementChildNodesProxy>(lua_State* L, int metatable_index);
+int ElementChildNodesProxy__index(lua_State* L);
 
 
+//method
+int ElementChildNodesProxyGetTable(lua_State* L, ElementChildNodesProxy* obj);
+
+RegType<ElementChildNodesProxy> ElementChildNodesProxyMethods[];
+luaL_reg ElementChildNodesProxyGetters[];
+luaL_reg ElementChildNodesProxySetters[];
+
+LUATYPEDECLARE(ElementChildNodesProxy)
 }
 }
 }
 }
-}
+}
+
+#endif

+ 11 - 0
Source/Core/Lua/ElementText.h

@@ -27,6 +27,17 @@
  
  
 #ifndef ROCKETCORELUAELEMENTTEXT_H
 #ifndef ROCKETCORELUAELEMENTTEXT_H
 #define ROCKETCORELUAELEMENTTEXT_H
 #define ROCKETCORELUAELEMENTTEXT_H
+/*
+    This defines the ElementText type in the Lua global namespace
+    no methods
+
+    getter:
+    string ElementText.text
+
+    setter:
+    ElementText.text = string
+*/
+
 #include <Rocket/Core/Lua/lua.hpp>
 #include <Rocket/Core/Lua/lua.hpp>
 #include <Rocket/Core/Lua/LuaType.h>
 #include <Rocket/Core/Lua/LuaType.h>
 #include <Rocket/Core/ElementText.h>
 #include <Rocket/Core/ElementText.h>

+ 6 - 8
Source/Core/Lua/Interpreter.cpp

@@ -51,6 +51,8 @@
 #include "Context.h"
 #include "Context.h"
 #include "Event.h"
 #include "Event.h"
 #include "ElementInstancer.h"
 #include "ElementInstancer.h"
+#include "ElementChildNodesProxy.h"
+#include "ElementText.h"
 
 
 namespace Rocket {
 namespace Rocket {
 namespace Core {
 namespace Core {
@@ -66,11 +68,11 @@ void Interpreter::Startup()
     _L = luaL_newstate();
     _L = luaL_newstate();
     luaL_openlibs(_L);
     luaL_openlibs(_L);
 
 
-    RegisterEverything(_L);
+    RegisterCoreTypes(_L);
 }
 }
 
 
 
 
-void Interpreter::RegisterEverything(lua_State* L)
+void Interpreter::RegisterCoreTypes(lua_State* L)
 {
 {
     LuaType<Vector2i>::Register(L);
     LuaType<Vector2i>::Register(L);
     LuaType<Vector2f>::Register(L);
     LuaType<Vector2f>::Register(L);
@@ -81,6 +83,7 @@ void Interpreter::RegisterEverything(lua_State* 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);
+        LuaType<ElementText>::Register(L);
     LuaType<Event>::Register(L);
     LuaType<Event>::Register(L);
     LuaType<Context>::Register(L);
     LuaType<Context>::Register(L);
     LuaType<rocket>::Register(L);
     LuaType<rocket>::Register(L);
@@ -89,6 +92,7 @@ void Interpreter::RegisterEverything(lua_State* L)
     LuaType<ContextDocumentsProxy>::Register(L);
     LuaType<ContextDocumentsProxy>::Register(L);
     LuaType<EventParametersProxy>::Register(L);
     LuaType<EventParametersProxy>::Register(L);
     LuaType<ElementAttributesProxy>::Register(L);
     LuaType<ElementAttributesProxy>::Register(L);
+    LuaType<ElementChildNodesProxy>::Register(L);
 }
 }
 
 
 
 
@@ -142,10 +146,6 @@ bool Interpreter::ExecuteCall(int params, int res)
 {
 {
     bool ret = true;
     bool ret = true;
     int top = lua_gettop(_L);
     int top = lua_gettop(_L);
-    //String strtype = lua_typename(_L,top-params);
-    String strtype;
-    for(int i = top; i >= 1; i--)
-        strtype = lua_typename(_L,lua_type(_L,i));
     if(lua_type(_L,top-params) != LUA_TFUNCTION)
     if(lua_type(_L,top-params) != LUA_TFUNCTION)
     {
     {
         ret = false;
         ret = false;
@@ -198,8 +198,6 @@ void Interpreter::OnInitialise()
 
 
 void Interpreter::OnShutdown()
 void Interpreter::OnShutdown()
 {
 {
-	//causing crashes
-    //lua_close(_L);
 }
 }
 
 
 void Interpreter::Initialise()
 void Interpreter::Initialise()

+ 0 - 45
Source/Core/Lua/Register.h

@@ -1,45 +0,0 @@
-/*
- * This source file is part of libRocket, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://www.librocket.com
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- 
-//whenever you want to have a type exposed to lua, you have to have it in here as
-//LuaType<type>::Register(L);
-//It will be #included in the correct place in Interpreter.cpp, as to make this more like a macro file
-
-//THE ORDER DOES MATTER
-//You have to register a base class before any others can inherit from it
-LuaType<Vector2i>::Register(L);
-LuaType<Vector2f>::Register(L);
-LuaType<Colourf>::Register(L);
-LuaType<Colourb>::Register(L);
-LuaType<Log>::Register(L);
-LuaType<Element>::Register(L);
-    //things that inherit from element
-    LuaType<Document>::Register(L);
-    LuaType<ElementStyle>::Register(L);
-LuaType<Event>::Register(L);
-LuaType<Context>::Register(L);
-LuaType<rocket>::Register(L);

+ 0 - 41
Source/Core/Lua/RocketLua.h

@@ -1,41 +0,0 @@
-/*
- * This source file is part of libRocket, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://www.librocket.com
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- 
-#ifndef ROCKETCORELUAROCKETLUA_H
-#define ROCKETCORELUAROCKETLUA_H
-
-#include "Header.h"
-
-namespace Rocket {
-namespace Core {
-namespace Lua {
-
-void ROCKETLUA_API Initialise();
-}
-}
-}
-#endif