当前位置: 首页>>代码示例>>C#>>正文


C# Lua.GetFunction方法代码示例

本文整理汇总了C#中Lua.GetFunction方法的典型用法代码示例。如果您正苦于以下问题:C# Lua.GetFunction方法的具体用法?C# Lua.GetFunction怎么用?C# Lua.GetFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lua的用法示例。


在下文中一共展示了Lua.GetFunction方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

    void Start()
    {
        L = new Lua();
        L.DoString(luaText.text);
        object[] v;

        v = L.GetFunction("getCostStaminaByLevel").Call(4,4);
        dumpResult("getCostStaminaByLevel",v);

        //
        v = L.GetFunction("rewardGold").Call(4,4,21);
        dumpResult("rewardGold",v);
        //
        v = L.GetFunction("getGearLevelUpCostSilver").Call(1,2,100,100);
        dumpResult("getGearLevelUpCostSilver",v);
        //		v = L.GetFunction("getPracticeLimitAtk").Call(4);
        //		dumpResult("getPracticeLimitAtk",v);
        //		v = L.GetFunction("getPracticeLimitDef").Call(4);
        //		dumpResult("getPracticeLimitDef",v);
        //		v = L.GetFunction("getPracticeLimitSp").Call(5);
        //		dumpResult("getPracticeLimitSp",v);
        //		v = L.GetFunction("getSummonCostCash").Call("b");
        //		dumpResult("getSummonCostCash",v);
        //
        //
        //
        //		v = L.GetFunction("getTrumpFuseProvideXp").Call(4,2);
        //		dumpResult("getTrumpFuseProvideXp",v);
        //
        //		v = L.GetFunction("getEquipForgeLvLimit").Call(3);
        //		dumpResult("getEquipForgeLvLimit",v);
        //
        //		v = L.GetFunction("getEquipForgeCostCoins").Call(2,11);
        //		dumpResult("getEquipForgeCostCoins",v);
        //
        //		v = L.GetFunction("getEquipForgeCostEquipClips").Call(2);
        //		dumpResult("getEquipForgeCostEquipClips",v);
        //
        //		v = L.GetFunction("getPracticeLimitHp").Call(2);
        //		dumpResult("getPracticeLimitHp",v);
        //		v = L.GetFunction("getPracticeLimitAtk").Call(2);
        //		dumpResult("getPracticeLimitAtk",v);
        //		v = L.GetFunction("getPracticeLimitDef").Call(2);
        //		dumpResult("getPracticeLimitDef",v);
        //		v = L.GetFunction("getPracticeLimitSp").Call(2);
        //		dumpResult("getPracticeLimitSp",v);
    }
开发者ID:rogeryuan99,项目名称:Hello,代码行数:47,代码来源:LuaTest.cs

示例2: CallGlobalFunctionOneArg

 public void CallGlobalFunctionOneArg()
 {
     using (Lua lua = new Lua())
     {
         lua.DoString("a=2\nfunction f(x)\na=a+x\nend");
         lua.GetFunction("f").Call(1);
         double num = lua.GetNumber("a");
         //Console.WriteLine("a="+num);
         Assert.Equal(num, 3d);
     }
 }
开发者ID:h34tn,项目名称:luainterface,代码行数:11,代码来源:LuaTests.cs

示例3: Start

	void Start () {
        lua = new Lua();
        // 加载定义脚本
        lua.DoString(CommonLuaScript.text);
        lua.DoString(BindLuaScript.text);

        lua["gameObject"] = gameObject;
        lua["transform"] = transform;

        LuaFunction luaFunc = lua.GetFunction("test");
        luaFunc.Call();

	}
开发者ID:Henry-T,项目名称:UnityPG,代码行数:13,代码来源:LuaScript.cs

示例4: Start

            public bool Start()
            {
                lock (FLock)
                {
                    FLua = CreateLuaVM();

                    FLua.DoFile(FBotDesc.Script);

                    FLua.NewTable("BotEvent");
                    FLuaEvent = FLua.GetTable("BotEvent");
                    FLuaEventHandler = FLua.GetFunction("OnEvent");

                    BotEvent_Start startEvent = new BotEvent_Start(FBotId);

                    EmmitBotEvent(startEvent);

                    return startEvent.ret_val;
                }
            }
开发者ID:lythm,项目名称:orb3d,代码行数:19,代码来源:Bot.cs

示例5: Main

        /*
         * Sample test script that shows some of the capabilities of
         * LuaInterface
         */
        public static void Main()
        {
            Console.WriteLine("Starting interpreter...");
            var l = new Lua();

            // Pause so we can connect with the debugger
            // Thread.Sleep(30000);
            Console.WriteLine("Reading test.lua file...");
            l.DoFile("test.lua");
            double width = l.GetNumber("width");
            double height = l.GetNumber("height");
            string message = l.GetString("message");
            double color_r = l.GetNumber("color.r");
            double color_g = l.GetNumber("color.g");
            double color_b = l.GetNumber("color.b");
            Console.WriteLine("Printing values of global variables width, height and message...");
            Console.WriteLine("width: " + width);
            Console.WriteLine("height: " + height);
            Console.WriteLine("message: " + message);
            Console.WriteLine("Printing values of the 'color' table's fields...");
            Console.WriteLine("color.r: " + color_r);
            Console.WriteLine("color.g: " + color_g);
            Console.WriteLine("color.b: " + color_b);
            width = 150;
            Console.WriteLine("Changing width's value and calling Lua function print to show it...");
            l["width"] = width;
            l.GetFunction("print").Call(width);
            message = "LuaNet Interface Test";
            Console.WriteLine("Changing message's value and calling Lua function print to show it...");
            l["message"] = message;
            l.GetFunction("print").Call(message);
            color_r = 30;
            color_g = 10;
            color_b = 200;
            Console.WriteLine("Changing color's fields' values and calling Lua function print to show it...");
            l["color.r"] = color_r;
            l["color.g"] = color_g;
            l["color.b"] = color_b;
            l.DoString("print(color.r,color.g,color.b)");
            Console.WriteLine("Printing values of the tree table's fields...");
            double leaf1 = l.GetNumber("tree.branch1.leaf1");
            string leaf2 = l.GetString("tree.branch1.leaf2");
            string leaf3 = l.GetString("tree.leaf3");
            Console.WriteLine("leaf1: " + leaf1);
            Console.WriteLine("leaf2: " + leaf2);
            Console.WriteLine("leaf3: " + leaf3);
            leaf1 = 30; leaf2 = "new leaf2";
            Console.WriteLine("Changing tree's fields' values and calling Lua function print to show it...");
            l["tree.branch1.leaf1"] = leaf1; l["tree.branch1.leaf2"] = leaf2;
            l.DoString("print(tree.branch1.leaf1,tree.branch1.leaf2)");
            Console.WriteLine("Returning values from Lua with 'return'...");
            object[] vals = l.DoString("return 2,3");
            Console.WriteLine("Returned: " + vals[0] + " and " + vals[1]);
            Console.WriteLine("Calling a Lua function that returns multiple values...");
            object[] vals1 = l.GetFunction("func").Call(2, 3);
            Console.WriteLine("Returned: " + vals1[0] + " and " + vals1[1]);
            Console.WriteLine("Creating a table and filling it from C#...");
            l.NewTable("tab");
            l.NewTable("tab.tab");
            l["tab.a"] = "a!";
            l["tab.b"] = 5.5;
            l["tab.tab.c"] = 6.5;
            l.DoString("print(tab.a,tab.b,tab.tab.c)");
            Console.WriteLine("Setting a table as another table's field...");
            l["tab.a"] = l["tab.tab"];
            l.DoString("print(tab.a.c)");
            Console.WriteLine("Registering a C# static method and calling it from Lua...");

            // Pause so we can connect with the debugger
            // Thread.Sleep(30000);
            l.RegisterFunction("func1", null, typeof(TestLuaInterface).GetMethod("func"));
            vals1 = l.GetFunction("func1").Call(2, 3);
            Console.WriteLine("Returned: " + vals1[0]);
            TestLuaInterface obj = new TestLuaInterface();
            Console.WriteLine("Registering a C# instance method and calling it from Lua...");
            l.RegisterFunction("func2", obj, typeof(TestLuaInterface).GetMethod("funcInstance"));
            vals1 = l.GetFunction("func2").Call(2, 3);
            Console.WriteLine("Returned: " + vals1[0]);

            Console.WriteLine("Testing throwing an exception...");
            obj.ThrowUncaughtException();

            Console.WriteLine("Testing catching an exception...");
            obj.ThrowException();

            Console.WriteLine("Testing inheriting a method from Lua...");
            obj.LuaTableInheritedMethod();

            Console.WriteLine("Testing overriding a C# method with Lua...");
            obj.LuaTableOverridedMethod();

            Console.WriteLine("Stress test RegisterFunction (based on a reported bug)..");
            obj.RegisterFunctionStressTest();

            Console.WriteLine("Test structures...");
            obj.TestStructs();
//.........这里部分代码省略.........
开发者ID:rumkex,项目名称:LuaInterface,代码行数:101,代码来源:TestLuaInterface.cs

示例6: _Calc

        private void _Calc(Lua lua, int i)
        {
            lua.DoString(
                     "sqrt = math.sqrt;" +
                     "sqr = function(x) return math.pow(x,2); end;" +
                     "log = math.log;" +
                     "log10 = math.log10;" +
                     "exp = math.exp;" +
                     "sin = math.sin;" +
                     "cos = math.cos;" +
                     "tan = math.tan;" +
                     "abs = math.abs;"
                     );

            lua.DoString("function calcVP(a,b) return a+b end");
            LuaFunction lf = lua.GetFunction("calcVP");
            /*Object[] ret = */lf.Call(i, 20);
        }
开发者ID:rumkex,项目名称:LuaInterface,代码行数:18,代码来源:TestLuaInterface.cs

示例7: CallGlobalFunctionOneReturn

 public void CallGlobalFunctionOneReturn()
 {
     using (Lua lua = new Lua())
     {
         lua.DoString("function f(x)\nreturn x+2\nend");
         object[] ret = lua.GetFunction("f").Call(3);
         //Console.WriteLine("ret="+ret[0]);
         Assert.Equal(1, ret.Length);
         Assert.Equal(5, (double)ret[0]);
     }
 }
开发者ID:h34tn,项目名称:luainterface,代码行数:11,代码来源:LuaTests.cs

示例8: CallTableFunctionTwoReturns

 public void CallTableFunctionTwoReturns()
 {
     using (Lua lua = new Lua())
     {
         lua.DoString("a={}\nfunction a.f(x,y)\nreturn x,x+y\nend");
         object[] ret = lua.GetFunction("a.f").Call(3, 2);
         //Console.WriteLine("ret="+ret[0]+","+ret[1]);
         Assert.Equal(2, ret.Length);
         Assert.Equal(3, (double)ret[0]);
         Assert.Equal(5, (double)ret[1]);
     }
 }
开发者ID:h34tn,项目名称:luainterface,代码行数:12,代码来源:LuaTests.cs

示例9: TestRegisterFunction

        public void TestRegisterFunction()
        {
            using (Lua lua = new Lua())
            {

                lua.RegisterFunction("func1", null, typeof(TestClass2).GetMethod("func"));
                object[] vals1 = lua.GetFunction("func1").Call(2, 3);

                Assert.Equal(5.0f, Convert.ToSingle(vals1[0]));

                TestClass2 obj = new TestClass2();
                lua.RegisterFunction("func2", obj, typeof(TestClass2).GetMethod("funcInstance"));
                vals1 = lua.GetFunction("func2").Call(2, 3);

                Assert.Equal(5.0f, Convert.ToSingle(vals1[0]));
            }
        }
开发者ID:h34tn,项目名称:luainterface,代码行数:17,代码来源:LuaTests.cs

示例10: TestEventException

        public void TestEventException()
        {
            using (Lua lua = new Lua())
            {
                //Register a C# function
                MethodInfo testException = this.GetType().GetMethod("_TestException", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance, null, new Type[] { typeof(float), typeof(float) }, null);
                lua.RegisterFunction("Multiply", this, testException);

                //create the lua event handler code for the entity
                //includes the bad code!
                lua.DoString("function OnClick(sender, eventArgs)\r\n" +
                              "--Multiply expects 2 floats, but instead receives 2 strings\r\n" +
                              "Multiply(asd, we)\r\n" +
                            "end");

                //create the lua event handler code for the entity
                //good code
                //lua.DoString("function OnClick(sender, eventArgs)\r\n" +
                //              "--Multiply expects 2 floats\r\n" +
                //              "Multiply(2, 50)\r\n" +
                //            "end");

                //Create the event handler script
                lua.DoString("function SubscribeEntity(e)\r\ne.Clicked:Add(OnClick)\r\nend");

                //Create the entity object
                Entity entity = new Entity();

                //Register the entity object with the event handler inside lua
                LuaFunction lf = lua.GetFunction("SubscribeEntity");
                lf.Call(new object[1] { entity });

                try
                {
                    //Cause the event to be fired
                    entity.Click();

                    //failed
                    Assert.True(false);
                }
                catch (LuaException e)
                {
                    //passed
                    Assert.True(true);
                }
            }
        }
开发者ID:h34tn,项目名称:luainterface,代码行数:47,代码来源:LuaTests.cs

示例11: CallGlobalFunctionTwoArgs

 public void CallGlobalFunctionTwoArgs()
 {
     using (Lua lua = new Lua())
     {
         lua.DoString("a=2\nfunction f(x,y)\na=x+y\nend");
         lua.GetFunction("f").Call(1, 3);
         double num = lua.GetNumber("a");
         //Console.WriteLine("a="+num);
         Assert.Equal(num, 4d);
     }
 }
开发者ID:h34tn,项目名称:luainterface,代码行数:11,代码来源:LuaTests.cs

示例12: Main

    public static void Main(string[] args)
    {
        Lua L = new Lua();

        // testing out parameters and type coercion for object[] args.
        L["obj"] = new RefParms();
        dump("void,out,out",L.DoString("return obj:Args()"));
        dump("int,out,out",L.DoString("return obj:ArgsI()"));
        L.DoString("obj:ArgsVar{1}");
        Console.WriteLine("equals {0} {1} {2}",IsInteger(2.3),IsInteger(0),IsInteger(44));
        //Environment.Exit(0);

        object[] res = L.DoString("return 20,'hello'","tmp");
        Console.WriteLine("returned {0} {1}",res[0],res[1]);

        L.DoString("answer = 42");
        Console.WriteLine("answer was {0}",L["answer"]);

        MyClass.Register(L);

        L.DoString(@"
        print(Sqr(4))
        print(Sum(1.2,10))
        -- please note that this isn't true varargs syntax!
        print(utils.sum {1,5,4.2})
        ");

        L.DoString("X = {1,2,3}; Y = {fred='dog',alice='cat'}");

        LuaTable X = (LuaTable)L["X"];
        Console.WriteLine("1st {0} 2nd {1}",X[1],X[2]);
        // (but no Length defined: an oversight?)
        Console.WriteLine("X[4] was nil {0}",X[4] == null);

        // only do this if the table only has string keys
        LuaTable Y = (LuaTable)L["Y"];
        foreach (string s in Y.Keys)
            Console.WriteLine("{0}={1}",s,Y[s]);

        // getting and calling functions by name
        LuaFunction f = L.GetFunction("string.gsub");
        object[] ans = f.Call("here is the dog's dog","dog","cat");
        Console.WriteLine("results '{0}' {1}",ans[0],ans[1]);

        // and it's entirely possible to do these things from Lua...
        L["L"] = L;
        L.DoString(@"
            L:DoString 'print(1,2,3)'
        ");

        // it is also possible to override a CLR class in Lua using luanet.make_object.
        // This defines a proxy object which will successfully fool any C# code
        // receiving it.
         object[] R = L.DoString(@"
            luanet.load_assembly 'CallLua'  -- load this program
            local CSharp = luanet.import_type 'CSharp'
            local T = {}
            function T:MyMethod(s)
                return s:lower()
            end
            function T:Protected(s)
                return s:upper()
            end
            function T:ProtectedBool()
                return true
            end
            luanet.make_object(T,'CSharp')
            print(CSharp.UseMe(T,'CoOl'))
            io.flush()
            return T
        ");
        // but it's still a table, and there's no way to cast it to CSharp from here...
        Console.WriteLine("type of returned value {0}",R[0].GetType());
    }
开发者ID:bobbyzhu,项目名称:MonoLuaInterface,代码行数:74,代码来源:CallLua.cs


注:本文中的Lua.GetFunction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。