Esempio n. 1
0
        public void ExposeLibraries()
        {
            lua.NewTable("Console");
            lua.RegisterFunction("Console.Write", null, typeof(System.Console).GetMethod("Write", new Type[] { typeof(string) }));
            lua.RegisterFunction("Console.WriteLine", null, typeof(System.Console).GetMethod("WriteLine", new Type[] { typeof(string) }));

            lua.NewTable("Mouse");
            lua.RegisterFunction("Mouse.GetPos", null, typeof(LuaMouse).GetMethod("GetPos"));

            // Register GUI creation functions
            lua.RegisterFunction("_CreateFrame", null, typeof(LuaGUI).GetMethod("CreateFrame", new Type[] { }));
            lua.RegisterFunction("_CreateFrameAsChild", null, typeof(LuaGUI).GetMethod("CreateFrame", new Type[] { typeof(GUI.Frame) }));
            lua.RegisterFunction("_CreateButton", null, typeof(LuaGUI).GetMethod("CreateButton", new Type[] { }));
            lua.RegisterFunction("_CreateButtonAsChild", null, typeof(LuaGUI).GetMethod("CreateButton", new Type[] { typeof(GUI.Frame) }));
            lua.RegisterFunction("_CreateText", null, typeof(LuaGUI).GetMethod("CreateText", new Type[] { }));
            lua.RegisterFunction("_CreateTextAsChild", null, typeof(LuaGUI).GetMethod("CreateText", new Type[] { typeof(GUI.Frame) }));

            lua.NewTable("GUI");

            /*
             *	Because Lua can't dynamically call overloads of registered functions, a generic Lua function needs to do the decision making.
             *	This way we can also dynamically create different frame classes with the same function.
             */
            lua.DoString(@"
				CreateFrame = function(frameType, parent)
					frameType = string.lower(frameType):gsub('^%l', string.upper)
					if (parent == nil) then
						return _G['_Create' .. frameType]()
					else
						return _G['_Create' .. frameType .. 'AsChild'](parent)
					end
				end
			"            );
        }