Просмотр исходного кода

Created the ElementText type for Lua.

Finished out Document:CreateTextNode

Fixed the documentation for the basic types to use the .new syntax.
Nate Starkey 13 лет назад
Родитель
Сommit
a174747884

+ 8 - 0
Build/RocketLua.vcproj

@@ -375,6 +375,14 @@
 					RelativePath="..\Source\Core\Lua\ElementStyle.h"
 					>
 				</File>
+				<File
+					RelativePath="..\Source\Core\Lua\ElementText.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\Source\Core\Lua\ElementText.h"
+					>
+				</File>
 				<Filter
 					Name="Document"
 					>

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

@@ -3,11 +3,11 @@
 /*
     Declares Colourb in the Lua global namespace. It implements the below (examples using Lua syntax) :
 
-    Colourb(int red,int green,int blue,int alpha) creates a new Colourf (values must be bounded between 0 and 255 inclusive), 
+    Colourb.new(int red,int green,int blue,int alpha) creates a new Colourf (values must be bounded between 0 and 255 inclusive), 
     and gets deleted when Lua garbage collects
     
     everything after this will assume that you have a local variable named 'col', declared something similar to
-    local col = Colourb(0,15,3,255)
+    local col = Colourb.new(0,15,3,255)
 
     operators (the types that it can operate on are on the right):
     col == Colourb

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

@@ -2,11 +2,11 @@
 /*
     Declares Colourf in the Lua global namespace. It implements the below (examples using Lua syntax) :
 
-    Colourf(float red,float green,float blue,float alpha) creates a new Colourf (values must be bounded between 0 and 1 inclusive), 
+    Colourf.new(float red,float green,float blue,float alpha) creates a new Colourf (values must be bounded between 0 and 1 inclusive), 
     and gets deleted when Lua garbage collects
     
     everything after this will assume that you have a local variable named 'col', declared something similar to
-    local col = Colourf(0.1,0.5,0.25,1.0)
+    local col = Colourf.new(0.1,0.5,0.25,1.0)
 
     operators (the types that it can operate on are on the right):
     col == Colourf

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

@@ -56,7 +56,10 @@ int DocumentCreateElement(lua_State* L, Document* obj)
 int DocumentCreateTextNode(lua_State* L, Document* obj)
 {
     //need ElementText object first
-	return 0;
+    const char* text = luaL_checkstring(L,1);
+    ElementText* et = obj->CreateTextNode(text);
+    LuaType<ElementText>::push(L, et, false);
+	return 1;
 }
 
 

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

@@ -13,7 +13,7 @@
     noreturn Document:Hide()
     noreturn Document:Close()
     Element Document:CreateElement(string tag)
-    ElementText Document:CreateTextNode --NYI
+    ElementText Document:CreateTextNode(string text)
     
     //getters
     string Document.title

+ 45 - 0
Source/Core/Lua/ElementText.cpp

@@ -0,0 +1,45 @@
+#include "precompiled.h"
+#include "ElementText.h"
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+int ElementTextGetAttrtext(lua_State* L)
+{
+    ElementText* obj = LuaType<ElementText>::check(L, 1);
+    LUACHECKOBJ(obj);
+    lua_pushstring(L,obj->GetText().ToUTF8(String()).CString());
+    return 1;
+}
+
+int ElementTextSetAttrtext(lua_State* L)
+{
+    ElementText* obj = LuaType<ElementText>::check(L, 1);
+    LUACHECKOBJ(obj);
+    const char* text = luaL_checkstring(L,2);
+    obj->SetText(text);
+    return 0;
+}
+
+RegType<ElementText> ElementTextMethods[] =
+{
+    { NULL, NULL },
+};
+
+luaL_reg ElementTextGetters[] =
+{
+    LUAGETTER(ElementText,text)
+    { NULL, NULL },
+};
+
+luaL_reg ElementTextSetters[] =
+{
+    LUASETTER(ElementText,text)
+    { NULL, NULL },
+};
+
+
+}
+}
+}

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

@@ -0,0 +1,22 @@
+#pragma once
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/ElementText.h>
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+//will inherit from Element
+template<> void LuaType<ElementText>::extra_init(lua_State* L, int metatable_index);
+template<> bool LuaType<ElementText>::is_reference_counted();
+
+int ElementTextGetAttrtext(lua_State* L);
+int ElementTextSetAttrtext(lua_State* L);
+
+RegType<ElementText> ElementTextMethods[];
+luaL_reg ElementTextGetters[];
+luaL_reg ElementTextSetters[];
+
+}
+}
+}

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

@@ -14,6 +14,7 @@
 #include "Log.h"
 #include "Rocket.h"
 #include "Element.h"
+#include "ElementText.h"
 #include "Document.h"
 #include "Event.h"
 #include "Context.h"
@@ -44,6 +45,7 @@ LUATYPEDEFINE(Log)
 LUATYPEDEFINE(rocket)
 LUATYPEDEFINE(Element)
 LUATYPEDEFINE(Document)
+LUATYPEDEFINE(ElementText)
 LUATYPEDEFINE(ElementStyle)
 LUATYPEDEFINE(Event)
 LUATYPEDEFINE(Context)
@@ -68,6 +70,7 @@ template class LuaType<Log>;
 template class LuaType<rocket>;
 template class LuaType<Element>;
 template class LuaType<Document>;
+template class LuaType<ElementText>;
 template class LuaType<ElementStyle>;
 template class LuaType<Event>;
 template class LuaType<Context>;
@@ -87,6 +90,7 @@ template class LuaType<DataFormatter>;
 //reference counted types
 template<> bool LuaType<Element>::is_reference_counted() { return true; }
 template<> bool LuaType<Document>::is_reference_counted() { return true; }
+template<> bool LuaType<ElementText>::is_reference_counted() { return true; }
 template<> bool LuaType<Event>::is_reference_counted() { return true; }
 template<> bool LuaType<Context>::is_reference_counted() { return true; }
 template<> bool LuaType<ElementForm>::is_reference_counted() { return true; }
@@ -250,6 +254,13 @@ template<> void LuaType<Document>::extra_init(lua_State* L, int metatable_index)
     LuaType<Element>::_regfunctions(L,metatable_index,metatable_index - 1);
 }
 
+template<> void LuaType<ElementText>::extra_init(lua_State* L, int metatable_index)
+{
+    //inherit from Element
+    LuaType<Element>::extra_init(L,metatable_index);
+    LuaType<Element>::_regfunctions(L,metatable_index,metatable_index-1);
+}
+
 template<> void LuaType<ElementStyle>::extra_init(lua_State* L, int metatable_index)
 {
     lua_pushcfunction(L,ElementStyle__index);

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

@@ -8,6 +8,7 @@
     methods: 
     rocket.CreateContext(string name, Vector2i dimensions)
     rocket.LoadFontFace(string font_path)
+    rocket.RegisterTag(string tag, class) --NYI
     
     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

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

@@ -2,10 +2,10 @@
 /*
     Declares Vector2f in the Lua global namespace. It implements the below (examples using Lua syntax) :
 
-    Vector2f(float,float) creates a new Vector2f, and gets deleted when Lua garbage collects
+    Vector2f.new(float,float) creates a new Vector2f, and gets deleted when Lua garbage collects
     
     everything after this will assume that you have a local variable named 'vect', declared something similar to
-    local vect = Vector2f(3.5,2.3)
+    local vect = Vector2f.new(3.5,2.3)
     operators (the types that it can operate on are on the right):
     vect * float
     vect / float

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

@@ -5,7 +5,7 @@
     Vector2i(int,int) creates a new Vector2i, and gets deleted when Lua garbage collects
     
     everything after this will assume that you have a local variable named 'vect', declared something similar to
-    local vect = Vector2i(50,90)
+    local vect = Vector2i.new(50,90)
     operators (the types that it can operate on are on the right):
     vect * int
     vect / int