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


C# Lua.DoString方法代码示例

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


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

示例1: Main2

        static void Main2()
        {
            Lua L = new Lua();
            //            L.DoString("UnityEngine = luanet.UnityEngine");
            //            L.DoString("print(UnityEngine)");
            //            L.DoString("cubetype = UnityEngine.PrimitiveType.Cube");
            //            L.DoString("print(cubetype)");
            //            L.DoString("gotype = UnityEngine.GameObject");
            //            L.DoString("print(gotype)");
            //            L.DoString("CP = gotype.CreatePrimitive");
            //            L.DoString("print(CP)");
            //            L.DoString("cube2 = UnityEngine.GameObject.CP2()");
            //            L.DoString("print(cube2)");
            //            L.DoString("cube = CP(cubetype)");
            //            L.DoString("cube = luanet.UnityEngine.GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Cube)");
            L.DoString("luanet.import_type(UnityEngine.GameObject)()");
            L.DoString("luanet.UnityEngine.GameObject.CP2()");

            while (true)
            {
                L.DoString("t = UnityEngine.Time.realtimeSinceStartup");
                L.DoString("q = UnityEngine.Quaternion.AngleAxis(t*50, UnityEngine.Vector3.up)");
                L.DoString("cube.transform.rotation = q");
                System.Threading.Thread.Sleep(1);
            }
        }
开发者ID:niuniuzhu,项目名称:kopiluainterface,代码行数:26,代码来源:StressTest.cs

示例2: Main

        static void Main(string[] args)
        {
            using (var lua = new Lua())
            {
                lua.DoFile("Apollo.lua");

                var luaUnit = @"C:/git/luaunit";
                var addonDir = "TrackMaster";
                var addonPath = Path.Combine(Environment.GetEnvironmentVariable("appdata"), @"NCSOFT\Wildstar\Addons\" + addonDir + @"\");

                lua.DoString(string.Format("package.path = package.path .. ';{0}/?.lua;{1}/?.lua'", luaUnit, addonPath.Replace('\\', '/')));
                var toc = XDocument.Load(Path.Combine(addonPath, "toc.xml"));
                foreach (var script in toc.Element("Addon").Elements("Script"))
                {
                    lua.DoFile(Path.Combine(addonPath, script.Attribute("Name").Value));
                }

                foreach (var testFiles in Directory.GetFiles(Path.Combine(addonPath, "Tests")))
                {
                    Console.WriteLine("Loading File: " + testFiles);
                    lua.DoFile(testFiles);
                }
                try
                {
                    lua.DoString("require('luaunit'):run()");
                }
                catch (LuaException ex)
                {
                    Console.WriteLine("Execution Error: " + ex.ToString());
                }
                //Console.ReadLine();
            }
        }
开发者ID:nilfisk,项目名称:WildstarUT,代码行数:33,代码来源:Program.cs

示例3: Start

	void Start()
	{
		_lua = new Lua();
		_lua.DoString("UnityEngine = luanet.UnityEngine");
		_lua.DoString("System = luanet.System");
		_lua["gameObject"] = this;
		
		Code = "function update(dt)\n\nend\n";
		
		DoCode(Code);
	}
开发者ID:drakelinglabs,项目名称:unityarmada,代码行数:11,代码来源:Controller.cs

示例4: Update

	void Update()
	{
		if (virgin)
		{
			virgin = false;
			
			L = new Lua();
			
			gameObject.GetComponent<Renderer>().material.color = new Color(1.0f, 0.8f, 0.2f);
		
			L.DoString("r = 0");
			L.DoString("g = 1");
			L.DoString("b = 0.2");
			
			float r = (float)(double)L["r"];
			float g = (float)(double)L["g"];
			float b = (float)(double)L["b"];
			
			gameObject.GetComponent<Renderer>().material.color = new Color(r, g, b);
		
			Debug.Log("1");
			
			L["go"] = gameObject;
			
			Debug.Log("2");
			
			Vector3 v = gameObject.transform.position;
			v.y += 1.0f;
			L["v"] = v;
			
			Debug.Log("3");
			
			L.DoString("go.transform.position = v");
		
			Debug.Log("4");
			
			string[] script = {
				"UnityEngine = luanet.UnityEngine",
				"cube = UnityEngine.GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Cube)",
				""
			};
			
			foreach (var line in script)
			{
				L.DoString(line);
			}
		}
		
		L.DoString("t = UnityEngine.Time.realtimeSinceStartup");
		L.DoString("q = UnityEngine.Quaternion.AngleAxis(t*50, UnityEngine.Vector3.up)");
		L.DoString("cube.transform.rotation = q");
	}
开发者ID:drakelinglabs,项目名称:unityarmada,代码行数:52,代码来源:KLITest.cs

示例5: Main

        static void Main(string[] args)
        {
            Lua lua = new Lua();
            lua["x"] = 3;
            lua.DoString("y=x");
            Console.WriteLine("y={0}", lua["y"]);

            {
                object[] retVals = lua.DoString("return 1,'hello'");
                Console.WriteLine("{0},{1}", retVals[0], retVals[1]);
            }

            {
                KopiLua.Lua.lua_pushcfunction(lua.luaState, Func);
                KopiLua.Lua.lua_setglobal(lua.luaState, "func");
                Console.WriteLine("registered 'func'");

                double result = (double)lua.DoString("return func(1,2,3)")[0];
                Console.WriteLine("{0}", result);
            }

            {
                Bar bar = new Bar();
                bar.x = 2;
                lua["bar"] = bar;
                Console.WriteLine("'bar' registered");

                object o = lua["bar"];
                Console.WriteLine("'bar' read back as {0}", o);
                Console.WriteLine(o == bar ? "same" : "different");
                Console.WriteLine("LuaInterface says bar.x = {0}", lua["bar.x"]);

                double result = (double)lua.DoString("return bar.x")[0];
                Console.WriteLine("lua says bar.x = {0}", result);

                lua.DoString("bar.x = 4");
                Console.WriteLine("now bar.x = {0}", bar.x);
            }

            {
                Foo foo = new Foo();
                lua.RegisterFunction("multiply", foo, foo.GetType().GetMethod("multiply"));
                Console.WriteLine("registered 'multiply'");

                double result = (double)lua.DoString("return multiply(3)")[0];
                Console.WriteLine("{0}", result);
            }

            Console.ReadLine();
        }
开发者ID:sanyaade-embedded-systems,项目名称:kopiluainterface,代码行数:50,代码来源:Program.cs

示例6: Start

    void Start()
    {
        Debug.Log("== 测试 ==   C#获取Lua Float");
        Lua lua = new Lua();
        lua.DoString("num1 = -0.9999999");
        Debug.Log(lua["num1"]);
	}
开发者ID:Henry-T,项目名称:UnityPG,代码行数:7,代码来源:LuaFloatGet.cs

示例7: Load

    public void Load(Lua lua)
    {
        if(lua == null)
        {
            return;
        }

        foreach(TextAsset code in Scripts)
        {
            lua.DoString(code.text);
        }
    }
开发者ID:Henry-T,项目名称:UnityPG,代码行数:12,代码来源:LuaLoad.cs

示例8: Main

        private static void Main(string[] args)
        {
            using (Lua = new Lua())
            {
                Lua["_TESTRUNNER"] = true;
                Lua.DoFile("Apollo.lua");
                Lua.DoString("function Print(string) print(string) end");
                Lua.RegisterFunction("XmlDoc.CreateFromFile", null, typeof(XmlDoc).GetMethod("CreateFromFile"));

                string addonDir = "TrackMaster";
                string addonPath = FindTocFile(args.FirstOrDefault()) ?? Path.Combine(Environment.GetEnvironmentVariable("appdata"), @"NCSOFT\Wildstar\Addons\" + addonDir + @"\");
                Directory.SetCurrentDirectory(addonPath);

                Lua.DoString(string.Format("package.path = package.path .. ';{0}/?.lua'", addonPath.Replace('\\', '/')));
                XDocument toc = XDocument.Load(Path.Combine(addonPath, "toc.xml"));
                Lua.DoString(string.Format("Apollo.__AddonName = '{0}'", toc.Element("Addon").Attribute("Name").Value));
                foreach (XElement script in toc.Element("Addon").Elements("Script"))
                {
                    Console.WriteLine("Loading File: " + script.Attribute("Name").Value);
                    Lua.DoFile(Path.Combine(addonPath, script.Attribute("Name").Value));
                }

                //foreach (var testFiles in Directory.GetFiles(Path.Combine(addonPath, "Tests")))
                //{
                //    Console.WriteLine("Loading File: " + testFiles);
                //    Lua.DoFile(testFiles);
                //}
                try
                {
                    //Lua.DoString("Apollo.GetPackage('WildstarUT-1.0').tPackage:RunAllTests()");

                    Lua.DoString("Apollo.GetPackage('Lib:Busted-2.0').tPackage:RunAllTests()");
                }
                catch (LuaException ex)
                {
                    Console.WriteLine("Execution Error: " + ex);
                }
            }
        }
开发者ID:James226,项目名称:WildstarUT,代码行数:39,代码来源:Program.cs

示例9: Main

        static void Main(string[] args)
        {
            Lua lua = new Lua();
            lua["x"] = 3;
            lua.DoString("y=x");
            Console.WriteLine("y={0}", lua["y"]);

            {
                lua.DoString("luanet.load_assembly('SimpleTest')");
                lua.DoString("Foo = luanet.import_type('SimpleTest.Foo')");
                lua.DoString("method = luanet.get_method_bysig(Foo, 'OutMethod', 'SimpleTest.Foo', 'out SimpleTest.Bar')");
                Console.WriteLine(lua["method"]);
            }

            {
                object[] retVals = lua.DoString("return 1,'hello'");
                Console.WriteLine("{0},{1}", retVals[0], retVals[1]);
            }

            {
                KopiLua.Lua.lua_pushcfunction(lua.luaState, Func);
                KopiLua.Lua.lua_setglobal(lua.luaState, "func");
                Console.WriteLine("registered 'func'");

                double result = (double)lua.DoString("return func(1,2,3)")[0];
                Console.WriteLine("{0}", result);
            }

            {
                Bar bar = new Bar();
                bar.x = 2;
                lua["bar"] = bar;
                Console.WriteLine("'bar' registered");

                object o = lua["bar"];
                Console.WriteLine("'bar' read back as {0}", o);
                Console.WriteLine(o == bar ? "same" : "different");
                Console.WriteLine("LuaInterface says bar.x = {0}", lua["bar.x"]);

                double result = (double)lua.DoString("return bar.x")[0];
                Console.WriteLine("lua says bar.x = {0}", result);

                lua.DoString("bar.x = 4");
                Console.WriteLine("now bar.x = {0}", bar.x);
            }

            {
                Foo foo = new Foo();
                lua.RegisterFunction("multiply", foo, foo.GetType().GetMethod("multiply"));
                Console.WriteLine("registered 'multiply'");

                double result = (double)lua.DoString("return multiply(3)")[0];
                Console.WriteLine("{0}", result);
            }

            Console.WriteLine("Finished, press Enter to quit");
            Console.ReadLine();
        }
开发者ID:huxia,项目名称:kopiluainterface,代码行数:58,代码来源:Program.cs

示例10: Initialize

    public void Initialize()
    {
        _lua = new Lua();

        if(PreLoad != null)
        {
            PreLoad.Load(_lua);
        }

        SetData();

        foreach(TextAsset code in Scripts)
        {
            _lua.DoString(code.text);
        }
    }
开发者ID:Henry-T,项目名称:UnityPG,代码行数:16,代码来源:LuaUnity.cs

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

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

示例13: read

        public static void read (Lua L)
        {
            
            using (System.IO.StreamReader sr = System.IO.File.OpenText(fullLuaPath))
            {
                string line;
		//while the reader is not at the end of text. load a lua line.
                while ((line = sr.ReadLine()) != null)
                {
		    luaLines.Add(line);
                    L.DoString(line);
		    GDLog.log(line);
                }
            }
	    luaLines.Clear();
	    using (System.IO.StreamWriter sw = System.IO.File.CreateText(fullLuaPath))	
		{
	            //only here to create the file and close the stream
		    //if it ain't broke don't fix it
		    GDLog.log("Erasing path for lua logger");
                }

        }
开发者ID:alfred316,项目名称:GamePracticumF14,代码行数:23,代码来源:LuaLogger.cs

示例14: cmdTreePhFolder_newFile_Click

        /// <summary>
        /// 新建文件
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void cmdTreePhFolder_newFile_Click(object sender, EventArgs e)
        {
            if (treePh.SelectedNode != null)
            {
                // 开始和lua交互
                string strFullPath = treePh.SelectedNode.FullPath;
                Lua plua = new Lua();
                object[] oRet = null;
                
                plua.DoString(DataBaseManager.GetDataBaseManager().GetScriptData(this.getFileIDsFromPath("Template")[0].ToString()));
                LuaFunction fun = plua.GetFunction("LoadParms");

                if (fun != null)
                {
                    object[] args = { strFullPath };
                    oRet = fun.Call(args);

                    if (oRet == null)
                    {
                        return;
                    }
                }                            
                
                string strControls = oRet[0] as string;

                // 孙韬返回的内容
                object[] strParms;

                // 文件名
                string strName = "";
                string[] asp1 = { "|" };
                ModelForm mf = new ModelForm(strControls.Split(asp1, StringSplitOptions.RemoveEmptyEntries));

                if (mf.ShowDialog() == DialogResult.OK)
                {
                    List<string> list = mf.InputList;

                    if (list.Count >= 2)
                    {
                        strParms = list.ToArray();
                        strName = strParms[1] as string;

                        string strCode = "";
                        fun = plua.GetFunction("LoadScript");

                        if (fun != null)
                        {
                            oRet = fun.Call(strParms);
                            strCode = oRet[0] as string;
                        }
                        else
                        {
                            return;
                        }                

                        // 交互完毕
                        if (string.IsNullOrEmpty(strName))
                        {
                            return;
                        }

                        if (CheckNodeExist(treePh.SelectedNode, strName))
                        {
                            MessageBox.Show("当前树结点已经存在!", "新建文件",
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }

                        Hashtable infoTable = new Hashtable();
                        infoTable["type"] = "file";

                        // 存数据库
                        DataBaseManager dbm = DataBaseManager.GetDataBaseManager();
                        string strPath = treePh.SelectedNode.FullPath;
                        string[] asp = { "\\" };
                        string[] as_Path = strPath.Split(asp, StringSplitOptions.RemoveEmptyEntries);

                        if (as_Path.Length < 2 && as_Path[0] == "scripts")
                        {
                            MessageBox.Show("暂时不支持在其他地图以外的目录建文件", "新建文件", 
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        string id = dbm.CreateScriptData(string.Format("{0}\\{1}", strPath, strName));

                        if (id == null)
                        {
                            MessageBox.Show("新建文件失败!", "新建文件", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else
                        {
                            // 新建成功,更新树缓存
                            treePh.Tag = dbm.GetScriptInformation();
//.........这里部分代码省略.........
开发者ID:viticm,项目名称:pap2,代码行数:101,代码来源:MainForm.cs

示例15: testScript_Click

		private void testScript_Click(object sender, EventArgs e) {
			scriptValidatedValue.Visible = false;
			if (scriptTypeValue.Text == "Lua") {
				Lua lua = new Lua();
				lua.RegisterMarkedMethodsOf(this);
				//add some variables so we can pass tests
				lua["item"] = Items.ItemFactory.CreateItem(ObjectId.Parse("5383dc8531b6bd11c4095993"));

				if (byPassTestValue.Visible) {
					ScriptError = !byPassTestValue.Checked;
				}
				else {
					try {
						lua.DoString(scriptValue.Text);
						ScriptError = false;
						scriptValidatedValue.Visible = true;
					}
					catch (LuaException lex) {
						MessageBox.Show(lex.Message, "Lua Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
						ScriptError = true;
					}
				}
			}
			else {
				if (byPassTestValue.Visible) {
					ScriptError = !byPassTestValue.Checked;
				}
				ScriptEngine engine = new ScriptEngine();
				ScriptMethods host = new ScriptMethods();
				host.DataSet.Add("player", Character.NPCUtils.CreateNPC(1));
				host.DataSet.Add("npc", Character.NPCUtils.CreateNPC(1));
				Roslyn.Scripting.Session session = engine.CreateSession(host, host.GetType());
				new[]
					   {
						 typeof (Type).Assembly,
						 typeof (ICollection).Assembly,
						 typeof (Console).Assembly,
						 typeof (RoslynScript).Assembly,
						 typeof (IEnumerable<>).Assembly,
						 typeof (IQueryable).Assembly,
						 typeof (ScriptMethods).Assembly,
						 typeof(IActor).Assembly,
						 typeof(Character.Character).Assembly,
						 typeof(NPC).Assembly,
						 typeof(Room).Assembly,
						 typeof(Commands.CommandParser).Assembly,
						 typeof(Interfaces.Message).Assembly,
						 GetType().Assembly
					}.ToList().ForEach(asm => session.AddReference(asm));

				//Import common namespaces
				new[]
						{
						 "System", "System.Linq", "System.Object", "System.Collections", "System.Collections.Generic",
						 "System.Text", "System.Threading.Tasks", "System.IO",
						 "Character", "Rooms", "Items", "Commands", "ClientHandling", "Triggers"
					 }.ToList().ForEach(ns => session.ImportNamespace(ns));
				try {
					var result = session.CompileSubmission<object>(scriptValue.Text);
					ScriptError = false;
					scriptValidatedValue.Visible = true;
				}
				catch (Exception ex) {
					MessageBox.Show("Errors found in script:\n " + ex.Message, "Script Errors", MessageBoxButtons.OK);
				}
			}
		}
开发者ID:jandar78,项目名称:Novus,代码行数:67,代码来源:ScriptsTab.cs


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