Переглянути джерело

Fixed Release compile errors.

Added a proxy table for Context.documents
Nate Starkey 13 роки тому
батько
коміт
345e60c0c5

+ 42 - 15
Build/RocketLua.vcproj

@@ -120,13 +120,15 @@
 			/>
 			<Tool
 				Name="VCCLCompilerTool"
-				Optimization="2"
+				Optimization="3"
+				InlineFunctionExpansion="0"
 				EnableIntrinsicFunctions="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;"
 				PreprocessorDefinitions="_WIN32,NDEBUG,RocketLua_EXPORTS"
 				RuntimeLibrary="2"
 				EnableFunctionLevelLinking="true"
-				UsePrecompiledHeader="1"
+				UsePrecompiledHeader="2"
 				PrecompiledHeaderThrough="precompiled.h"
 				WarningLevel="3"
 				DebugInformationFormat="3"
@@ -142,12 +144,17 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
+				LinkLibraryDependencies="true"
 				AdditionalDependencies="lua51.lib RocketCore.lib RocketControls.lib"
+				ShowProgress="0"
 				OutputFile="..\bin\$(ProjectName).dll"
+				AdditionalLibraryDirectories="$(SolutionDir)..\bin"
 				GenerateManifest="false"
+				EnableUAC="true"
 				GenerateDebugInformation="false"
 				OptimizeReferences="2"
 				EnableCOMDATFolding="2"
+				LinkTimeCodeGeneration="1"
 				ImportLibrary="$(TargetDir)$(TargetName).lib"
 				TargetMachine="1"
 			/>
@@ -292,14 +299,6 @@
 		<Filter
 			Name="Core"
 			>
-			<File
-				RelativePath="..\Source\Core\Lua\Context.cpp"
-				>
-			</File>
-			<File
-				RelativePath="..\Source\Core\Lua\Context.h"
-				>
-			</File>
 			<File
 				RelativePath="..\Source\Core\Lua\Interpreter.cpp"
 				>
@@ -321,7 +320,11 @@
 				>
 			</File>
 			<File
-				RelativePath="..\Source\Core\Lua\LuaType.cpp"
+				RelativePath="..\Include\Rocket\Core\Lua\LuaType.h"
+				>
+			</File>
+			<File
+				RelativePath="..\Source\Core\Lua\LuaType.inl"
 				>
 				<FileConfiguration
 					Name="Release|Win32"
@@ -332,10 +335,6 @@
 					/>
 				</FileConfiguration>
 			</File>
-			<File
-				RelativePath="..\Include\Rocket\Core\Lua\LuaType.h"
-				>
-			</File>
 			<File
 				RelativePath="..\Source\Core\Lua\LuaTypeTemplateSpec.inl"
 				>
@@ -440,6 +439,26 @@
 					>
 				</File>
 			</Filter>
+			<Filter
+				Name="Context"
+				>
+				<File
+					RelativePath="..\Source\Core\Lua\Context.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\Source\Core\Lua\Context.h"
+					>
+				</File>
+				<File
+					RelativePath="..\Source\Core\Lua\ContextDocumentsProxy.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\Source\Core\Lua\ContextDocumentsProxy.h"
+					>
+				</File>
+			</Filter>
 		</Filter>
 		<Filter
 			Name="Basic Types"
@@ -492,6 +511,14 @@
 					UsePrecompiledHeader="1"
 				/>
 			</FileConfiguration>
+			<FileConfiguration
+				Name="Release|Win32"
+				>
+				<Tool
+					Name="VCCLCompilerTool"
+					UsePrecompiledHeader="1"
+				/>
+			</FileConfiguration>
 		</File>
 		<File
 			RelativePath="..\Source\Core\Lua\precompiled.h"

+ 0 - 28
Build/Rocket_Prefix.pch

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

+ 1 - 1
Include/Rocket/Core/Lua/Interpreter.h

@@ -1,5 +1,5 @@
 #ifndef ROCKETCORELUAINTERPRETER_H
-#define ROCKETCORELUALUATYPE_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

+ 19 - 17
Include/Rocket/Core/Lua/LuaType.h

@@ -34,10 +34,10 @@ namespace Lua {
 
 //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; } \
+    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.h file
 #define LUATYPEDECLARE(type) \
@@ -71,43 +71,45 @@ 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);
+    static inline void Register(lua_State *L);
+    static inline int push(lua_State *L, T* obj, bool gc=false);
+    static inline T* check(lua_State* L, int narg);
 
     //for calling a C closure with upvalues
-    static int thunk(lua_State* L);
+    static inline int thunk(lua_State* L);
     //pointer to string
-    static void tostring(char* buff, void* obj);
+    static inline void tostring(char* buff, void* obj);
     //these are metamethods
     //.__gc
-    static int gc_T(lua_State* L);
+    static inline int gc_T(lua_State* L);
     //.__tostring
-    static int tostring_T(lua_State* L);
+    static inline int tostring_T(lua_State* L);
     //.__index
-    static int index(lua_State* L);
+    static inline int index(lua_State* L);
     //.__newindex
-    static 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  void extra_init(lua_State* L, int metatable_index);
+    static inline  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);
+    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 bool is_reference_counted();
+    static inline bool is_reference_counted();
 private:
     LuaType(); //hide constructor
 
 };
+
+
 }
 }
 }
 
-//#include "LuaType.inl"
+#include "LuaType.inl" //this feels so dirty, but it is the only way I got it to compile in release
 #endif

+ 5 - 19
Source/Core/Lua/Context.cpp

@@ -4,6 +4,7 @@
 #include <Rocket/Core/ElementDocument.h>
 #include <Rocket/Core/Factory.h>
 #include "LuaEventListener.h"
+#include "ContextDocumentsProxy.h"
 
 namespace Rocket {
 namespace Core {
@@ -147,25 +148,10 @@ int ContextGetAttrdimensions(lua_State* L)
 int ContextGetAttrdocuments(lua_State* L)
 {
     Context* cont = LuaType<Context>::check(L,1);
-    Element* root = cont->GetRootElement();
-
-    lua_newtable(L);
-    int tableindex = lua_gettop(L);
-    for(int i = 0; i < root->GetNumChildren(); i++)
-    {
-        Document* doc = root->GetChild(i)->GetOwnerDocument();
-        if(doc == NULL)
-            continue;
-
-        LuaType<Document>::push(L,doc);
-        lua_setfield(L, tableindex,doc->GetId().CString());
-
-        /* //is this a bad idea?
-        lua_pushinteger(L,i);
-        lua_setfield(L,tableindex,doc->GetId().CString());
-        */
-    }
-
+    LUACHECKOBJ(cont);
+    ContextDocumentsProxy* cdp = new ContextDocumentsProxy();
+    cdp->owner = cont;
+    LuaType<ContextDocumentsProxy>::push(L,cdp,true); //does get garbage collected (deleted)
     return 1;
 }
 

+ 71 - 0
Source/Core/Lua/ContextDocumentsProxy.cpp

@@ -0,0 +1,71 @@
+#include "precompiled.h"
+#include "ContextDocumentsProxy.h"
+#include <Rocket/Core/ElementDocument.h>
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+typedef Rocket::Core::ElementDocument Document;
+int ContextDocumentsProxy__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 type = lua_type(L,2);
+    if(type == LUA_TNUMBER || type == LUA_TSTRING) //only valid key types
+    {
+        ContextDocumentsProxy* proxy = LuaType<ContextDocumentsProxy>::check(L,1);
+        Document* ret = NULL;
+        if(type == LUA_TSTRING)
+            ret = proxy->owner->GetDocument(luaL_checkstring(L,2));
+        else
+            ret = proxy->owner->GetDocument(luaL_checkint(L,2));
+        LuaType<Document>::push(L,ret,false);
+        return 1;
+    }
+    else
+        return LuaType<ContextDocumentsProxy>::index(L);
+    
+}
+
+//method
+int ContextDocumentsProxyGetTable(lua_State* L, ContextDocumentsProxy* obj)
+{
+    Context* cont = obj->owner;
+    Element* root = cont->GetRootElement();
+
+    lua_newtable(L);
+    int tableindex = lua_gettop(L);
+    for(int i = 0; i < root->GetNumChildren(); i++)
+    {
+        Document* doc = root->GetChild(i)->GetOwnerDocument();
+        if(doc == NULL)
+            continue;
+
+        LuaType<Document>::push(L,doc);
+        lua_pushvalue(L,-1); //put it on the stack twice, since we assign it to 
+                                //both a string and integer index
+        lua_setfield(L, tableindex,doc->GetId().CString());
+        lua_rawseti(L,tableindex,i);
+    }
+    lua_settop(L,tableindex); //to make sure
+    return 1;
+}
+
+RegType<ContextDocumentsProxy> ContextDocumentsProxyMethods[] =
+{
+    LUAMETHOD(ContextDocumentsProxy,GetTable)
+    { NULL, NULL },
+};
+
+luaL_reg ContextDocumentsProxyGetters[] =
+{
+    { NULL, NULL },
+};
+
+luaL_reg ContextDocumentsProxySetters[] =
+{
+    { NULL, NULL },
+};
+
+}
+}
+}

+ 27 - 0
Source/Core/Lua/ContextDocumentsProxy.h

@@ -0,0 +1,27 @@
+#pragma once
+/*
+    A proxy table with key of string and int and a value of Document
+    Read only
+*/
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Context.h>
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+//where owner is the context that we should look information from
+struct ContextDocumentsProxy { Context* owner;  };
+
+template<> void LuaType<ContextDocumentsProxy>::extra_init(lua_State* L, int metatable_index);
+int ContextDocumentsProxy__index(lua_State* L);
+
+//method
+int ContextDocumentsProxyGetTable(lua_State* L, ContextDocumentsProxy* obj);
+
+RegType<ContextDocumentsProxy> ContextDocumentsProxyMethods[];
+luaL_reg ContextDocumentsProxyGetters[];
+luaL_reg ContextDocumentsProxySetters[];
+}
+}
+}

+ 0 - 5
Source/Core/Lua/ElementStyle.h

@@ -38,11 +38,6 @@
     However, the table returned from style:GetTable() is read only. Whatever changes you
     make to that table will not be saved to the 'style' object. To do that, just do whatever
     operation you were going to on the table before, but do it on the 'style' object instead.
-
-
-
-    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 <Rocket/Core/Lua/LuaType.h>
 #include <Rocket/Core/Lua/lua.hpp>

+ 0 - 1
Source/Core/Lua/LuaType.cpp → Source/Core/Lua/LuaType.inl

@@ -6,7 +6,6 @@
 namespace Rocket {
 namespace Core {
 namespace Lua {
-
 template<typename T>
 void LuaType<T>::Register(lua_State* L)
 {

+ 9 - 0
Source/Core/Lua/LuaTypeTemplateSpec.inl

@@ -29,6 +29,7 @@
 #include "ElementTabSet.h"
 #include "DataSource.h"
 #include "DataFormatter.h"
+#include "ContextDocumentsProxy.h"
 
 
 
@@ -60,6 +61,7 @@ LUATYPEDEFINE(ElementDataGridRow)
 LUATYPEDEFINE(ElementTabSet)
 LUATYPEDEFINE(DataSource)
 LUATYPEDEFINE(DataFormatter)
+LUATYPEDEFINE(ContextDocumentsProxy)
 
 
 template class LuaType<Colourb>;
@@ -85,6 +87,7 @@ template class LuaType<ElementDataGridRow>;
 template class LuaType<ElementTabSet>;
 template class LuaType<DataSource>;
 template class LuaType<DataFormatter>;
+template class LuaType<ContextDocumentsProxy>;
 
 
 //reference counted types
@@ -372,6 +375,12 @@ template<> void LuaType<DataFormatter>::extra_init(lua_State* L, int metatable_i
     return;
 }
 
+template<> void LuaType<ContextDocumentsProxy>::extra_init(lua_State* L, int metatable_index)
+{
+    lua_pushcfunction(L,ContextDocumentsProxy__index);
+    lua_setfield(L,metatable_index,"__index");
+}
+
 }
 }
 }