Browse Source

Fixed the rocket global variable that I broke with the last commit.

I did not test the previous commit due to it being 4 am, however this has been tested.

I have also added the key_modifier enum from Input::KeyModifier, which wasn't implemented in Python.
Nate Starkey 13 years ago
parent
commit
ae25e4cc4a
3 changed files with 30 additions and 11 deletions
  1. 1 4
      Source/Core/Lua/Interpreter.cpp
  2. 26 6
      Source/Core/Lua/Rocket.cpp
  3. 3 1
      Source/Core/Lua/Rocket.h

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

@@ -62,8 +62,6 @@ namespace Lua {
 lua_State* Interpreter::_L = NULL;
 //typedefs for nicer Lua names
 typedef Rocket::Core::ElementDocument Document;
-//global variable 
-LuaRocket rocket = LuaRocket();
 
 void Interpreter::Startup()
 {
@@ -99,8 +97,7 @@ void Interpreter::RegisterCoreTypes(lua_State* L)
     LuaType<RocketContextsProxy>::Register(L);
     OverrideLuaGlobalFunctions(L);
     //push the global variable "rocket" to use the "Rocket" methods
-    LuaType<LuaRocket>::push(L,&rocket,false);
-    lua_setglobal(L,"rocket");
+    LuaRocketPushrocketGlobal(L);
 }
 
 

+ 26 - 6
Source/Core/Lua/Rocket.cpp

@@ -36,17 +36,24 @@
 namespace Rocket {
 namespace Core {
 namespace Lua {
+#define ROCKETLUA_INPUTENUM(keyident,tbl) lua_pushinteger(L,Input::KI_##keyident); lua_setfield(L,(tbl),#keyident);
+#define ROCKETLUA_INPUTMODIFIERENUM(keymod,tbl) lua_pushinteger(L,Input::KM_##keymod); lua_setfield(L,(tbl),#keymod);
 
-template<> void ExtraInit<LuaRocket>(lua_State* L, int metatable_index)
+
+void LuaRocketPushrocketGlobal(lua_State* L)
 {
-    //because of the way LuaType::Register is done, we know that the methods table is directly
-    //before the metatable 
-    int method_index = metatable_index - 1;
+    lua_newtable(L);
     LuaRocketEnumkey_identifier(L);
-    lua_setfield(L,method_index,"key_identifier");
-    return;
+    lua_setfield(L,-2,"key_identifier");
+    LuaRocketEnumkey_modifier(L);
+    lua_setfield(L,-2,"key_modifier");
+    luaL_getmetatable(L,GetTClassName<LuaRocket>());
+    lua_setmetatable(L,-2); //metatable of the new table = LuaRocket
+    lua_setglobal(L,"rocket");
 }
 
+template<> void ExtraInit<LuaRocket>(lua_State* L, int metatable_index){ return; }
+
 int LuaRocketCreateContext(lua_State* L, LuaRocket* obj)
 {
     const char* name = luaL_checkstring(L,1);
@@ -267,6 +274,19 @@ void LuaRocketEnumkey_identifier(lua_State* L)
 	ROCKETLUA_INPUTENUM(OEM_CLEAR,tbl)
 }
 
+void LuaRocketEnumkey_modifier(lua_State* L)
+{
+    lua_newtable(L);
+    int tbl = lua_gettop(L);
+    ROCKETLUA_INPUTMODIFIERENUM(CTRL,tbl)
+    ROCKETLUA_INPUTMODIFIERENUM(SHIFT,tbl)
+    ROCKETLUA_INPUTMODIFIERENUM(ALT,tbl)
+    ROCKETLUA_INPUTMODIFIERENUM(META,tbl)
+    ROCKETLUA_INPUTMODIFIERENUM(CAPSLOCK,tbl)
+    ROCKETLUA_INPUTMODIFIERENUM(NUMLOCK,tbl)
+    ROCKETLUA_INPUTMODIFIERENUM(SCROLLLOCK,tbl)
+}
+
 
 RegType<LuaRocket> LuaRocketMethods[] = 
 {

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

@@ -34,11 +34,12 @@
 namespace Rocket {
 namespace Core {
 namespace Lua {
-#define ROCKETLUA_INPUTENUM(keyident,tbl) lua_pushinteger(L,Input::KI_##keyident); lua_setfield(L,(tbl),#keyident);
 
 //just need a class to take up a type name, and a single object to be able to be pushed to Lua
 class LuaRocket { int to_remove_warning; }; //instance of object defined in Interpreter.cpp
 
+void LuaRocketPushrocketGlobal(lua_State* L);
+
 template<> void ExtraInit<LuaRocket>(lua_State* L, int metatable_index);
 int LuaRocketCreateContext(lua_State* L, LuaRocket* obj);
 int LuaRocketLoadFontFace(lua_State* L, LuaRocket* obj);
@@ -47,6 +48,7 @@ int LuaRocketRegisterTag(lua_State* L, LuaRocket* obj);
 int LuaRocketGetAttrcontexts(lua_State* L);
 
 void LuaRocketEnumkey_identifier(lua_State* L);
+void LuaRocketEnumkey_modifier(lua_State* L);
 
 RegType<LuaRocket> LuaRocketMethods[];
 luaL_reg LuaRocketGetters[];