Procházet zdrojové kódy

Implemented the RegisterTag function.

To do that, I had to create a LuaElementInstancer, a Lua interface for that type, and a function for Element.new(string tag).

I restored some files that were accidentally deleted.
Nate Starkey před 13 roky
rodič
revize
13dbd75edd

+ 16 - 0
Build/RocketCoreLua.vcproj

@@ -258,6 +258,14 @@
 					RelativePath="..\Source\Core\Lua\ElementAttributesProxy.h"
 					>
 				</File>
+				<File
+					RelativePath="..\Source\Core\Lua\ElementInstancer.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\Source\Core\Lua\ElementInstancer.h"
+					>
+				</File>
 				<File
 					RelativePath="..\Source\Core\Lua\ElementStyle.cpp"
 					>
@@ -274,6 +282,14 @@
 					RelativePath="..\Source\Core\Lua\ElementText.h"
 					>
 				</File>
+				<File
+					RelativePath="..\Source\Core\Lua\LuaElementInstancer.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\Source\Core\Lua\LuaElementInstancer.h"
+					>
+				</File>
 				<Filter
 					Name="Document"
 					>

+ 7 - 0
Build/RocketLua.sln

@@ -14,8 +14,15 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RocketDebugger", "RocketDeb
 	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RocketCoreLua", "RocketCoreLua.vcproj", "{FC02901C-3CE4-4625-856A-F180DC45A855}"
+	ProjectSection(ProjectDependencies) = postProject
+		{1AAC0B29-AEB9-4E3F-8EDF-B46F8949C41B} = {1AAC0B29-AEB9-4E3F-8EDF-B46F8949C41B}
+	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RocketControlsLua", "RocketControlsLua.vcproj", "{45C9CB50-E22C-465E-AB17-CA81D2372DEF}"
+	ProjectSection(ProjectDependencies) = postProject
+		{FC02901C-3CE4-4625-856A-F180DC45A855} = {FC02901C-3CE4-4625-856A-F180DC45A855}
+		{1AAC0B29-AEC9-4E3F-9EDF-B56F8949C41B} = {1AAC0B29-AEC9-4E3F-9EDF-B56F8949C41B}
+	EndProjectSection
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution

+ 28 - 0
Build/Rocket_Prefix.pch

@@ -0,0 +1,28 @@
+/*
+ * 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 <Rocket/Core.h>

+ 1 - 1
Samples/invaders/RocketInvaders.vcproj

@@ -110,7 +110,7 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				AdditionalIncludeDirectories="..\shell\include;..\..\Include"
-				PreprocessorDefinitions="WIN32"
+				PreprocessorDefinitions="WIN32,NDEBUG"
 				RuntimeLibrary="2"
 				WarningLevel="4"
 				DebugInformationFormat="3"

+ 65 - 0
Samples/invaders/RocketInvaders.vcproj.user

@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+	ProjectType="Visual C++"
+	Version="8.00"
+	ShowAllFiles="false"
+	>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			>
+			<DebugSettings
+				Command="$(TargetPath)"
+				WorkingDirectory="..\..\bin"
+				CommandArguments=""
+				Attach="false"
+				DebuggerType="3"
+				Remote="1"
+				RemoteMachine=""
+				RemoteCommand=""
+				HttpUrl=""
+				PDBPath=""
+				SQLDebugging=""
+				Environment=""
+				EnvironmentMerge="true"
+				DebuggerFlavor="0"
+				MPIRunCommand=""
+				MPIRunArguments=""
+				MPIRunWorkingDirectory=""
+				ApplicationCommand=""
+				ApplicationArguments=""
+				ShimCommand=""
+				MPIAcceptMode=""
+				MPIAcceptFilter=""
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			>
+			<DebugSettings
+				Command="$(TargetPath)"
+				WorkingDirectory="..\..\bin"
+				CommandArguments=""
+				Attach="false"
+				DebuggerType="3"
+				Remote="1"
+				RemoteMachine=""
+				RemoteCommand=""
+				HttpUrl=""
+				PDBPath=""
+				SQLDebugging=""
+				Environment=""
+				EnvironmentMerge="true"
+				DebuggerFlavor="0"
+				MPIRunCommand=""
+				MPIRunArguments=""
+				MPIRunWorkingDirectory=""
+				ApplicationCommand=""
+				ApplicationArguments=""
+				ShimCommand=""
+				MPIAcceptMode=""
+				MPIAcceptFilter=""
+			/>
+		</Configuration>
+	</Configurations>
+</VisualStudioUserFile>

+ 7 - 7
Samples/luainvaders/LuaRocketInvaders.sln

@@ -1,27 +1,27 @@
 
 Microsoft Visual Studio Solution File, Format Version 10.00
 # Visual C++ Express 2008
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PyRocketInvaders", "PyRocketInvaders.vcproj", "{D343E357-BF62-424F-B22A-16D7B8A6422B}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Shell", "..\shell\Shell.vcproj", "{AF4FF882-AFD9-457B-979E-A5B482388D46}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LuaRocketInvaders", "LuaRocketInvaders.vcproj", "{D343E357-BF62-424F-B22A-16D7B8A6422B}"
 	ProjectSection(ProjectDependencies) = postProject
 		{AF4FF882-AFD9-457B-979E-A5B482388D46} = {AF4FF882-AFD9-457B-979E-A5B482388D46}
 	EndProjectSection
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Shell", "..\shell\Shell.vcproj", "{AF4FF882-AFD9-457B-979E-A5B482388D46}"
-EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Win32 = Debug|Win32
 		Release|Win32 = Release|Win32
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
-		{D343E357-BF62-424F-B22A-16D7B8A6422B}.Debug|Win32.ActiveCfg = Debug|Win32
-		{D343E357-BF62-424F-B22A-16D7B8A6422B}.Debug|Win32.Build.0 = Debug|Win32
-		{D343E357-BF62-424F-B22A-16D7B8A6422B}.Release|Win32.ActiveCfg = Release|Win32
-		{D343E357-BF62-424F-B22A-16D7B8A6422B}.Release|Win32.Build.0 = Release|Win32
 		{AF4FF882-AFD9-457B-979E-A5B482388D46}.Debug|Win32.ActiveCfg = Debug|Win32
 		{AF4FF882-AFD9-457B-979E-A5B482388D46}.Debug|Win32.Build.0 = Debug|Win32
 		{AF4FF882-AFD9-457B-979E-A5B482388D46}.Release|Win32.ActiveCfg = Release|Win32
 		{AF4FF882-AFD9-457B-979E-A5B482388D46}.Release|Win32.Build.0 = Release|Win32
+		{D343E357-BF62-424F-B22A-16D7B8A6422B}.Debug|Win32.ActiveCfg = Debug|Win32
+		{D343E357-BF62-424F-B22A-16D7B8A6422B}.Debug|Win32.Build.0 = Debug|Win32
+		{D343E357-BF62-424F-B22A-16D7B8A6422B}.Release|Win32.ActiveCfg = Release|Win32
+		{D343E357-BF62-424F-B22A-16D7B8A6422B}.Release|Win32.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 2 - 2
Samples/luainvaders/PyRocketInvaders.vcproj → Samples/luainvaders/LuaRocketInvaders.vcproj

@@ -39,7 +39,7 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="..\shell\include;..\..\include;..\..\..\support\python\include;..\..\..\support\python\pc;..\..\..\support\boost;..\..\Dependencies\lua\src"
+				AdditionalIncludeDirectories="..\shell\include;..\..\include;..\..\Dependencies\lua\src"
 				PreprocessorDefinitions="WIN32"
 				RuntimeLibrary="3"
 				DebugInformationFormat="3"
@@ -108,7 +108,7 @@
 			/>
 			<Tool
 				Name="VCCLCompilerTool"
-				AdditionalIncludeDirectories="..\shell\include;..\..\include;..\..\..\support\python\include;..\..\..\support\python\pc;..\..\..\support\boost;..\..\Dependencies\lua\src"
+				AdditionalIncludeDirectories="..\shell\include;..\..\include;..\..\Dependencies\lua\src"
 				PreprocessorDefinitions="WIN32,NDEBUG"
 				RuntimeLibrary="2"
 				WarningLevel="3"

+ 0 - 0
Samples/luainvaders/PyRocketInvaders.vcproj.user → Samples/luainvaders/LuaRocketInvaders.vcproj.user


+ 11 - 0
Source/Core/Lua/Element.cpp

@@ -49,9 +49,20 @@ template<> void ExtraInit<Element>(lua_State* L, int metatable_index)
         lua_setfield(L,metatable_index-1,"As");
     }
     lua_pop(L,1); //pop the result of lua_getfield
+    lua_pushcfunction(L,Elementnew);
+    lua_setfield(L,metatable_index-1,"new");
     lua_settop(L,top);
 }
 
+int Elementnew(lua_State* L)
+{
+    const char* tag = luaL_checkstring(L,1);
+    Element* ele = new Element(tag);
+    LuaType<Element>::push(L,ele,true);
+    ele->RemoveReference();
+    return 1;
+}
+
 //methods
 int ElementAddEventListener(lua_State* L, Element* obj)
 {

+ 2 - 2
Source/Core/Lua/Element.h

@@ -60,6 +60,7 @@
     noreturn Element:SetAttribute(string name,string value)
     noreturn Element:SetClass(string name, bool activate)
     %type% Element.As.%type%(Element obj) --see footnote 2
+    Element Element.new(string tag) --Do not use unless inside an ElementInstancer function.
 
 
     //getters accessed by the period syntax from an element object
@@ -125,7 +126,7 @@ namespace Core {
 namespace Lua {
 template<> ROCKETLUA_API void ExtraInit<Element>(lua_State* L, int metatable_index);
 
-
+int Elementnew(lua_State* L);
 //methods
 int ElementAddEventListener(lua_State* L, Element* obj);
 int ElementAppendChild(lua_State* L, Element* obj);
@@ -146,7 +147,6 @@ int ElementReplaceChild(lua_State* L, Element* obj);
 int ElementScrollIntoView(lua_State* L, Element* obj);
 int ElementSetAttribute(lua_State* L, Element* obj);
 int ElementSetClass(lua_State* L, Element* obj);
-int ElementAsType(lua_State* L, Element* obj);
 
 //getters
 int ElementGetAttrattributes(lua_State* L);

+ 88 - 0
Source/Core/Lua/ElementInstancer.cpp

@@ -0,0 +1,88 @@
+/*
+ * 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 "ElementInstancer.h"
+
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+template<> void ExtraInit<ElementInstancer>(lua_State* L, int metatable_index)
+{
+    lua_pushcfunction(L,ElementInstancernew);
+    lua_setfield(L,metatable_index-1,"new");
+}
+
+//method
+int ElementInstancernew(lua_State* L)
+{
+    LuaElementInstancer* lei = new LuaElementInstancer(L);
+    LuaType<ElementInstancer>::push(L,lei,true);
+    lei->RemoveReference();
+    return 1;
+}
+
+//setter
+int ElementInstancerSetAttrInstanceElement(lua_State* L)
+{
+    LuaElementInstancer* lei = (LuaElementInstancer*)LuaType<ElementInstancer>::check(L,1);
+    LUACHECKOBJ(lei);
+    
+    if(lua_type(L,2) != LUA_TFUNCTION)
+    {
+        Log::Message(Log::LT_ERROR, "The argument to ElementInstancer.InstanceElement must be a function. You passed in a %s.", luaL_typename(L,2));
+        return 0;
+    }
+    lei->PushFunctionsTable(L); //top of the stack is now ELEMENTINSTANCERFUNCTIONS table
+    lua_pushvalue(L,2); //copy of the function
+    lei->ref_InstanceElement = luaL_ref(L,-2); 
+    lua_pop(L,1); //pop the ELEMENTINSTANCERFUNCTIONS table
+    return 0;
+}
+
+RegType<ElementInstancer> ElementInstancerMethods[] =
+{
+    { NULL, NULL },
+};
+
+luaL_reg ElementInstancerGetters[] =
+{
+    { NULL, NULL },
+};
+
+luaL_reg ElementInstancerSetters[] =
+{
+    LUASETTER(ElementInstancer,InstanceElement)
+    { NULL, NULL },
+};
+
+LUATYPEDEFINE(ElementInstancer,true)
+}
+}
+}

+ 66 - 0
Source/Core/Lua/ElementInstancer.h

@@ -0,0 +1,66 @@
+/*
+ * 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 ROCKETCORELUAELEMENTINSTANCER_H
+#define ROCKETCORELUAELEMENTINSTANCER_H
+
+/*
+    This defines the ElementInstancer type in the Lua global namespace. It is reference counted.
+
+    To use this, you will want to call ElementInstancer.new to get an object, and call rocket.RegisterTag to tell Rocket to use the 
+    instancer for that tag.
+
+    ElementInstancer ElementInstancer.new([function InstanceElement]) --argument is optional, and new is not called from a specific object
+
+    //setter
+    ElementInstancer.InstanceElement = function(string tag) return Element end --gets called when the factory sees the tag being instanced
+*/
+
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
+#include "LuaElementInstancer.h"
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+template<> void ExtraInit<ElementInstancer>(lua_State* L, int metatable_index);
+//method
+int ElementInstancernew(lua_State* L);
+//setter
+int ElementInstancerSetAttrInstanceElement(lua_State* L);
+
+RegType<ElementInstancer> ElementInstancerMethods[];
+luaL_reg ElementInstancerGetters[];
+luaL_reg ElementInstancerSetters[];
+
+LUATYPEDECLARE(ElementInstancer)
+}
+}
+}
+
+
+#endif

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

@@ -50,6 +50,7 @@
 #include "Vector2i.h"
 #include "Context.h"
 #include "Event.h"
+#include "ElementInstancer.h"
 
 namespace Rocket {
 namespace Core {
@@ -83,6 +84,7 @@ void Interpreter::RegisterEverything(lua_State* L)
     LuaType<Event>::Register(L);
     LuaType<Context>::Register(L);
     LuaType<rocket>::Register(L);
+    LuaType<ElementInstancer>::Register(L);
     //Proxy tables
     LuaType<ContextDocumentsProxy>::Register(L);
     LuaType<EventParametersProxy>::Register(L);
@@ -111,7 +113,7 @@ void Interpreter::LoadFile(const String& file)
         else
         {
             msg.Append(" was successful. ").Append(file);
-            Log::Message(Log::LT_INFO, msg.CString());
+            Log::Message(Log::LT_DEBUG, msg.CString());
         }
     }
 }

+ 42 - 0
Source/Core/Lua/LuaElement.h

@@ -0,0 +1,42 @@
+/*
+ * 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 ROCKETCORELUALUAELEMENT_H
+#define ROCKETCORELUALUAELEMENT_H
+
+#include <Rocket/Core/Element.h>
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+class 
+}
+}
+}
+
+#endif

+ 97 - 0
Source/Core/Lua/LuaElementInstancer.cpp

@@ -0,0 +1,97 @@
+/*
+ * 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 "LuaElementInstancer.h"
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/Interpreter.h>
+#include <Rocket/Core/Log.h>
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+//This will be called from Rocket::Core::Lua::ElementInstancernew
+LuaElementInstancer::LuaElementInstancer(lua_State* L) : ElementInstancer(), ref_InstanceElement(LUA_NOREF)
+{
+    if(lua_type(L,1) != LUA_TFUNCTION && !lua_isnoneornil(L,1))
+    {
+        Log::Message(Log::LT_ERROR, "The argument to ElementInstancer.new has to be a function or nil. You passed in a %s.", luaL_typename(L,1));
+        return;
+    }
+    PushFunctionsTable(L); //top of the table is now ELEMENTINSTANCERFUNCTIONS table
+    lua_pushvalue(L,1); //copy of the function
+    ref_InstanceElement = luaL_ref(L,-2); 
+    lua_pop(L,1); //pop the ELEMENTINSTANCERFUNCTIONS table
+}
+
+Element* LuaElementInstancer::InstanceElement(Element* ROCKET_UNUSED(parent), const String& tag, const XMLAttributes& ROCKET_UNUSED(attributes))
+{
+    lua_State* L = Interpreter::GetLuaState();
+    int top = lua_gettop(L);
+    Element* ret = NULL;
+    if(ref_InstanceElement != LUA_REFNIL && ref_InstanceElement != LUA_NOREF)
+    {
+        PushFunctionsTable(L);
+        lua_rawgeti(L,-1,ref_InstanceElement); //push the function
+        lua_pushstring(L,tag.CString()); //push the tag
+        Interpreter::ExecuteCall(1,1); //we pass in a string, and we want to get an Element back
+        ret = LuaType<Element>::check(L,-1);
+    }
+    else
+    {
+        Log::Message(Log::LT_WARNING, "Attempt to call the function for ElementInstancer.InstanceElement, the function does not exist.");
+    }
+    lua_settop(L,top);
+    return ret;
+}
+
+void LuaElementInstancer::ReleaseElement(Element* element)
+{
+    delete element;
+}
+
+void LuaElementInstancer::Release()
+{
+    delete this;
+}
+
+void LuaElementInstancer::PushFunctionsTable(lua_State* L)
+{
+    //make sure there is an area to save the function
+    lua_getglobal(L,"ELEMENTINSTANCERFUNCTIONS");
+    if(lua_isnoneornil(L,-1))
+    {
+        lua_newtable(L);
+        lua_setglobal(L,"ELEMENTINSTANCERFUNCTIONS");
+        lua_pop(L,1); //pop the unsucessful getglobal
+        lua_getglobal(L,"ELEMENTINSTANCERFUNCTIONS");
+    }
+}
+
+}
+}
+}

+ 64 - 0
Source/Core/Lua/LuaElementInstancer.h

@@ -0,0 +1,64 @@
+/*
+ * 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 ROCKETCORELUALUAELEMENTINSTANCER_H
+#define ROCKETCORELUALUAELEMENTINSTANCER_H
+
+#include <Rocket/Core/Element.h>
+#include <Rocket/Core/ElementInstancer.h>
+#include <Rocket/Core/Lua/lua.hpp>
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+class LuaElementInstancer : public Rocket::Core::ElementInstancer
+{
+public:
+    LuaElementInstancer(lua_State* L);
+    /// Instances an element given the tag name and attributes.
+	/// @param[in] parent The element the new element is destined to be parented to.
+	/// @param[in] tag The tag of the element to instance.
+	/// @param[in] attributes Dictionary of attributes.
+	virtual Element* InstanceElement(Element* parent, const String& tag, const XMLAttributes& attributes);
+	/// Releases an element instanced by this instancer.
+	/// @param[in] element The element to release.
+	virtual void ReleaseElement(Element* element);
+	/// Release the instancer.
+	virtual void Release();
+
+    int ref_InstanceElement;
+
+    //Pushes on to the top of the stack the table named EVENTINSTNACERFUNCTIONS
+    void PushFunctionsTable(lua_State* L);
+};
+
+}
+}
+}
+
+#endif

+ 7 - 4
Source/Core/Lua/Rocket.cpp

@@ -29,6 +29,8 @@
 #include "Rocket.h"
 #include <Rocket/Core/Core.h>
 #include <Rocket/Core/Input.h>
+#include "ElementInstancer.h"
+#include "LuaElementInstancer.h"
 
 namespace Rocket {
 namespace Core {
@@ -66,13 +68,12 @@ int rocketCreateContext(lua_State* L)
     if(new_context == NULL || dimensions == NULL)
     {
         lua_pushnil(L);
-        return 1;
     }
     else
     {
         LuaType<Context>::push(L, new_context);
-        return 1;
     }
+    return 1;
 }
 
 int rocketLoadFontFace(lua_State* L)
@@ -84,7 +85,10 @@ int rocketLoadFontFace(lua_State* L)
 
 int rocketRegisterTag(lua_State* L)
 {
-    //this may take some thought
+    const char* tag = luaL_checkstring(L,1);
+    LuaElementInstancer* lei = (LuaElementInstancer*)LuaType<ElementInstancer>::check(L,2);
+    LUACHECKOBJ(lei);
+    Factory::RegisterElementInstancer(tag,lei);
     return 0;
 }
 
@@ -297,7 +301,6 @@ RegType<rocket> rocketMethods[] =
 
 luaL_reg rocketGetters[] = 
 {
-    LUAGETTER(rocket,contexts)
     { NULL, NULL },
 };
 

+ 1 - 1
Source/Core/Lua/Rocket.h

@@ -36,7 +36,7 @@
     methods: 
     rocket.CreateContext(string name, Vector2i dimensions)
     rocket.LoadFontFace(string font_path)
-    rocket.RegisterTag(string tag, class) --NYI
+    rocket.RegisterTag(string tag, ElementInstancer instancer)
     
     getters:
     rocket.contexts  returns a table of contexts, which are indexed by number AND string, so there are two copies of each context in the table