예제 #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
			"            );
        }
예제 #2
0
        } // func ExecuteScriptLoop

        private static long ExecuteLuaIntf(int i, string sScript)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            using (LuaInterface.Lua lua = new LuaInterface.Lua())
            {
                lua.RegisterFunction("test", null, typeof(Program).GetMethod("LuaTest"));
                lua.RegisterFunction("echo", null, typeof(Program).GetMethod("LuaEcho"));
                DebugOut("LuaIntf", i, lua.DoString(sScript, "test"));
            }
            return(sw.ElapsedMilliseconds);
        } // proc ExecuteLuaIntf
예제 #3
0
        private static double ExecuteLuaIntfCompiled(string sScript, int iLoops)
        {
            using (LuaInterface.Lua lua = new LuaInterface.Lua())
            {
                lua.RegisterFunction("test", null, typeof(Program).GetMethod("LuaTest"));
                lua.RegisterFunction("echo", null, typeof(Program).GetMethod("LuaEcho"));
                LuaInterface.LuaFunction f = lua.LoadString(sScript, "test");

                Stopwatch sw = new Stopwatch();
                sw.Start();

                for (int i = 0; i < iLoops; i++)
                {
                    DebugOut("LuaIntf-C", i, f.Call());
                }

                return(sw.ElapsedMilliseconds / (double)iLoops);
            }
        }
예제 #4
0
        public static void RegisterNewMethod(Object target)
        {
            Type type = target.GetType();

            foreach (MethodInfo info in type.GetMethods())
            {
                foreach (Attribute att in Attribute.GetCustomAttributes(info))
                {
                    if (att is AI.Scripting.AttributScriptMethod)
                    {
                        lua.RegisterFunction((att as AI.Scripting.AttributScriptMethod).GetMethodName(), target, info);
                    }
                }
            }
        }
예제 #5
0
        public Main()
        {
            Lua = new LuaInterface.Lua();

            Lua.DoFile(AppDomain.CurrentDomain.BaseDirectory + "Lua\\TrigEditPlus\\constparser.lua");
            Lua.DoFile(AppDomain.CurrentDomain.BaseDirectory + "Lua\\TrigEditPlus\\condition.lua");
            Lua.DoFile(AppDomain.CurrentDomain.BaseDirectory + "Lua\\TrigEditPlus\\action.lua");
            Lua.DoFile(AppDomain.CurrentDomain.BaseDirectory + "Lua\\TrigEditPlus\\briefing.lua");
            Lua.DoFile(AppDomain.CurrentDomain.BaseDirectory + "Lua\\TrigEditPlus\\tool.lua");


            Lua.RegisterFunction("msgbox", this, this.GetType().GetMethod("MsgBox"));



            Lua.RegisterFunction("Trigger", this, this.GetType().GetMethod("Triggerinterpreter"));
            Lua.RegisterFunction("ParseString", this, this.GetType().GetMethod("ParseString"));
            Lua.RegisterFunction("ParseLocation", this, this.GetType().GetMethod("ParseLocation"));
            Lua.RegisterFunction("ParseUPRP", this, this.GetType().GetMethod("ParseUPRP"));
            Lua.RegisterFunction("ParseUnit", this, this.GetType().GetMethod("ParseUnit"));
            Lua.RegisterFunction("ParseSwitchName", this, this.GetType().GetMethod("ParseSwitchName"));
        }
예제 #6
0
파일: Program.cs 프로젝트: edisonh/neolua
    private static double ExecuteLuaIntfCompiled(string sScript, int iLoops)
    {
      using (LuaInterface.Lua lua = new LuaInterface.Lua())
      {
        lua.RegisterFunction("test", null, typeof(Program).GetMethod("LuaTest"));
        lua.RegisterFunction("echo", null, typeof(Program).GetMethod("LuaEcho"));
        LuaInterface.LuaFunction f = lua.LoadString(sScript, "test");
        
        Stopwatch sw = new Stopwatch();
        sw.Start();

        for (int i = 0; i < iLoops; i++)
          DebugOut("LuaIntf-C", i, f.Call());

        return sw.ElapsedMilliseconds / (double)iLoops;
      }
    }
예제 #7
0
파일: Program.cs 프로젝트: edisonh/neolua
    } // func ExecuteScriptLoop

    private static long ExecuteLuaIntf(int i, string sScript)
    {
      Stopwatch sw = new Stopwatch();
      sw.Start();
      using (LuaInterface.Lua lua = new LuaInterface.Lua())
      {
        lua.RegisterFunction("test", null, typeof(Program).GetMethod("LuaTest"));
        lua.RegisterFunction("echo", null, typeof(Program).GetMethod("LuaEcho"));
        DebugOut("LuaIntf", i, lua.DoString(sScript, "test"));
      }
      return sw.ElapsedMilliseconds;
    } // proc ExecuteLuaIntf
예제 #8
0
 /// <summary>
 /// This method is called to set an function to be accessible by the functionName for the script once Executed.
 /// </summary>
 /// <param name="functionName">The desired alias for the function at script level</param>
 /// <param name="functionPointer">The delegate for the function to use at script</param>
 public void SetFunction(string functionName, Delegate functionPointer)
 {
     scriptEngine.RegisterFunction(functionName, functionPointer.Target, functionPointer.Method);
 }