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


C# Lua.DoFile方法代码示例

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


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

示例1: Start

    public void Start()
    {
        //Init LuaBinding class that demonstrates communication
        LuaBinding binding = new LuaBinding();

        //Init instance of Lua virtual machine (Note: Can only init ONCE)
        luaVirtualMachine = new Lua();
        //Tell Lua about the LuaBinding object to allow Lua to call C# functions
        luaVirtualMachine["luabinding"] = binding;

        //test luabinding test
        LuaBindingTest bindingTest = LuaBindingTest.SharedInstance();
        bindingTest.name = "name1";
        luaVirtualMachine["LuaBindingTest"] = bindingTest;
        //luaVirtualMachine[""] = ;

        //Debug.LogError("LuaManager: " + Application.persistentDataPath);

        //Run the code contained within the file
        #if UNITY_ANDROID
        luaVirtualMachine.DoFile("/sdcard/Download/"+LuaFileToLoad);
        #else
        luaVirtualMachine.DoFile(Application.streamingAssetsPath+"/"+LuaFileToLoad);
        #endif
        //Trigger binding in c# to call the bound Lua function

        binding.MessageToLua();
        TestStaticFunction();
    }
开发者ID:haiweizhang,项目名称:UnityKopiLuaIntegration,代码行数:29,代码来源:LuaManager.cs

示例2: Start

    public void Start()
    {
        //Init LuaBinding class that demonstrates communication
        LuaBinding binding = new LuaBinding();

        //Init instance of Lua virtual machine (Note: Can only init ONCE)
        luaVirtualMachine = new Lua();
        //Tell Lua about the LuaBinding object to allow Lua to call C# functions
        luaVirtualMachine["luabinding"] = binding;
        //Run the code contained within the file
        luaVirtualMachine.DoFile(Application.streamingAssetsPath+"/"+LuaFileToLoad);
        //Trigger binding in c# to call the bound Lua function
        binding.MessageToLua();
    }
开发者ID:TrentSterling,项目名称:UnityLuaIntegration,代码行数:14,代码来源:LuaManager.cs

示例3: LuaAPI

	public LuaFunction boundMessageFunction; //Reference to bound Lua function set within Lua
	
	// Constructor
	public LuaAPI() {
		// create new instance of Lua
		lua = new Lua();
		
		// Initialize array.
		movementQueue = new Queue();
		
		// Get the UnityEngine reference
		lua.DoString("UnityEngine = luanet.UnityEngine");
		
		// get the boat and its controls
		boat = GameObject.FindGameObjectWithTag("TheBoat");
		shipControls = boat.GetComponent<ShipControls>();
		
		//Tell Lua about the LuaBinding object to allow Lua to call C# functions
		lua["luabinding"] = this;
		
		//Run the code contained within the file
		lua.DoFile(Application.streamingAssetsPath + "/" + drivers);
	}
开发者ID:alfred316,项目名称:GamePracticumF14,代码行数:23,代码来源:LuaAPI.cs

示例4: Main

        static void Main(string[] args)
        {
            // Create the Lua object.
            Lua lua = new Lua();
            dynamic E = lua.Environment;

            //E.TailCalls = Lua.UseDynamicTypes;
            E.DoThreads = true;

            // Expose these to Lua.
            lua.Register(typeof(ITest));
            lua.Register((Test)Foo);

            // Load and execute a Lua file.
            lua.DoFile("Tests.lua");
            
            // Keep the console window open.
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
开发者ID:TheModMaker,项目名称:ModMaker.Lua,代码行数:20,代码来源:Program.cs

示例5: 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

示例6: 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


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