Browse Source

Added some documentation for the types I have already implemented.

Implemented some of the Context methods that I couldn't do before.
Nate Starkey 13 years ago
parent
commit
0ad3eacb7a

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

@@ -1,10 +1,12 @@
 #include "precompiled.h"
 #include "precompiled.h"
 #include "Context.h"
 #include "Context.h"
 #include <Rocket/Core/Context.h>
 #include <Rocket/Core/Context.h>
+#include <Rocket/Core/ElementDocument.h>
 
 
 namespace Rocket {
 namespace Rocket {
 namespace Core {
 namespace Core {
 namespace Lua {
 namespace Lua {
+typedef Rocket::Core::ElementDocument Document;
 
 
 //methods
 //methods
 int ContextAddEventListener(lua_State* L, Context* obj)
 int ContextAddEventListener(lua_State* L, Context* obj)
@@ -15,35 +17,43 @@ int ContextAddEventListener(lua_State* L, Context* obj)
 
 
 int ContextAddMouseCursor(lua_State* L, Context* obj)
 int ContextAddMouseCursor(lua_State* L, Context* obj)
 {
 {
-    return 1;   
+    Document* cursor_doc = LuaType<Document>::check(L,1);
+    obj->AddMouseCursor(cursor_doc);
+    return 0;   
 }
 }
 
 
 int ContextCreateDocument(lua_State* L, Context* obj)
 int ContextCreateDocument(lua_State* L, Context* obj)
 {
 {
-    const char* tag = luaL_checkstring(L,1);
-
+    const char* tag;
+    if(lua_gettop(L) < 1)
+        tag = "body";
+    else
+        tag = luaL_checkstring(L,1);
+    Document* doc = obj->CreateDocument(tag);
+    LuaType<Document>::push(L,doc,true);
     return 1;
     return 1;
 }
 }
 
 
 int ContextLoadDocument(lua_State* L, Context* obj)
 int ContextLoadDocument(lua_State* L, Context* obj)
 {
 {
     const char* path = luaL_checkstring(L,1);
     const char* path = luaL_checkstring(L,1);
-    
+    Document* doc = obj->LoadDocument(path);
+    LuaType<Document>::push(L,doc,true);
     return 1;
     return 1;
 }
 }
 
 
 int ContextLoadMouseCursor(lua_State* L, Context* obj)
 int ContextLoadMouseCursor(lua_State* L, Context* obj)
 {
 {
     const char* path = luaL_checkstring(L,1);
     const char* path = luaL_checkstring(L,1);
-    ElementDocument* doc = obj->LoadMouseCursor(path);
-    //LuaType<Document>::push(L,doc);
+    Document* doc = obj->LoadMouseCursor(path);
+    LuaType<Document>::push(L,doc);
     return 1;
     return 1;
 }
 }
 
 
 int ContextRender(lua_State* L, Context* obj)
 int ContextRender(lua_State* L, Context* obj)
 {
 {
-    obj->Render();
-    return 0;
+    lua_pushboolean(L,obj->Render());
+    return 1;
 }
 }
 
 
 int ContextShowMouseCursor(lua_State* L, Context* obj)
 int ContextShowMouseCursor(lua_State* L, Context* obj)
@@ -67,8 +77,8 @@ int ContextUnloadAllMouseCursors(lua_State* L, Context* obj)
 
 
 int ContextUnloadDocument(lua_State* L, Context* obj)
 int ContextUnloadDocument(lua_State* L, Context* obj)
 {
 {
-    //Document* doc = LuaType<Document>::check(L,1);
-    //obj->UnloadDocument(doc);
+    Document* doc = LuaType<Document>::check(L,1);
+    obj->UnloadDocument(doc);
     return 0;
     return 0;
 }
 }
 
 
@@ -81,8 +91,8 @@ int ContextUnloadMouseCursor(lua_State* L, Context* obj)
 
 
 int ContextUpdate(lua_State* L, Context* obj)
 int ContextUpdate(lua_State* L, Context* obj)
 {
 {
-    obj->Update();
-    return 0;
+    lua_pushboolean(L,obj->Update());
+    return 1;
 }
 }
 
 
 
 
@@ -93,11 +103,11 @@ int ContextGetAttrdimensions(lua_State* L)
     const Vector2i* dim = &cont->GetDimensions();
     const Vector2i* dim = &cont->GetDimensions();
     //const_cast-ing so that the user can do dimensions.x = 3 and it will actually change the dimensions
     //const_cast-ing so that the user can do dimensions.x = 3 and it will actually change the dimensions
     //of the context
     //of the context
-    LuaType<Vector2i>::push(L,const_cast<Vector2i*>(dim),true);
+    LuaType<Vector2i>::push(L,const_cast<Vector2i*>(dim));
     return 1;
     return 1;
 }
 }
 
 
-//returns a table of everything. Not exactly the most efficient way of doing it.
+//returns a table of everything
 int ContextGetAttrdocuments(lua_State* L)
 int ContextGetAttrdocuments(lua_State* L)
 {
 {
     Context* cont = LuaType<Context>::check(L,1);
     Context* cont = LuaType<Context>::check(L,1);
@@ -107,15 +117,17 @@ int ContextGetAttrdocuments(lua_State* L)
     int tableindex = lua_gettop(L);
     int tableindex = lua_gettop(L);
     for(int i = 0; i < root->GetNumChildren(); i++)
     for(int i = 0; i < root->GetNumChildren(); i++)
     {
     {
-        ElementDocument* doc = root->GetChild(i)->GetOwnerDocument();
+        Document* doc = root->GetChild(i)->GetOwnerDocument();
         if(doc == NULL)
         if(doc == NULL)
             continue;
             continue;
 
 
-        //LuaType<Document>::push(L,doc);
+        LuaType<Document>::push(L,doc);
         lua_setfield(L, tableindex,doc->GetId().CString());
         lua_setfield(L, tableindex,doc->GetId().CString());
 
 
+        /* //is this a bad idea?
         lua_pushinteger(L,i);
         lua_pushinteger(L,i);
         lua_setfield(L,tableindex,doc->GetId().CString());
         lua_setfield(L,tableindex,doc->GetId().CString());
+        */
     }
     }
 
 
     return 1;
     return 1;
@@ -124,14 +136,14 @@ int ContextGetAttrdocuments(lua_State* L)
 int ContextGetAttrfocus_element(lua_State* L)
 int ContextGetAttrfocus_element(lua_State* L)
 {
 {
     Context* cont = LuaType<Context>::check(L,1);
     Context* cont = LuaType<Context>::check(L,1);
-    //LuaType<Element>::push(L,cont->GetFocusElement());
+    LuaType<Element>::push(L,cont->GetFocusElement());
     return 1;
     return 1;
 }
 }
 
 
 int ContextGetAttrhover_element(lua_State* L)
 int ContextGetAttrhover_element(lua_State* L)
 {
 {
     Context* cont = LuaType<Context>::check(L,1);
     Context* cont = LuaType<Context>::check(L,1);
-    //LuaType<Element>::push(L,cont->GetHoverElement());
+    LuaType<Element>::push(L,cont->GetHoverElement());
     return 1;
     return 1;
 }
 }
 
 
@@ -146,7 +158,7 @@ int ContextGetAttrname(lua_State* L)
 int ContextGetAttrroot_element(lua_State* L)
 int ContextGetAttrroot_element(lua_State* L)
 {
 {
     Context* cont = LuaType<Context>::check(L,1);
     Context* cont = LuaType<Context>::check(L,1);
-    //LuaType<Element>::push(L,cont->GetRootElement());
+    LuaType<Element>::push(L,cont->GetRootElement());
     return 1;
     return 1;
 }
 }
 
 

+ 29 - 0
Source/Core/Lua/Context.h

@@ -1,4 +1,33 @@
 #pragma once
 #pragma once
+/*
+    This defines a Context type in the Lua global namespace
+
+    //methods
+    Context:AddEventListener --NYI
+    noreturn Context:AddMouseCursor(Document cursor_document)
+    Document Context:CreateDocument([string tag]) --tag defaults to "body"
+    Document Context:LoadDocument(string path)
+    Document Context:LoadMouseCursor(string path)
+    bool Context:Render
+    noreturn Context:ShowMouseCursor(bool show)
+    noreturn Context:UnloadAllDocuments()
+    noreturn Context:UnloadAllMouseCursors()
+    noreturn Context:UnloadDocument(Document doc)
+    noreturn Context:UnloadMouseCursor(string name)
+    bool Context:Update()
+
+    //getters
+    Vector2i Context.dimensions
+    {} where key=string id,value=Document Context.documents
+    Element Context.focus_element
+    Element Context.hover_element
+    string Context.name
+    Element Context.root_element
+
+    //setters
+    Context.dimensions = Vector2i
+
+*/
 #include "LuaType.h"
 #include "LuaType.h"
 #include "lua.hpp"
 #include "lua.hpp"
 
 

+ 23 - 0
Source/Core/Lua/Document.h

@@ -1,4 +1,27 @@
 #pragma once
 #pragma once
+/*
+    This defines the Document type in the Lua global namespace
+
+    It inherits from Element, so check the documentation for Element.h to
+    see what other functions you can call from a Document object. Document
+    specific things are below
+
+    //methods
+    noreturn Document:PullToFront()
+    noreturn Document:PushToBack()
+    noreturn Document:Show(int flag)
+    noreturn Document:Hide()
+    noreturn Document:Close()
+    Element Document:CreateElement(string tag)
+    ElementText Document:CreateTextNode --NYI
+    
+    //getters
+    string Document.title
+    Context Document.context
+
+    //setter
+    Document.title = string
+*/
 #include "lua.hpp"
 #include "lua.hpp"
 #include "LuaType.h"
 #include "LuaType.h"
 #include <Rocket/Core/ElementDocument.h>
 #include <Rocket/Core/ElementDocument.h>

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

@@ -48,7 +48,7 @@ int ElementDispatchEvent(lua_State* L, Element* obj)
     const char* event = luaL_checkstring(L,1);
     const char* event = luaL_checkstring(L,1);
     Dictionary params;
     Dictionary params;
     lua_pushnil(L); //becauase lua_next pops a key from the stack first, we don't want to pop the table
     lua_pushnil(L); //becauase lua_next pops a key from the stack first, we don't want to pop the table
-    while(lua_next != 0)
+    while(lua_next(L,2) != 0)
     {
     {
         //[-1] is value, [-2] is key
         //[-1] is value, [-2] is key
         int type = lua_type(L,-1);
         int type = lua_type(L,-1);

+ 71 - 0
Source/Core/Lua/Element.h

@@ -1,4 +1,75 @@
 #pragma once
 #pragma once
+/*
+    This defines the Element type in the Lua global namespace
+
+    A few classes "inherit" from Element, such as Document. Document will call
+    LuaType<Element>::_regfunctions to put all of these functions in its own table, and
+    will be used with the same syntax except it will be from a Document object. It isn't true
+    inheritance, but it is a fair enough emulation. Any functions in the child class that have
+    the same name as the function in Element will overwrite the one in Element.
+
+    Here, I will be showing usage of the API, and it will show the type names rather than the regular
+    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:AppendChild(Element child)
+    noreturn Element:Blur()
+    noreturn Element:Click()
+    noreturn Element:DispatchEvent(string event, {} params) --in params, keys have to be a string and value can be number,bool,string,userdata,lightuserdata
+    noreturn Element:Focus()
+    [int,float,Colourb,Colourf,string,Vector2f,lightuserdata] Element:GetAttribute(string name) --will return one of those types
+    Element Element:GetElementById(string id)
+    {}of elements Element:GetElementsByTagName(string tag)
+    bool Element:HasAttribute(string name)
+    bool Element:HasChildNodes()
+    noreturn Element:InsertBefore(Element child,Element adjacent)
+    bool Element:IsClassSet(string name)
+    noreturn Element:RemoveAttribute(string name)
+    bool Element:RemoveChild(Element child)
+    bool Element:ReplaceChild(Element inserted,Element replaced)
+    noreturn Element:ScrollIntoView(bool align_with_top)
+    noreturn Element:SetAttribute(string name,string value)
+    noreturn Element:SetClass(string name, bool activate)
+
+
+    //getters accessed by the period syntax from an element object
+    --for attributes, if you save it to a local/global variable and try to modify that variable,
+    --your changes will not be saved. You will have to use Element:SetAttribute
+    {} of [key=string,value=int,float,Colourb,Colourf,string,Vector2f,lightuserdata] Element.attributes
+    {} of Element Element.child_nodes
+    string Element.class_name
+    float Element.client_left
+    float Element.client_height
+    float Element.client_top
+    float Element.client_width
+    Element Element.first_child
+    string Element.id
+    string Element.inner_rml
+    Element Element.last_child
+    Element Element.next_sibling
+    float Element.offset_height
+    float Element.offset_left
+    Element Element.offset_parent
+    float Element.offset_top
+    float Element.offset_width
+    Document Element.owner_document
+    Element Element.parent_nod
+    Element Element.previous_sibling
+    float Element.scroll_height
+    float Element.scroll_left
+    float Element.scroll_top
+    float Element.scroll_width
+    ElementStyle Element.style --see ElementStyle.h documentation
+    string Element.tag_name
+
+    //setters to be used with a dot syntax on an Element object
+    Element.class_name = string
+    Element.id = string
+    Element.inner_rml = string
+    Element.scroll_left = float
+    Element.scroll_top = float  
+*/
 #include "LuaType.h"
 #include "LuaType.h"
 #include "lua.hpp"
 #include "lua.hpp"
 #include <Rocket/Core/Element.h>
 #include <Rocket/Core/Element.h>

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

@@ -2,8 +2,19 @@
 #include "lua.hpp"
 #include "lua.hpp"
 
 
 /*
 /*
-    Declares "Log" in the global Lua namespace. Lua usage example:
-    Log(Log.logtype.always, "Hello World")
+    Declares "Log" in the global Lua namespace.
+
+    //It is not nessecarry to call it on a "Log" object, just
+    //call it on the Log table
+    Log(logtype type, string message)
+
+    where logtype is defined in Log.logtype, and can be:
+    logtype.always
+    logtype.error
+    logtype.warning
+    logtype.info
+    logtype.debug
+    and they have the same value as the C++ Log::Type of the same name
 */
 */
 
 
 namespace Rocket {
 namespace Rocket {

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

@@ -22,7 +22,7 @@ namespace Core {
 namespace Lua {
 namespace Lua {
 
 
 //just need a class to take up a type name
 //just need a class to take up a type name
-class rocket {};
+class rocket { int to_remove_warning; };
 
 
 template<> void LuaType<rocket>::extra_init(lua_State* L, int metatable_index);
 template<> void LuaType<rocket>::extra_init(lua_State* L, int metatable_index);
 int rocketCreateContext(lua_State* L);
 int rocketCreateContext(lua_State* L);