Bladeren bron

The sample now works completely.

The sample only has one warning upon exit, trying to remove the logo when it has already been destroyed.

Created the DataFormatter class for Lua and the C++ object LuaDataFormatter.

Cleaned up the includes so that any of the exposed API header files only exist in /Include/Rocket/Core/Lua
Nate Starkey 13 jaren geleden
bovenliggende
commit
2a72dfdbb6

+ 16 - 0
Build/RocketLua.vcproj

@@ -180,6 +180,14 @@
 		<Filter
 			Name="Controls"
 			>
+			<File
+				RelativePath="..\Source\Controls\Lua\DataFormatter.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\Source\Controls\Lua\DataFormatter.h"
+				>
+			</File>
 			<File
 				RelativePath="..\Source\Controls\Lua\DataSource.cpp"
 				>
@@ -212,6 +220,14 @@
 				RelativePath="..\Source\Controls\Lua\ElementTabSet.h"
 				>
 			</File>
+			<File
+				RelativePath="..\Source\Controls\Lua\LuaDataFormatter.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\Source\Controls\Lua\LuaDataFormatter.h"
+				>
+			</File>
 			<File
 				RelativePath="..\Source\Controls\Lua\LuaDataSource.cpp"
 				>

+ 1 - 1
Samples/luainvaders/data/high_score.rml

@@ -43,7 +43,7 @@ HighScore = HighScore or {}
 
 --because we pass it as a plain function in HighScore.OnLoad, we have to pay attention
 --to the order of arguments. We don't need the first two in this case, so the name doesn't matter
-function HighScore.OnRowAdd(_,_,document)
+function HighScore.OnRowAdd(_a,_b,document)
 	input = document:GetElementById('player_input')
 	if input then
 		input:Focus()

+ 2 - 2
Samples/luainvaders/data/main_menu.rml

@@ -22,8 +22,8 @@ MainMenu = MainMenu or {}
 
 function MainMenu.CloseLogo(document)
 	if document.context then
-		--context.documents seems to be empty
-		--document.context.documents['logo']:Close()
+        --this will log an error upon exit, but doesn't crash
+		document.context.documents['logo']:Close()
     end
 end
 		</script>

+ 10 - 6
Samples/luainvaders/data/options.rml

@@ -43,21 +43,25 @@ end
 function Options.Deserialize(filename)
     local ret = {} --table to return
     --cache functions that are used a lot for faster lookup
-    local lines = io.lines
     local gmatch = string.gmatch
     
-    for line in lines(filename) do
-        for k,v in gmatch(line, '(%w+)=(%w+)') do ret[k] = v end
-    end 
-    --io.lines automatically closes the file when it get to the end
+    local f = io.open(filename)
+    if f then
+        for line in f:lines() do
+            for k,v in gmatch(line, '(%w+)=(%w+)') do ret[k] = v end
+        end 
+        f:close()
+    else
+        return nil
+    end
     
     return ret
 end
         
         
 function Options.LoadOptions(document)
-    --TODO: check for a non-existing file so we don't get warnings
     local options = Options.Deserialize('options.dat')
+    if options == nil then return end --short circuit if the file doesn't exist
     local type = Element.etype
     
     document:GetElementById(options['graphics']):AsType(type.input).checked = true

+ 1 - 1
Samples/luainvaders/data/pause.rml

@@ -21,7 +21,7 @@
 	<body template="luawindow" onload="Window.OnWindowLoad(element) Game.SetPaused(true)" onunload="Game.SetPaused(false)">
 		<br />
 		<p>Are you sure you want to end this game?</p>
-		<button onclick="Window.LoadMenu('high_score') document.context.documents['game_window']:Close()">Yes</button>
+		<button onclick="Window.LoadMenu('high_score',document) document.context.documents['game_window']:Close()">Yes</button>
 		<button onclick="document:Close()">No!</button>
 	</body>
 </rml>

+ 30 - 0
Samples/luainvaders/lua/start.lua

@@ -1,4 +1,34 @@
 
+Formatters = Formatters or {} --table to hold the formatters so that they don't get GC'd
+
+--this will use two different ways to show how to create DataFormatter objects
+--first way is to set the FormatData function explicitly
+local formatter = DataFormatter.new("name")
+formatter.FormatData = function(raw_data)
+    --[[ 
+    Data format:
+    raw_data[0] is the name.
+    raw_data[1] is a bool - True means the name has to be entered. False means the name has been entered already.
+    ]]
+    
+    formatted_data = ""
+    
+    if (raw_data[1] == "1") then
+        --because we know that it is only used in the high_score.rml file, use that namespace for the OnKeyDown function
+        formatted_data = "<input id=\"player_input\" type=\"text\" name=\"name\" onkeydown=\"HighScore.OnKeyDown(event)\" />"
+    else
+        formatted_data = raw_data[0]
+    end
+        
+    return formatted_data
+end
+Formatters["name"] = formatter --using "name" as the key only for convenience
+
+--second example uses a previously defined function, and passes in as a parameter for 'new'
+function SecondFormatData(raw_data)
+    return "<defender style=\"color: rgba(" .. raw_data[0] .. ");\" />"
+end
+Formatters["ship"] = DataFormatter.new("ship",SecondFormatData)
 
 
 function Startup()

+ 78 - 0
Source/Controls/Lua/DataFormatter.cpp

@@ -0,0 +1,78 @@
+#include "precompiled.h"
+#include "DataFormatter.h"
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+//method
+int DataFormatternew(lua_State* L)
+{
+    DataFormatter* df;
+    int ref = LUA_NOREF;
+    int top = lua_gettop(L);
+    if(top == 0)
+        df = new DataFormatter();
+    else if (top > 0) //at least one element means at least a name
+    {
+        if(top > 1) //if a function as well
+        {
+            if(lua_type(L,2) != LUA_TFUNCTION)
+            {
+                Log::Message(Log::LT_ERROR, "Lua: In DataFormatter.new, the second argument MUST be a function (or not exist). You passed in a %s.", lua_typename(L,lua_type(L,2)));
+            }
+            else //if it is a function
+            {
+                LuaDataFormatter::PushDataFormatterFunctionTable(L);
+                lua_pushvalue(L,2); //re-push the function so it is on the top of the stack
+                ref = luaL_ref(L,-2);
+                lua_pop(L,1); //pop the function table
+            }
+        }
+        df = new DataFormatter(luaL_checkstring(L,1));
+        df->ref_FormatData = ref; //will either be valid or LUA_NOREF
+    }
+    LuaType<DataFormatter>::push(L,df,true);
+    return 1;
+}
+
+//setter
+int DataFormatterSetAttrFormatData(lua_State* L)
+{
+    DataFormatter* obj = LuaType<DataFormatter>::check(L,1);
+    LUACHECKOBJ(obj);
+    int ref = LUA_NOREF;
+    if(lua_type(L,2) != LUA_TFUNCTION)
+    {
+        Log::Message(Log::LT_ERROR, "Lua: Setting DataFormatter.FormatData, the value must be a function. You passed in a %s.", lua_typename(L,lua_type(L,2)));
+    }
+    else //if it is a function
+    {
+        LuaDataFormatter::PushDataFormatterFunctionTable(L);
+        lua_pushvalue(L,2); //re-push the function so it is on the top of the stack
+        ref = luaL_ref(L,-2);
+        lua_pop(L,1); //pop the function table
+    }
+    obj->ref_FormatData = ref;
+    return 0;
+}
+
+RegType<DataFormatter> DataFormatterMethods[] =
+{
+    { NULL, NULL },
+};
+
+luaL_reg DataFormatterGetters[] =
+{
+    { NULL, NULL },
+};
+
+luaL_reg DataFormatterSetters[] =
+{
+    LUASETTER(DataFormatter,FormatData)
+    { NULL, NULL },
+};
+
+}
+}
+}

+ 39 - 0
Source/Controls/Lua/DataFormatter.h

@@ -0,0 +1,39 @@
+#pragma once
+/*
+    This defines the DataFormatter type in the Lua global namespace
+
+    The usage is to create a new DataFormatter, and set the FormatData variable on it to a function, where you return a rml string that will
+    be the formatted data
+
+    //method
+    --this method is NOT called from any particular instance, use it as from the type
+    DataFormatter DataFormatter.new([string name[, function FormatData]]) --both are optional, but if you pass in a function, you must also pass in a name first
+
+    //setter
+    --this is called from a specific instance (one returned from DataFormatter.new)
+    DataFormatter.FormatData = function( {key=int,value=string} ) --where indexes are sequential, like an array of strings
+*/
+
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
+#include "LuaDataFormatter.h"
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+typedef LuaDataFormatter DataFormatter;
+//for DataFormatter.new
+template<> void LuaType<DataFormatter>::extra_init(lua_State* L, int metatable_index);
+
+//method
+int DataFormatternew(lua_State* L);
+
+//setter
+int DataFormatterSetAttrFormatData(lua_State* L);
+
+RegType<DataFormatter> DataFormatterMethods[];
+luaL_reg DataFormatterGetters[];
+luaL_reg DataFormatterSetters[];
+}
+}
+}

+ 68 - 0
Source/Controls/Lua/LuaDataFormatter.cpp

@@ -0,0 +1,68 @@
+#include "precompiled.h"
+#include "LuaDataFormatter.h"
+#include <Rocket/Core/Lua/Interpreter.h>
+#include <Rocket/Core/Log.h>
+
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+LuaDataFormatter::LuaDataFormatter(const String& name) : Rocket::Controls::DataFormatter(name), ref_FormatData(LUA_NOREF)
+{
+    
+}
+
+LuaDataFormatter::~LuaDataFormatter()
+{
+    //empty
+}
+
+void LuaDataFormatter::FormatData(Rocket::Core::String& formatted_data, const Rocket::Core::StringList& raw_data)
+{
+    if(ref_FormatData == LUA_NOREF || ref_FormatData == LUA_REFNIL)
+    {
+        Log::Message(Log::LT_ERROR, "In LuaDataFormatter: There is no value assigned to the \"FormatData\" variable.");
+        return;
+    }
+    lua_State* L = Interpreter::GetLuaState();
+    PushDataFormatterFunctionTable(L); // push the table where the function resides
+    lua_rawgeti(L,-1,ref_FormatData); //push the function
+    if(lua_type(L,-1) != LUA_TFUNCTION)
+    {
+        Log::Message(Log::LT_ERROR, "In LuaDataFormatter: The value for the FormatData variable must be a function. You passed in a %s.", lua_typename(L,lua_type(L,-1)));
+        return;
+    }
+    lua_newtable(L); //to hold raw_data
+    int tbl = lua_gettop(L);
+    for(unsigned int i = 0; i < raw_data.size(); i++)
+    {
+        lua_pushstring(L,raw_data[i].CString());
+        lua_rawseti(L,tbl,i);
+    }
+    Interpreter::ExecuteCall(1,1); //1 parameter (the table), 1 result (a string)
+
+    //top of the stack should be the return value
+    if(lua_type(L,-1) != LUA_TSTRING)
+    {
+        Log::Message(Log::LT_ERROR, "In LuaDataFormatter: the return value of FormatData must be a string. You returned a %s.", lua_typename(L,lua_type(L,-1)));
+        return;
+    }
+    formatted_data = String(lua_tostring(L,-1));
+}
+
+void LuaDataFormatter::PushDataFormatterFunctionTable(lua_State* L)
+{
+    lua_getglobal(L,"LUADATAFORMATTERFUNCTIONS");
+    if(lua_isnoneornil(L,-1))
+    {
+        lua_newtable(L);
+        lua_setglobal(L,"LUADATAFORMATTERFUNCTIONS");
+        lua_pop(L,1); //pop the unsucessful getglobal
+        lua_getglobal(L,"LUADATAFORMATTERFUNCTIONS");
+    }
+}
+
+}
+}
+}

+ 26 - 0
Source/Controls/Lua/LuaDataFormatter.h

@@ -0,0 +1,26 @@
+#pragma once
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Controls/DataFormatter.h>
+
+using Rocket::Controls::DataFormatter;
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+class LuaDataFormatter : public Rocket::Controls::DataFormatter
+{
+public:
+    LuaDataFormatter(const String& name = "");
+    ~LuaDataFormatter();
+
+    virtual void FormatData(Rocket::Core::String& formatted_data, const Rocket::Core::StringList& raw_data);
+
+    //Helper function used to push on to the stack the table where the function ref should be stored
+    static void PushDataFormatterFunctionTable(lua_State* L);
+
+    int ref_FormatData; //the lua reference to the FormatData function
+};
+
+}
+}
+}

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

@@ -26,8 +26,8 @@
     local red,green,blue,alpha = col.rgba    
 */
 
-#include "LuaType.h"
-#include "lua.hpp"
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
 #include <Rocket/Core/Types.h>
 
 using Rocket::Core::Colourb;

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

@@ -23,8 +23,8 @@
     local red,green,blue,alpha = col.rgba    
 */
 
-#include "lua.hpp"
-#include "LuaType.h"
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
 #include <Rocket/Core/Types.h>
 
 using Rocket::Core::Colourf;

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

@@ -36,8 +36,8 @@
 	]]
 
 */
-#include "LuaType.h"
-#include "lua.hpp"
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
 #include <Rocket/Core/Context.h>
 
 

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

@@ -22,8 +22,8 @@
     //setter
     Document.title = string
 */
-#include "lua.hpp"
-#include "LuaType.h"
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
 #include <Rocket/Core/ElementDocument.h>
 
 

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

@@ -89,8 +89,8 @@
     datagrid,dataselect,element,form,input,select,tabset,textarea
     If you give it a bad parameter, it will return an Element type
 */
-#include "LuaType.h"
-#include "lua.hpp"
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
 #include <Rocket/Core/Element.h>
 
 namespace Rocket {

+ 2 - 2
Source/Core/Lua/ElementStyle.cpp

@@ -1,6 +1,6 @@
 #include "precompiled.h"
-#include "LuaType.h"
-#include "lua.hpp"
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
 #include "ElementStyle.h"
 #include <ElementStyle.h>
 

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

@@ -44,8 +44,8 @@
     At the moment, you are unable to say element.style = {} and have a table of key,value pairs
     added to the style. That is planned for a little later
 */
-#include "LuaType.h"
-#include "lua.hpp"
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
 #include <ElementStyle.h>
 
 namespace Rocket {

+ 2 - 2
Source/Core/Lua/Event.cpp

@@ -1,6 +1,6 @@
 #include "precompiled.h"
-#include "LuaType.h"
-#include "lua.hpp"
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
 #include <Rocket/Core/Event.h>
 #include <Rocket/Core/Element.h>
 #include <Rocket/Core/Dictionary.h>

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

@@ -14,8 +14,8 @@
     {}key=string,value=int,float,Colourb/f,string,Vector2f,userdata Event.parameters
 */
 
-#include "LuaType.h"
-#include "lua.hpp"
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
 
 namespace Rocket {
 namespace Core {

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

@@ -1,20 +0,0 @@
-#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

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

@@ -1,11 +1,12 @@
 #include "precompiled.h"
-#include "Interpreter.h"
+#include <Rocket/Core/Lua/Interpreter.h>
 #include <Rocket/Core/Log.h>
 #include <Rocket/Core/String.h>
 #include <Rocket/Core/Lua/LuaType.h>
 #include "LuaDocumentElementInstancer.h"
 #include <Rocket/Core/Factory.h>
 #include "LuaEventListenerInstancer.h"
+#include "LuaDataFormatter.h"
 #include "Rocket.h"
 
 namespace Rocket {
@@ -13,6 +14,7 @@ namespace Core {
 namespace Lua {
 lua_State* Interpreter::_L = NULL;
 typedef Rocket::Core::ElementDocument Document;
+typedef Rocket::Core::Lua::LuaDataFormatter DataFormatter;
 
 void Interpreter::Startup()
 {
@@ -48,6 +50,7 @@ void Interpreter::RegisterEverything(lua_State* L)
             LuaType<Rocket::Controls::ElementFormControlTextArea>::Register(L);
     LuaType<Event>::Register(L);
     LuaType<Context>::Register(L);
+    LuaType<DataFormatter>::Register(L);
     LuaType<rocket>::Register(L);
 }
 

+ 0 - 46
Source/Core/Lua/Interpreter.h

@@ -1,46 +0,0 @@
-#ifndef ROCKETCORELUAINTERPRETER_H
-#define ROCKETCORELUALUATYPE_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 <Rocket/Core/Lua/lua.hpp>
-#include <Rocket/Core/Plugin.h>
-
-namespace Rocket {
-namespace Core {
-namespace Lua {
-
-class ROCKETLUA_API 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);
-
-    static lua_State* GetLuaState();
-
-    static void Initialise();
-	static void Shutdown();
-    
-    //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;
-};
-}
-}
-}
-#endif
-

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

@@ -1,5 +1,5 @@
-#include "LuaType.h"
-#include "lua.hpp"
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
 
 /*
     Declares "Log" in the global Lua namespace.

+ 2 - 2
Source/Core/Lua/LuaDocument.cpp

@@ -1,7 +1,7 @@
 #include "precompiled.h"
 #include "LuaDocument.h"
-#include "lua.hpp"
-#include "Interpreter.h"
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/Interpreter.h>
 
 
 namespace Rocket {

+ 2 - 2
Source/Core/Lua/LuaEventListener.cpp

@@ -1,7 +1,7 @@
 #include "precompiled.h"
 #include "LuaEventListener.h"
-#include "Interpreter.h"
-#include "LuaType.h"
+#include <Rocket/Core/Lua/Interpreter.h>
+#include <Rocket/Core/Lua/LuaType.h>
 
 namespace Rocket {
 namespace Core {

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

@@ -1,7 +1,7 @@
 #pragma once
 #include <Rocket/Core/EventListener.h>
 #include <Rocket/Core/String.h>
-#include "lua.hpp"
+#include <Rocket/Core/Lua/lua.hpp>
 
 namespace Rocket {
 namespace Core {

+ 1 - 5
Source/Core/Lua/LuaType.cpp

@@ -73,6 +73,7 @@ int LuaType<T>::push(lua_State *L, T* obj, bool gc)
             luaL_newmetatable(L,"DO NOT TRASH"); //[4] = the new metatable
             lua_pop(L,1); //pop [4]
         }
+        lua_pop(L,1); //pop [3]
         lua_getfield(L,LUA_REGISTRYINDEX,"DO NOT TRASH"); //->[3] = value returned from function
         if(gc == false) //if we shouldn't garbage collect it, then put the name in to [3]
         {
@@ -86,14 +87,9 @@ int LuaType<T>::push(lua_State *L, T* obj, bool gc)
         }
         lua_pop(L,1); // -> pop [3]
     }
-    String strtype = lua_typename(L,ud);
-    strtype = lua_typename(L,mt);
     lua_settop(L,ud); //[ud = 2] -> remove everything that is above 2, top = [2]
-    strtype = lua_typename(L,-1);
     lua_replace(L, mt); //[mt = 1] -> move [2] to pos [1], and pop previous [1]
-    strtype = lua_typename(L,-1);
     lua_settop(L, mt); //remove everything above [1]
-    strtype = lua_typename(L,-1);
     return mt;  // index of userdata containing pointer to T object
 }
 

+ 0 - 113
Source/Core/Lua/LuaType.h

@@ -1,113 +0,0 @@
-#ifndef 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/lua.hpp>
-
-namespace Rocket {
-namespace Core {
-namespace Lua {
-
-//As an example, if you used this macro like
-//LUAMETHOD(Unit,GetId)
-//it would result in code that looks like
-//{ "GetId", UnitGetId },
-//Which would force you to create a global function named UnitGetId in C with the correct function signature, usually int(*)(lua_State*,type*);
-#define LUAMETHOD(type,name) { #name, type##name },
-
-//See above, but the method must match the function signature int(*)(lua_State*) and as example:
-//LUAGETTER(Unit,Id) would mean you need a function named UnitGetAttrId
-//The first stack position will be the userdata
-#define LUAGETTER(type,varname) { #varname, type##GetAttr##varname },
-
-//Same method signature as above, but as example:
-//LUASETTER(Unit,Id) would mean you need a function named UnitSetAttrId
-//The first stack position will be the userdata, and the second will be value on the other side of the equal sign
-#define LUASETTER(type,varname) { #varname, type##SetAttr##varname },
-
-#define CHECK_BOOL(L,narg) (lua_toboolean((L),(narg)) > 0 ? true : false )
-#define LUACHECKOBJ(obj) if(obj == NULL) { lua_pushnil(L); return 1; }
-
-//put this in the type.cpp file
-#define LUATYPEDEFINE(type) \
-    template<> const char* GetTClassName<type>() { return #type; } \
-    template<> RegType<type>* GetMethodTable<type>() { return type##Methods; } \
-    template<> luaL_reg* GetAttrTable<type>() { return type##Getters; } \
-    template<> luaL_reg* SetAttrTable<type>() { return type##Setters; } \
-
-//put this in the type.h file
-#define LUATYPEDECLARE(type) \
-    template<> const char* GetTClassName<type>(); \
-    template<> RegType<type>* GetMethodTable<type>(); \
-    template<> luaL_reg* GetAttrTable<type>(); \
-    template<> luaL_reg* SetAttrTable<type>(); \
-
-
-//replacement for luaL_reg that uses a different function pointer signature, but similar syntax
-template<typename T>
-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> ROCKETLUA_API inline RegType<T>* GetMethodTable();
-//this is for all of the function that 'get' an attribute/property
-template<typename T> ROCKETLUA_API inline luaL_reg* GetAttrTable();
-//this is for all of the functions that 'set' an attribute/property
-template<typename T> ROCKETLUA_API inline luaL_reg* SetAttrTable();
-//String representation of the class
-template<typename T> ROCKETLUA_API inline const char* GetTClassName();
-
-template<typename T>
-class ROCKETLUA_API LuaType
-{
-public:
-    typedef int (*ftnptr)(lua_State* L, T* ptr);
-    typedef struct { const char* name; ftnptr func; } RegType;
-
-    static void Register(lua_State *L);
-    static int push(lua_State *L, T* obj, bool gc=false);
-    static T* check(lua_State* L, int narg);
-
-    //for calling a C closure with upvalues
-    static int thunk(lua_State* L);
-    //pointer to string
-    static void tostring(char* buff, void* obj);
-    //these are metamethods
-    //.__gc
-    static int gc_T(lua_State* L);
-    //.__tostring
-    static int tostring_T(lua_State* L);
-    //.__index
-    static int index(lua_State* L);
-    //.__newindex
-    static 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  void extra_init(lua_State* L, int metatable_index);
-    //Registers methods,getters,and setters to the type
-    static 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 bool is_reference_counted();
-private:
-    LuaType(); //hide constructor
-
-};
-}
-}
-}
-
-//#include "LuaType.inl"
-#endif

+ 11 - 1
Source/Core/Lua/LuaTypeTemplateSpec.inl

@@ -5,7 +5,7 @@
 #include "precompiled.h"
 #include <Rocket/Core/Core.h>
 #include <Rocket/Controls/Controls.h>
-#include "LuaType.h"
+#include <Rocket/Core/Lua/LuaType.h>
 #include "Colourb.h"
 #include "Colourf.h"
 #include "Vector2f.h"
@@ -27,6 +27,7 @@
 #include "ElementDataGridRow.h"
 #include "ElementTabSet.h"
 #include "DataSource.h"
+#include "DataFormatter.h"
 
 
 
@@ -56,6 +57,7 @@ LUATYPEDEFINE(ElementDataGrid)
 LUATYPEDEFINE(ElementDataGridRow)
 LUATYPEDEFINE(ElementTabSet)
 LUATYPEDEFINE(DataSource)
+LUATYPEDEFINE(DataFormatter)
 
 
 template class LuaType<Colourb>;
@@ -79,6 +81,7 @@ template class LuaType<ElementDataGrid>;
 template class LuaType<ElementDataGridRow>;
 template class LuaType<ElementTabSet>;
 template class LuaType<DataSource>;
+template class LuaType<DataFormatter>;
 
 
 //reference counted types
@@ -351,6 +354,13 @@ template<> void LuaType<Log>::extra_init(lua_State* L, int metatable_index)
     return;
 }
 
+template<> void LuaType<DataFormatter>::extra_init(lua_State* L, int metatable_index)
+{
+    lua_pushcfunction(L,DataFormatternew);
+    lua_setfield(L,metatable_index-1,"new");
+    return;
+}
+
 }
 }
 }

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

@@ -14,8 +14,8 @@
 
 */
 
-#include "LuaType.h"
-#include "lua.hpp"
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
 
 namespace Rocket {
 namespace Core {

+ 1 - 1
Source/Core/Lua/RocketLua.cpp

@@ -1,5 +1,5 @@
 #include "precompiled.h"
-#include "Interpreter.h"
+#include <Rocket/Core/Lua/Interpreter.h>
 
 
 namespace Rocket {

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

@@ -26,8 +26,8 @@
     vect.magnitude
 
 */
-#include "lua.hpp"
-#include "LuaType.h"
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
 #include <Rocket/Core/Types.h>
 
 using Rocket::Core::Vector2f;

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

@@ -19,8 +19,8 @@
     vect.x
     vect.y
 */
-#include "lua.hpp"
-#include "LuaType.h"
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
 #include <Rocket/Core/Types.h>
 
 using Rocket::Core::Vector2i;

+ 0 - 7
Source/Core/Lua/lua.hpp

@@ -1,7 +0,0 @@
-//The standard Lua headers
-
-extern "C" {
-#include "lua.h"
-#include "lauxlib.h"
-#include "lualib.h"
-}

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

@@ -2,4 +2,4 @@
 #include <Rocket/Core/Core.h>
 #include <Rocket/Core/Debug.h>
 #include <Rocket/Controls/Controls.h>
-#include <Lua/LuaType.h>
+#include <Rocket/Core/Lua/LuaType.h>