Browse Source

Untested event inner-workings have been layed out.

Registered all of the types that I forgot to earlier.

Exposed the Interpreter and LuaType as dllexport/import.
Nate Starkey 13 years ago
parent
commit
a54055525a

+ 51 - 8
Build/RocketLua.vcproj

@@ -17,8 +17,8 @@
 	<Configurations>
 		<Configuration
 			Name="Debug|Win32"
-			OutputDirectory="$(SolutionDir)..\bin"
-			IntermediateDirectory="\build"
+			OutputDirectory="$(IntDir)"
+			IntermediateDirectory="build\$(ProjectName)\$(ConfigurationName)"
 			ConfigurationType="2"
 			CharacterSet="2"
 			DeleteExtensionsOnClean="*.obj;*.ilk;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;$(TargetPath)"
@@ -42,6 +42,7 @@
 				Name="VCCLCompilerTool"
 				Optimization="0"
 				AdditionalIncludeDirectories="$(SolutionDir)..\Include;$(SolutionDir)..\Source\Core;$(SolutionDir)..\Dependencies\lua\src;"
+				PreprocessorDefinitions="_WIN32,_DEBUG,RocketLua_EXPORTS"
 				MinimalRebuild="true"
 				BasicRuntimeChecks="3"
 				RuntimeLibrary="3"
@@ -61,12 +62,15 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
+				LinkLibraryDependencies="false"
 				AdditionalDependencies="lua51.lib RocketCore_d.lib"
-				OutputFile="$(OutDir)\$(ProjectName)_d.dll"
+				ShowProgress="0"
+				OutputFile="..\bin\$(ProjectName)_d.dll"
 				AdditionalLibraryDirectories="$(SolutionDir)..\bin"
 				GenerateManifest="false"
 				EnableUAC="false"
 				GenerateDebugInformation="true"
+				ImportLibrary="$(TargetDir)$(TargetName).lib"
 				TargetMachine="1"
 			/>
 			<Tool
@@ -93,8 +97,8 @@
 		</Configuration>
 		<Configuration
 			Name="Release|Win32"
-			OutputDirectory="$(SolutionDir)..\bin"
-			IntermediateDirectory="\build"
+			OutputDirectory="$(IntDir)"
+			IntermediateDirectory="build\$(ProjectName)\$(ConfigurationName)"
 			ConfigurationType="2"
 			CharacterSet="2"
 			WholeProgramOptimization="1"
@@ -119,6 +123,7 @@
 				Optimization="2"
 				EnableIntrinsicFunctions="true"
 				AdditionalIncludeDirectories="$(SolutionDir)..\Include;$(SolutionDir)..\Source\Core;$(SolutionDir)..\Dependencies\lua\src;"
+				PreprocessorDefinitions="_WIN32,NDEBUG,RocketLua_EXPORTS"
 				RuntimeLibrary="2"
 				EnableFunctionLevelLinking="true"
 				UsePrecompiledHeader="1"
@@ -138,10 +143,12 @@
 			<Tool
 				Name="VCLinkerTool"
 				AdditionalDependencies="lua51.lib;RocketCore.lib"
+				OutputFile="..\bin\$(ProjectName).dll"
 				GenerateManifest="false"
 				GenerateDebugInformation="false"
 				OptimizeReferences="2"
 				EnableCOMDATFolding="2"
+				ImportLibrary="$(TargetDir)$(TargetName).lib"
 				TargetMachine="1"
 			/>
 			<Tool
@@ -277,15 +284,19 @@
 				>
 			</File>
 			<File
-				RelativePath="..\Source\Core\Lua\RegTypes.h"
+				RelativePath="..\Source\Core\Lua\Rocket.cpp"
 				>
 			</File>
 			<File
-				RelativePath="..\Source\Core\Lua\Rocket.cpp"
+				RelativePath="..\Source\Core\Lua\Rocket.h"
 				>
 			</File>
 			<File
-				RelativePath="..\Source\Core\Lua\Rocket.h"
+				RelativePath="..\Source\Core\Lua\RocketLua.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\Source\Core\Lua\RocketLua.h"
 				>
 			</File>
 		</Filter>
@@ -325,6 +336,38 @@
 				>
 			</File>
 		</Filter>
+		<Filter
+			Name="Event"
+			>
+			<File
+				RelativePath="..\Source\Core\Lua\Event.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\Source\Core\Lua\Event.h"
+				>
+			</File>
+			<File
+				RelativePath="..\Source\Core\Lua\LuaEventListener.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\Source\Core\Lua\LuaEventListener.h"
+				>
+			</File>
+			<File
+				RelativePath="..\Source\Core\Lua\LuaEventListenerInstancer.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\Source\Core\Lua\LuaEventListenerInstancer.h"
+				>
+			</File>
+		</Filter>
+		<File
+			RelativePath="..\Source\Core\Lua\Header.h"
+			>
+		</File>
 		<File
 			RelativePath="..\Source\Core\Lua\precompiled.cpp"
 			>

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

@@ -1,65 +0,0 @@
-<?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>

+ 2 - 1
Source/Core/Lua/Context.h

@@ -30,12 +30,13 @@
 */
 #include "LuaType.h"
 #include "lua.hpp"
+#include <Rocket/Core/Context.h>
 
 
 namespace Rocket {
 namespace Core {
 namespace Lua {
-class Rocket::Core::Context;
+//class Rocket::Core::Context;
 
 //methods
 int ContextAddEventListener(lua_State* L, Context* obj);

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

@@ -2,6 +2,7 @@
 #include "precompiled.h"
 #include "Element.h"
 #include <ElementStyle.h>
+#include "LuaEventListener.h"
 
 
 namespace Rocket {
@@ -17,10 +18,27 @@ int ElementAddEventListener(lua_State* L, Element* obj)
     //default false if they didn't pass it in
     if (top < 3) capture = false;
     else capture = CHECK_BOOL(L,3);
+
     const char* event = luaL_checkstring(L,1);
-    EventListener* listener = NULL; //LuaType<EventListener>::check(L,2);
 
-    obj->AddEventListener(event,listener,capture);
+    LuaEventListener* listener = NULL;
+    int type = lua_type(L,2);
+    if(type == LUA_TFUNCTION)
+    {
+        lua_pushvalue(L,2);
+        int ref = lua_ref(L,true);
+        listener = new LuaEventListener(ref,obj);
+    }
+    else if(type == LUA_TSTRING)
+    {
+        const char* code = luaL_checkstring(L,2);
+        listener = new LuaEventListener(code,obj);
+    }
+
+    if(listener != NULL)
+    {
+        obj->AddEventListener(event,listener,capture);
+    }
     return 0;
 }
 

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

@@ -12,7 +12,7 @@
     local var = foo that is Lua. If you need info on the purpose of the functions, see the python docs
     
     //methods that need to be called from an Element object using the colon syntax
-    noreturn Element:AddEventListener(string event, EventListener listener, [bool capture])
+    noreturn Element:AddEventListener(string event, ? see footnote 1, [bool capture])
     noreturn Element:AppendChild(Element child)
     noreturn Element:Blur()
     noreturn Element:Click()
@@ -69,6 +69,18 @@
     Element.inner_rml = string
     Element.scroll_left = float
     Element.scroll_top = float  
+
+
+    footnote 1: for Element:AddEventListener(string,?,bool)
+    The ? can be either a string or a function. 
+    In the string, you can be guaranteed that you will have the
+    named variables 'event','element','document' available to you, and they mean the same as if you were to put
+    the string as onclick="string" in a .rml file.
+    If you give it a function, the function will be called every time that C++ EventListener::ProcessEvent would
+    would be called. In this case, it will call the function, and you can decide the name of the parameters, however
+    it is in a specific order. The order is event,element,document. So:
+    function foo(l,q,e) end element:AddEventListener("click",foo,true) is the correct syntax, and puts l=event,q=element,e=document
+    They are terrible names, but it is to make a point.
 */
 #include "LuaType.h"
 #include "lua.hpp"

+ 177 - 0
Source/Core/Lua/Event.cpp

@@ -0,0 +1,177 @@
+#include "precompiled.h"
+#include "LuaType.h"
+#include "lua.hpp"
+#include <Rocket/Core/Event.h>
+#include <Rocket/Core/Element.h>
+#include <Rocket/Core/Dictionary.h>
+
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+//method
+int EventStopPropagation(lua_State* L, Event* obj)
+{
+    LUACHECKOBJ(obj);
+    obj->StopPropagation();
+    return 0;
+}
+
+//getters
+int EventGetAttrcurrent_element(lua_State* L)
+{
+    Event* evt = LuaType<Event>::check(L,1);
+    LUACHECKOBJ(evt);
+    Element* ele = evt->GetCurrentElement();
+    LuaType<Element>::push(L,ele,false);
+    return 1;
+}
+
+int EventGetAttrtype(lua_State* L)
+{
+    Event* evt = LuaType<Event>::check(L,1);
+    LUACHECKOBJ(evt);
+    String type = evt->GetType();
+    lua_pushstring(L,type.CString());
+    return 1;
+}
+
+int EventGetAttrtarget_element(lua_State* L)
+{
+    Event* evt = LuaType<Event>::check(L,1);
+    LUACHECKOBJ(evt);
+    Element* target = evt->GetTargetElement();
+    LuaType<Element>::push(L,target,false);
+    return 1;
+}
+
+int EventGetAttrparameters(lua_State* L)
+{
+    Event* evt = LuaType<Event>::check(L,1);
+    LUACHECKOBJ(evt);
+    const Dictionary* params = evt->GetParameters();
+    int index;
+    String key;
+    Variant* value;
+
+    lua_newtable(L);
+    int tableindex = lua_gettop(L);
+    while(params->Iterate(index,key,value))
+    {
+        lua_pushstring(L,key.CString());
+        Variant::Type type = value->GetType();
+        switch(type)
+        {
+        case Variant::BYTE:
+        case Variant::CHAR:
+        case Variant::INT:
+            lua_pushinteger(L,*(int*)value);
+            break;
+        case Variant::FLOAT:
+            lua_pushnumber(L,*(float*)value);
+            break;
+        case Variant::COLOURB:
+            LuaType<Colourb>::push(L,(Colourb*)value,false);
+            break;
+        case Variant::COLOURF:
+            LuaType<Colourf>::push(L,(Colourf*)value,false);
+            break;
+        case Variant::STRING:
+            lua_pushstring(L,((String*)value)->CString());
+            break;
+        case Variant::VECTOR2:
+            //according to Variant.inl, it is going to be a Vector2f
+            LuaType<Vector2f>::push(L,((Vector2f*)value),false);
+            break;
+        case Variant::VOIDPTR:
+            lua_pushlightuserdata(L,(void*)value);
+            break;
+        default:
+            lua_pushnil(L);
+            break;
+        }
+        lua_settable(L,tableindex);
+    }
+    return 1;
+}
+
+
+
+//setters
+/*
+//Apparently, the dictionary returned is constant, and shouldn't be modified.
+//I am keeping this function in case that isn't the case
+int EventSetAttrparameters(lua_State* L)
+{
+    Event* evt = LuaType<Event>::check(L,1);
+    LUACHECKOBJ(evt);
+    const Dictionary* params = evt->GetParameters();
+    int valtype = lua_type(L,2);
+    if(valtype == LUA_TTABLE) //if the user gives a table, then go through the table and set everything
+    {
+        lua_pushnil(L); //becauase lua_next pops a key from the stack first, we don't want to pop the table
+        while(lua_next(L,2) != 0)
+        {
+            //[-1] is value, [-2] is key
+            int type = lua_type(L,-1);
+            const char* key = luaL_checkstring(L,-2); //key HAS to be a string, or things will go bad
+            switch(type)
+            {
+		    case LUA_TNUMBER:
+                params->Set(key,(float)lua_tonumber(L,-1));
+                break;
+		    case LUA_TBOOLEAN: 
+                params->Set(key,CHECK_BOOL(L,-1));
+                break;
+		    case LUA_TSTRING:
+                params->Set(key,luaL_checkstring(L,-1));
+                break;
+            case LUA_TUSERDATA:
+            case LUA_TLIGHTUSERDATA:
+                params->Set(key,lua_touserdata(L,-1));
+                break;
+            default:
+                break;
+            }
+        }
+    }
+    else if(valtype == LUA_TNIL)
+    {
+        params->Clear();
+    }
+    return 0;
+}
+*/
+
+
+RegType<Event> EventMethods[] =
+{
+    LUAMETHOD(Event,StopPropagation)
+    { NULL, NULL },
+};
+
+luaL_reg EventGetters[] =
+{
+    LUAGETTER(Event,current_element)
+    LUAGETTER(Event,type)
+    LUAGETTER(Event,target_element)
+    LUAGETTER(Event,parameters)
+    { NULL, NULL },
+};
+
+luaL_reg EventSetters[] =
+{
+    //LUASETTER(Event,parameters)
+    { NULL, NULL },
+};
+
+
+template<> const char* GetTClassName<Event>() { return "Event"; }
+template<> RegType<Event>* GetMethodTable<Event>() { return EventMethods; }
+template<> luaL_reg* GetAttrTable<Event>() { return EventGetters; }
+template<> luaL_reg* SetAttrTable<Event>() { return EventSetters; }
+
+}
+}
+}

+ 47 - 0
Source/Core/Lua/Event.h

@@ -0,0 +1,47 @@
+#pragma once
+/*
+    This defines an Event type name in the global Lua namespace
+
+    Generally, you won't create an event yourself, just receive it.
+
+    //method
+    noreturn Event:StopPropagation()
+    
+    //getters
+    Element Event.current_element
+    string Event.type
+    Element Event.target_element
+    {}key=string,value=int,float,Colourb/f,string,Vector2f,userdata Event.parameters
+*/
+
+#include "LuaType.h"
+#include "lua.hpp"
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+//method
+int EventStopPropagation(lua_State* L, Event* obj);
+
+//getters
+int EventGetAttrcurrent_element(lua_State* L);
+int EventGetAttrtype(lua_State* L);
+int EventGetAttrtarget_element(lua_State* L);
+int EventGetAttrparameters(lua_State* L);
+
+//setters
+//int EventSetAttrparameters(lua_State* L);
+
+RegType<Event> EventMethods[];
+luaL_reg EventGetters[];
+luaL_reg EventSetters[];
+
+template<> const char* GetTClassName<Event>();
+template<> RegType<Event>* GetMethodTable<Event>();
+template<> luaL_reg* GetAttrTable<Event>();
+template<> luaL_reg* SetAttrTable<Event>();
+
+}
+}
+}

+ 20 - 0
Source/Core/Lua/Header.h

@@ -0,0 +1,20 @@
+#ifndef ROCKETLUAHEADER_H
+#define ROCKETLUAHEADER_H
+
+#include <Rocket/Core/Platform.h>
+
+#if !defined STATIC_LIB
+	#ifdef ROCKET_PLATFORM_WIN32
+		#ifdef RocketLua_EXPORTS
+			#define ROCKETLUA_API __declspec(dllexport)
+		#else
+			#define ROCKETLUA_API __declspec(dllimport)
+		#endif
+	#else
+		#define ROCKETLUA_API __attribute__((visibility("default")))
+	#endif
+#else
+	#define ROCKETLUA_API
+#endif
+
+#endif

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

@@ -5,13 +5,12 @@
 #include "LuaType.h"
 #include "LuaDocumentElementInstancer.h"
 #include <Rocket/Core/Factory.h>
+#include "LuaEventListenerInstancer.h"
 
 namespace Rocket {
 namespace Core {
 namespace Lua {
 lua_State* Interpreter::_L = NULL;
-//forward declaration of the types unique to the lua portion
-class rocket;
 
 void Interpreter::Startup()
 {
@@ -84,7 +83,7 @@ bool Interpreter::ExecuteCall(int params, int res)
 {
     bool ret = true;
     int top = lua_gettop(_L);
-    if(strcmp(luaL_typename(_L,top-params),"function"))
+    if(lua_type(_L,top-params) != LUA_TFUNCTION)
     {
         ret = false;
         //stack cleanup
@@ -131,6 +130,7 @@ void Interpreter::OnInitialise()
 {
     Startup();
     Factory::RegisterElementInstancer("body",new LuaDocumentElementInstancer())->RemoveReference();
+    Factory::RegisterEventListenerInstancer(new LuaEventListenerInstancer())->RemoveReference();
 }
 
 void Interpreter::OnShutdown()

+ 22 - 21
Source/Core/Lua/Interpreter.h

@@ -10,30 +10,31 @@
 namespace Rocket {
 namespace Core {
 namespace Lua {
-    class Interpreter : public Plugin
-    {
-    public:
-        static void LoadFile(const Rocket::Core::String& file);
-        static void DoString(const Rocket::Core::String& str);
-        static void Report();
 
-        static void BeginCall(int funRef);
-        static bool ExecuteCall(int params = 0, int res = 0);
-        static void EndCall(int res = 0);
+class Interpreter : public Plugin
+{
+public:
+    static void LoadFile(const Rocket::Core::String& file);
+    static void DoString(const Rocket::Core::String& str);
+    static void Report();
 
-        static inline lua_State* GetLuaState();
-        
-        //From Plugin
-        virtual int GetEventClasses();
-        virtual void OnInitialise();
-        virtual void OnShutdown();
-    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();
+    static void BeginCall(int funRef);
+    static bool ExecuteCall(int params = 0, int res = 0);
+    static void EndCall(int res = 0);
 
-        static lua_State* _L;
-    };
+    static lua_State* GetLuaState();
+    
+    //From Plugin
+    virtual int GetEventClasses();
+    virtual void OnInitialise();
+    virtual void OnShutdown();
+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();
+
+    static lua_State* _L;
+};
 }
 }
 }

+ 52 - 0
Source/Core/Lua/LuaEventListener.cpp

@@ -0,0 +1,52 @@
+#include "precompiled.h"
+#include "LuaEventListener.h"
+#include "Interpreter.h"
+#include "LuaType.h"
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+typedef Rocket::Core::ElementDocument Document;
+
+LuaEventListener::LuaEventListener(const String& code, Element* element) : EventListener()
+{
+    String function = "function (event,element,document) ";
+    function.Append(code);
+    function.Append("end");
+
+    lua_State* L = Interpreter::GetLuaState();
+
+    luaL_loadstring(L,function.CString()); //pushes the compiled string to the top of the stack
+    luaFuncRef = lua_ref(L,true); //creates a reference to the item at the top of the stack
+    attached = element;
+    parent = element->GetOwnerDocument();
+}
+
+//if it is created from a Lua Element
+LuaEventListener::LuaEventListener(int ref, Element* element)
+{
+    luaFuncRef = ref;
+    attached = element;
+    parent = element->GetOwnerDocument();
+}
+
+/// Process the incoming Event
+void LuaEventListener::ProcessEvent(Event& event)
+{
+    lua_State* L = Interpreter::GetLuaState();
+    int top = lua_gettop(L); 
+    //push the arguments
+    LuaType<Event>::push(L,&event,false);
+    LuaType<Element>::push(L,attached,false);
+    LuaType<Document>::push(L,parent,false);
+    
+    lua_getref(L,luaFuncRef);
+    Interpreter::ExecuteCall(3,0); //call the function at the top of the stack with 3 arguments
+
+    lua_settop(L,top); //balanced stack makes Lua happy
+    
+}
+
+}
+}
+}

+ 32 - 0
Source/Core/Lua/LuaEventListener.h

@@ -0,0 +1,32 @@
+#pragma once
+#include <Rocket/Core/EventListener.h>
+#include "lua.hpp"
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+class LuaEventListener : public EventListener
+{
+public:
+    //The plan is to wrap the code in an anonymous function so that we can have named parameters to use,
+    //rather than putting them in global variables
+    LuaEventListener(const String& code, Element* element);
+
+    //This is called from a Lua Element if in element:AddEventListener it passes a function in as the 2nd
+    //parameter rather than a string. We don't wrap the function in an anonymous function, so the user
+    //should take care to have the proper order. The order is event,element,document.
+    LuaEventListener(int ref, Element* element);
+
+    /// Process the incoming Event
+	virtual void ProcessEvent(Event& event);
+private:
+    //the lua-side function to call when ProcessEvent is called
+    int luaFuncRef;
+    Element* attached;
+    ElementDocument* parent;
+};
+
+}
+}
+}

+ 25 - 0
Source/Core/Lua/LuaEventListenerInstancer.cpp

@@ -0,0 +1,25 @@
+#include "precompiled.h"
+#include "LuaEventListenerInstancer.h"
+#include "LuaEventListener.h"
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+/// Instance an event listener object.
+/// @param value Value of the event.
+/// @param element Element that triggers the events.
+EventListener* LuaEventListenerInstancer::InstanceEventListener(const String& value, Element* element)
+{
+    return new LuaEventListener(value,element);
+}
+
+/// Releases this event listener instancer.
+void LuaEventListenerInstancer::Release()
+{
+    delete this;
+}
+
+}
+}
+}

+ 22 - 0
Source/Core/Lua/LuaEventListenerInstancer.h

@@ -0,0 +1,22 @@
+#pragma once
+#include <Rocket/Core/EventListenerInstancer.h>
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+class LuaEventListenerInstancer : public EventListenerInstancer
+{
+public:
+    /// Instance an event listener object.
+	/// @param value Value of the event.
+	/// @param element Element that triggers the events.
+	virtual EventListener* InstanceEventListener(const String& value, Element* element);
+
+	/// Releases this event listener instancer.
+	virtual void Release();
+};
+
+}
+}
+}

+ 7 - 7
Source/Core/Lua/LuaType.h

@@ -3,7 +3,7 @@
 /*
     This is mostly the definition of the Lua userdata that we give to the user
 */
-
+#include "Header.h"
 #include "lua.hpp"
 
 namespace Rocket {
@@ -33,23 +33,23 @@ namespace Lua {
 
 //replacement for luaL_reg that uses a different function pointer signature, but similar syntax
 template<typename T>
-struct RegType
+struct ROCKETLUA_API RegType
 {
     const char* name;
     int (*ftnptr)(lua_State*,T*);
 };
 
 //this is for all of the methods available from Lua that call to the C functions
-template<typename T> RegType<T>* GetMethodTable();
+template<typename T> ROCKETLUA_API RegType<T>* GetMethodTable();
 //this is for all of the function that 'get' an attribute/property
-template<typename T> luaL_reg* GetAttrTable();
+template<typename T> ROCKETLUA_API luaL_reg* GetAttrTable();
 //this is for all of the functions that 'set' an attribute/property
-template<typename T> luaL_reg* SetAttrTable();
+template<typename T> ROCKETLUA_API luaL_reg* SetAttrTable();
 //String representation of the class
-template<typename T> const char* GetTClassName();
+template<typename T> ROCKETLUA_API const char* GetTClassName();
 
 template<typename T>
-class LuaType
+class ROCKETLUA_API LuaType
 {
 public:
     typedef int (*ftnptr)(lua_State* L, T* ptr);

+ 7 - 0
Source/Core/Lua/LuaType.inl

@@ -1,10 +1,17 @@
 #include "precompiled.h"
 #include "LuaType.h"
+#include "Rocket.h"
+#include <Rocket/Core/Event.h>
+#include <Rocket/Core/Element.h>
+#include <Rocket/Core/ElementDocument.h>
+#include <Rocket/Core/ElementStyle.h>
+#include <Rocket/Core/Context.h>
 
 
 namespace Rocket {
 namespace Core {
 namespace Lua {
+typedef Rocket::Core::ElementDocument Document;
 
 template<typename T>
 void LuaType<T>::Register(lua_State* L)

+ 0 - 14
Source/Core/Lua/RegTypes.h

@@ -1,14 +0,0 @@
-#pragma once
-#include "LuaType.h"
-//Macro to eliminate a bunch of repetitive typing. It declares all of the templated functions that are needed to
-//bind a C++ class to Lua. You have to actually implement the functions later on.
-
-
-namespace Rocket {
-namespace Core {
-namespace Lua {
-
-    ROCKETREGTYPE(rocket)
-}
-}
-}

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

@@ -9,4 +9,10 @@ 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);

+ 17 - 0
Source/Core/Lua/RocketLua.cpp

@@ -0,0 +1,17 @@
+#include "precompiled.h"
+#include "Interpreter.h"
+
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+void Initialise()
+{
+    Rocket::Core::RegisterPlugin(new Interpreter());
+    
+}
+
+}
+}
+}

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

@@ -0,0 +1,12 @@
+#pragma once
+
+#include "Header.h"
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+void ROCKETLUA_API Initialise();
+}
+}
+}