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


C# Lua.DoFile方法代码示例

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


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

示例1: TestBinaryLoadFile

		public void TestBinaryLoadFile ()
		{
			using (Lua lua = new Lua ()) {
				lua.LoadCLRPackage ();
				if (IntPtr.Size == 4)
					lua.DoFile ("test_32.luac");
				else
					lua.DoFile ("test_64.luac");

				int width = (int)(double)lua ["width"];
				int height = (int)(double)lua ["height"];
				string message = (string)lua ["message"];
				int color_g	= (int)(double)lua ["color.g"];
				LuaFunction func = (LuaFunction)lua ["func"];
				object[] res = func.Call (12, 34);
				int x = (int)(double)res [0];
				int y = (int)(double)res [1];
				//function func(x,y)
				//	return x,x+y
				//end

				Assert.AreEqual (100, width);
				Assert.AreEqual (200, height);
				Assert.AreEqual ("Hello World!", message);
				Assert.AreEqual (20, color_g);
				Assert.AreEqual (12, x);
				Assert.AreEqual (46, y);
			}
		}
开发者ID:mMellowz,项目名称:revcore,代码行数:29,代码来源:LoadFileTests.cs

示例2: Main

        private static void Main()
        {
            Console.Title = "NLua Test Environment";

            object x = 3;
            double y = (double)(int)x;

            string script = "function add(a, b) return a + b, a, b; end\n" +
                            "local function sub(a, b) return a - b; end\n" +
                            "local function mul(a, b) return a * b; end\n" +
                            "local function div(a, b) return a / b; end\n" +
                            "print(\"Adding 1 and 5 gives us \" .. add(1, 5));\n" +
                            "print(\"Subtracting 8 and 2 gives us \" .. sub(8, 2));\n" +
                            "print(\"Multiplying 32 and 1024 gives us \" .. mul(32, 1024));\n" +
                            "print(\"Dividing 8 and 2 gives us \" .. div(8, 2));\n";

            using (dynamic lua = new Lua())
            {
                lua.LoadStandardLibrary(LuaStandardLibraries.Basic);
                lua.DoString("print(\"This confirms the Lua environment has loaded the basic standard library.\\nThe Lua environment is operational.\");");
                lua.DoFile("TestScript.lua");

                lua.v = "test";

                object[] table = lua.x;
            }

            Console.ReadLine();
        }
开发者ID:JumpNotZero,项目名称:NLua,代码行数:29,代码来源:Program.cs

示例3: LuaScene

 /// <summary>
 /// 新しくLuaシーンを初期化。
 /// </summary>
 /// <param name="sceneName">シーン名</param>
 /// <param name="luafile">制御するLuaのファイル名</param>
 public LuaScene(string sceneName, string luafile)
     : base()
 {
     LuaScript = new Lua();
     LuaScript["Scenes"] = Scenes.Instance;
     LuaScript.DoFile(luafile);
     ID = sceneName;
 }
开发者ID:kb10uy,项目名称:Kb10uy,代码行数:13,代码来源:Scene.cs

示例4: Run

        public static void Run(string commandname, string[] args, bool fromGroup, string ChatterID, string ChatRoomID)
        {
            try
            {
                using (Lua lua = new Lua())
                {
                    GlobalSteamLuaFunctions steamFunc = new GlobalSteamLuaFunctions();

                    
                    lua.RegisterFunction("kickPlayer", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("kickPlayer"));
                    lua.RegisterFunction("notImplemented", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("notImplemented"));
                    lua.RegisterFunction("getPermissions", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("getPermissions"));
                    lua.RegisterFunction("sendRoomMessage", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("sendRoomMessage"));
                    lua.RegisterFunction("sendFriendMessage", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("sendFriendMessage"));
                    //lua.RegisterFunction("convertChatIDtoSteamKit", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("convertChatIDtoSteamKit"));
                    lua.RegisterFunction("getPersonaName", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("getPersonaName"));
                    lua.RegisterFunction("addRow", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("addRow"));
                    lua.RegisterFunction("getRow", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("getRow"));
                    lua.RegisterFunction("bindCommand", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("bindCommand"));
                    lua.RegisterFunction("unbindCommand", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("unbindCommand"));
                    lua.RegisterFunction("changePermissions", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("changePermissions"));
                    lua.RegisterFunction("changeName", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("changeName"));
                    lua.RegisterFunction("likeRow", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("likeRow"));
                    lua.RegisterFunction("getCustomURL", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("getCustomURL"));
                    lua.RegisterFunction("banPlayer", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("banPlayer"));
                    lua.RegisterFunction("createTable", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("createTable"));
                    lua.RegisterFunction("silentFail", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("silentFail"));

                    lua["ChatterID"] = ChatterID;
                    lua["fromGroup"] = fromGroup;
                    lua["ChatRoomID"] = ChatRoomID;
                    lua["args"] = args;
                    for(int i = 1; i < args.Count(); i++)
                    {
                        if (i == 1)
                        {
                            argsJoined = args[i];
                        }
                        else
                        {
                            argsJoined = argsJoined + " " + args[i];
                        }
                    }
                    lua["argsJoined"] = argsJoined;

                    lua.DoFile("lua/commands/" + commandname.Substring(1) + ".lua");
                }
            }
            catch (Exception e)
            {
                Log.addLog(Log.types.WARNING, "Lua", "You have an error in your command!", e.ToString());
            }
        }
开发者ID:JustHev,项目名称:BaHBot,代码行数:53,代码来源:LuaCommand.cs

示例5: Run

        public static void Run(string scriptname, params string[] args)
        {
            try
            {
                using (Lua lua = new Lua())
                {
                    GlobalSteamLuaFunctions steamFunc = new GlobalSteamLuaFunctions();


                    lua.RegisterFunction("kickPlayer", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("kickPlayer"));
                    lua.RegisterFunction("notImplemented", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("notImplemented"));
                    lua.RegisterFunction("getPermissions", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("getPermissions"));
                    lua.RegisterFunction("sendRoomMessage", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("sendRoomMessage"));
                    lua.RegisterFunction("sendFriendMessage", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("sendFriendMessage"));
                    lua.RegisterFunction("getPersonaName", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("getPersonaName"));
                    lua.RegisterFunction("addRow", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("addRow"));
                    lua.RegisterFunction("getRow", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("getRow"));
                    lua.RegisterFunction("bindCommand", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("bindCommand"));
                    lua.RegisterFunction("unbindCommand", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("unbindCommand"));
                    lua.RegisterFunction("changePermissions", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("changePermissions"));
                    lua.RegisterFunction("changeName", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("changeName"));
                    lua.RegisterFunction("likeRow", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("likeRow"));
                    lua.RegisterFunction("getCustomURL", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("getCustomURL"));
                    lua.RegisterFunction("banPlayer", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("banPlayer"));
                    lua.RegisterFunction("createTable", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("createTable"));
                    lua.RegisterFunction("setLoginCredentials", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("setLoginCredentials"));
                    lua.RegisterFunction("joinChat", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("joinChat"));
                    lua.RegisterFunction("setAuthCode", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("setAuthCode"));
                    lua.RegisterFunction("connect", steamFunc, typeof(GlobalSteamLuaFunctions).GetMethod("connect"));

                    lua["args"] = args;
                    for (int i = 1; i < args.Count(); i++)
                    {
                        if (i == 1)
                        {
                            argsJoined = args[i];
                        }
                        else
                        {
                            argsJoined = argsJoined + " " + args[i];
                        }
                    }
                    lua["argsJoined"] = argsJoined;

                    lua.DoFile("lua/scripts/" + scriptname + ".lua");
                }
            }
            catch (Exception e)
            {
                Log.addLog(Log.types.WARNING, "Lua", "You have an error in your command!", e.ToString());
            }
        }
开发者ID:JustHev,项目名称:BaHBot,代码行数:52,代码来源:LuaScript.cs

示例6: Main

        public static void Main(string[] args)
        {
            if(args.Length > 0)
            {
                // For attaching from the debugger
                // Thread.Sleep(20000);

                using(Lua lua = new Lua())
                {
                    //lua.OpenLibs();			// steffenj: Lua 5.1.1 API change (all libs already opened in Lua constructor!)
                    lua.NewTable("arg");
                    LuaTable argc = (LuaTable)lua["arg"];
                    argc[-1] = "LuaRunner";
                    argc[0] = args[0];

                    for(int i = 1; i < args.Length; i++)
                        argc[i] = args[i];

                    argc["n"] = args.Length - 1;

                    try
                    {
                        //Console.WriteLine("DoFile(" + args[0] + ");");
                        lua.DoFile(args[0]);
                    }
                    catch(Exception e)
                    {
                        // steffenj: BEGIN error message improved, output is now in decending order of importance (message, where, stacktrace)
                        // limit size of strack traceback message to roughly 1 console screen height
                        string trace = e.StackTrace;

                        if(e.StackTrace.Length > 1300)
                            trace = e.StackTrace.Substring(0, 1300) + " [...] (traceback cut short)";

                        Console.WriteLine();
                        Console.WriteLine(e.Message);
                        Console.WriteLine(e.Source + " raised a " + e.GetType().ToString());
                        Console.WriteLine(trace);

                        // wait for keypress if there is an error
                        Console.ReadKey();
                        // steffenj: END error message improved
                    }
                }
            }
            else
            {
                Console.WriteLine("LuaRunner -- runs Lua scripts with CLR access");
                Console.WriteLine("Usage: luarunner <script.lua> [{<arg>}]");
            }
        }
开发者ID:Azhei,项目名称:NLua,代码行数:51,代码来源:LuaNetRunner.cs

示例7: executeScript

 /// <summary>
 /// Execute a script from file by name
 /// </summary>
 /// <param name="scriptName"></param>
 public static bool executeScript(string scriptName)
 {
     Lua lua = new Lua();
     lua.LoadCLRPackage();
     lua.DoString(@" import ('TextRPG', 'TextRPG')
        import ('System') ");
     try
     {
         var x = lua.DoFile(scriptName+".lua");
         GUI.Instance.appendToOutput(x.ToString());
         return true;
     }
     catch (Exception e)
     {
         return false;
     }
 }
开发者ID:Gokimster,项目名称:Dissertation,代码行数:21,代码来源:LuaManager.cs

示例8: Load

        public override IEnumerable<Kbtter4Plugin> Load(Kbtter instance, IList<string> filenames)
        {
            var list = new List<Kbtter4LuaPlugin>();
            var files = filenames.Where(p => p.EndsWith(".lua"));
            foreach (var i in files)
            {
                try
                {
                    Lua l = new Lua();
                    l.LoadCLRPackage();
                    l["Kbtter4"] = new Kbtter4PluginProvider(instance);
                    l.DoFile(i);
                    list.Add(new Kbtter4LuaPlugin(l,instance));
                }
                catch (Exception e)
                {
                    instance.LogError("Luaプラグイン読み込み中にエラーが発生しました : " + e.Message);
                }
            }

            return list;
        }
开发者ID:kb10uy,项目名称:Kbtter4,代码行数:22,代码来源:Kbtter4LuaPlugin.cs

示例9: Execute

        public static Option<Exception> Execute(string pathOrLiteral, Dictionary<string, object> args)
        {
            using(var state = new Lua()) {
                Exception internalEx = null;
                state.HookException += (s, e) => internalEx = e.Exception;

                foreach(var ele in args) {
                    state[ele.Key] = ele.Value;
                }

                try {
                    if(IsValidLuaScriptPath(pathOrLiteral)) {
                        state.DoFile(pathOrLiteral);
                    } else {
                        state.DoString(pathOrLiteral);
                    }
                    return internalEx != null ? Option.New(internalEx) : Option.New<Exception>();
                } catch (TargetInvocationException ex) {
                    return Option.New(ex.InnerException);
                } catch(Exception ex) {
                    return Option.New(ex);
                }
            }
        }
开发者ID:Visic,项目名称:NotepadSharp,代码行数:24,代码来源:LuaScriptRunner.cs

示例10: Run

        public override void Run(string[] arguments)
        {
            // Correcting path => base path is package path
            arguments[0] = Path.Combine(Package.Directory.FullName + Path.DirectorySeparatorChar, arguments[0]);

            using (Lua lua = new Lua())
            {
                lua.LoadCLRPackage();

                lua.DoString("import(\"craftitude\")"); // Load craftitude assembly into Lua.
                lua.RegisterFunction("GetPlatformString", this, this.GetType().GetMethod("GetPlatformString"));
                lua.RegisterFunction("GetProfile", this, this.GetType().GetMethod("GetProfile"));
                lua.RegisterFunction("GetPackage", this, this.GetType().GetMethod("GetPackage"));
                lua.RegisterFunction("GetProfilePath", this, this.GetType().GetMethod("GetProfilePath"));
                lua.RegisterFunction("GetPackagePath", this, this.GetType().GetMethod("GetPackagePath"));
                lua.DoString(@"
            local mt = { }
            local methods = { }
            function mt.__index(userdata, k)
            if methods[k] then
            return methods[k]
            else
            return rawget(userdata, ""_array"")[k]
            end
            end

            function mt.__newindex(userdata, k, v)
            if methods[k] then
            error ""can't assign to method!""
            else
            rawget(userdata, ""_array"")[k] = v
            end
            end");
                lua.DoString(@"
            function import_plugin(assemblyName, namespace)
            import(Path.Combine(GetPluginsDir(), assemblyName))
            import(namespace)
            end");
                lua.DoString(@"function install_plugin(dllPath, assemblyName)
            System.IO.File.Copy(dllPath, Path.Combine(GetPluginsDir(), assemblyName .. "".dll""))
            end");
                lua.DoString(@"function uninstall_plugin(assemblyName)
            System.IO.File.Delete(Path.Combine(GetPluginsDir(), assemblyName .. "".dll""))
            end");
                lua.DoFile(Path.Combine(Package.Path + Path.DirectorySeparatorChar, arguments[0].Replace('/', Path.DirectorySeparatorChar)));
                lua.GetFunction(arguments[1]).Call();
            }
        }
开发者ID:Craftitude-Team,项目名称:Craftitude,代码行数:48,代码来源:LuaSetup.cs

示例11: run_lua_button_Click

        private void run_lua_button_Click(object sender, EventArgs e)
        {
            var file_dialog = new OpenFileDialog();
            file_dialog.Filter = "Lua File (*.lua)|*.lua";
            file_dialog.ShowDialog();
            if (file_dialog.FileName == null)
            {
                return;
            }
            var lua = new Lua();
            lua.LoadCLRPackage();

            lua.DoFile(Path.Combine(Application.StartupPath, "data/lua/init.lua"));
            lua.DoFile(file_dialog.FileName);
            Console.WriteLine("Running Lua...");
        }
开发者ID:ModulousSmash,项目名称:ModulousMM,代码行数:16,代码来源:MainForm.cs

示例12: update_mod_from_metafile

 public static void update_mod_from_metafile(ModConfig config, int id = 0)
 {
     Directory.CreateDirectory(Globals.temporary_path);
     /*
      * Runs the installation thread.
      */
     var state = new Lua();
     state.LoadCLRPackage();
     state.DoFile(Path.Combine(Globals.AssemblyDirectory, "data/lua/init.lua"));
     state.DoFile(Path.Combine(Globals.temporary_path, config.install_script));
     Directory.CreateDirectory(Path.Combine(new string[] { SDCard.sd_card_mod_store_path, config.name }));
     var json_contents = File.ReadAllText(Path.Combine(Globals.temporary_path, "mod.json"));
     var mod = JsonConvert.DeserializeObject<ModConfig>(json_contents);
     mod.id = id;
     var content = JsonConvert.SerializeObject(mod, Formatting.Indented);
     File.WriteAllText(Path.Combine(Globals.temporary_path, "mod.json"), content);
     File.Copy(Path.Combine(Globals.temporary_path, "mod.json"),
         Path.Combine(new string[] { SDCard.sd_card_mod_store_path, config.name, "mod.json" }));
 }
开发者ID:ModulousSmash,项目名称:ModulousMM,代码行数:19,代码来源:Mod.cs

示例13: install_mod_from_metafile

        public static void install_mod_from_metafile(ModConfig config, int id = 0)
        {
            Directory.CreateDirectory(Globals.temporary_path);
            /*
             * Runs the installation thread.
             */
            if (config.requires_brawlex == true)
            {
                if (!File.Exists(Path.Combine(SDCard.sd_card_path, "private/wii/app/RSBE/pf/BrawlEx/CSSRoster.dat")))
                {
                    TopMostMessageBox.Show("BrawlEX + CSS Extension is required for this mod to install.", "BrawlEX Error");

                    return;
                }
                if (!Directory.Exists(Path.Combine(SDCard.sd_card_path, "private/wii/app/RSBE/pf/BrawlEx/CosmeticConfig")));
                {
                    Directory.CreateDirectory(Path.Combine(SDCard.sd_card_path, "private/wii/app/RSBE/pf/BrawlEx/CosmeticConfig"));
                }
                if (!Directory.Exists(Path.Combine(SDCard.sd_card_path, "private/wii/app/RSBE/pf/BrawlEx/CSSSlotConfig")));
                {
                    Directory.CreateDirectory(Path.Combine(SDCard.sd_card_path, "private/wii/app/RSBE/pf/BrawlEx/CSSSlotConfig"));
                }
                if (!Directory.Exists(Path.Combine(SDCard.sd_card_path, "private/wii/app/RSBE/pf/BrawlEx/FighterConfig")));
                {
                    Directory.CreateDirectory(Path.Combine(SDCard.sd_card_path,
                        "private/wii/app/RSBE/pf/BrawlEx/FighterConfig"));
                }
                if (!Directory.Exists(Path.Combine(SDCard.sd_card_path, "private/wii/app/RSBE/pf/BrawlEx/SlotConfig")));
                {
                    Directory.CreateDirectory(Path.Combine(SDCard.sd_card_path,
                        "private/wii/app/RSBE/pf/BrawlEx/SlotConfig"));
                }
            }
            var state = new Lua();
            state.LoadCLRPackage();
            Globals.current_mod_config = config;
            state.DoFile(Path.Combine(Globals.AssemblyDirectory, "data/lua/init.lua"));
            state.DoFile(Path.Combine(Globals.temporary_path, config.install_script));
            Directory.CreateDirectory(Path.Combine(new string[] {SDCard.sd_card_mod_store_path, config.name}));
            var json_contents = File.ReadAllText(Path.Combine(Globals.temporary_path, "mod.json"));
            var mod = JsonConvert.DeserializeObject<ModConfig>(json_contents);
            mod.id = id;
            if (id != 0)
            {
                mod.online_mod = true;
            }
            var content = JsonConvert.SerializeObject(mod, Formatting.Indented);
            File.WriteAllText(Path.Combine(Globals.temporary_path, "mod.json"), content);
            File.Copy(Path.Combine(Globals.temporary_path, "mod.json"),
                Path.Combine(new string[] {SDCard.sd_card_mod_store_path, config.name, "mod.json"}));
            File.Copy(Path.Combine(Globals.temporary_path, "init.lua"),
                Path.Combine(new string[] { SDCard.sd_card_mod_store_path, config.name, "init.lua" }));
        }
开发者ID:ModulousSmash,项目名称:ModulousMM,代码行数:53,代码来源:Mod.cs

示例14: LoadRecipes

		public static void LoadRecipes()
		{
			using (Lua lua = new Lua())
			{
				List<String> luaFiles = getAllLuaFiles().ToList();
				List<String> luaDirs = getAllModDirs().ToList();

				//Add all these files to the Lua path variable
				foreach (String dir in luaDirs)
				{
					AddLuaPackagePath(lua, dir); //Prototype folder matches package hierarchy so this is enough.
				}

				AddLuaPackagePath(lua, Path.Combine(luaDirs[0], "lualib")); //Add lualib dir

				String dataloaderFile = luaFiles.Find(f => f.EndsWith("dataloader.lua"));
				String autoplaceFile = luaFiles.Find(f => f.EndsWith("autoplace_utils.lua"));

				List<String> itemFiles = luaFiles.Where(f => f.Contains("prototypes" + Path.DirectorySeparatorChar + "item")).ToList();
				itemFiles.AddRange(luaFiles.Where(f => f.Contains("prototypes" + Path.DirectorySeparatorChar + "fluid")).ToList());
				itemFiles.AddRange(luaFiles.Where(f => f.Contains("prototypes" + Path.DirectorySeparatorChar + "equipment")).ToList());
				List<String> recipeFiles = luaFiles.Where(f => f.Contains("prototypes" + Path.DirectorySeparatorChar + "recipe")).ToList();
				List<String> entityFiles = luaFiles.Where(f => f.Contains("prototypes" + Path.DirectorySeparatorChar + "entity")).ToList();
				
				try
				{
					lua.DoFile(dataloaderFile);
				}
				catch (Exception e)
				{
					failedFiles[dataloaderFile] = e;
					return; //There's no way to load anything else without this file.
				}
				try
				{
					lua.DoFile(autoplaceFile);
				}
				catch (Exception e)
				{
					failedFiles[autoplaceFile] = e;
				}
				foreach (String f in itemFiles.Union(recipeFiles).Union(entityFiles))
				{
					try
					{
						lua.DoFile(f);
					}
					catch (NLua.Exceptions.LuaScriptException e)
					{
						failedFiles[f] = e;
					}
				}

				foreach (String type in new List<String> { "item", "fluid", "capsule", "module", "ammo", "gun", "armor", "blueprint", "deconstruction-item" })
				{
					InterpretItems(lua, type);
				}

				LuaTable recipeTable = lua.GetTable("data.raw")["recipe"] as LuaTable;
				if (recipeTable != null)
				{
					var recipeEnumerator = recipeTable.GetEnumerator();
					while (recipeEnumerator.MoveNext())
					{
						InterpretLuaRecipe(recipeEnumerator.Key as String, recipeEnumerator.Value as LuaTable);
					}
				}

				LuaTable assemblerTable = lua.GetTable("data.raw")["assembling-machine"] as LuaTable;
				if (assemblerTable != null)
				{
					var assemblerEnumerator = assemblerTable.GetEnumerator();
					while (assemblerEnumerator.MoveNext())
					{
						InterpretAssemblingMachine(assemblerEnumerator.Key as String, assemblerEnumerator.Value as LuaTable);
					}
				}

				LuaTable furnaceTable = lua.GetTable("data.raw")["furnace"] as LuaTable;
				if (furnaceTable != null)
				{
					var furnaceEnumerator = furnaceTable.GetEnumerator();
					while (furnaceEnumerator.MoveNext())
					{
						InterpretFurnace(furnaceEnumerator.Key as String, furnaceEnumerator.Value as LuaTable);
					}
				}

				LuaTable minerTable = lua.GetTable("data.raw")["mining-drill"] as LuaTable;
				if (minerTable != null)
				{
					var minerEnumerator = minerTable.GetEnumerator();
					while (minerEnumerator.MoveNext())
					{
						InterpretMiner(minerEnumerator.Key as String, minerEnumerator.Value as LuaTable);
					}
				}

				LuaTable resourceTable = lua.GetTable("data.raw")["resource"] as LuaTable;
				if (resourceTable != null)
//.........这里部分代码省略.........
开发者ID:w-flo,项目名称:foreman-pkg,代码行数:101,代码来源:DataCache.cs

示例15: LoadSingleScript

        /// <summary>
        /// Load a single script from the specified manifest.
        /// </summary>
        private void LoadSingleScript(string path, ScriptManifest manifest)
        {
            string scriptFile = Path.Combine(path, manifest.ScriptFile);

            NLua.Lua lua = new NLua.Lua();
            lua.LoadCLRPackage();
            _luaAPI.RegisterFunctions(lua);
            bool success = true;
            try
            {
                lua.DoFile(scriptFile);
                LuaFunction fnc = lua.GetFunction("on_load");
                if (fnc != null)
                {
                    object[] res = fnc.Call();
                    if (res != null && res.Length == 1)
                    {
                        success = Convert.ToBoolean(res[0]);
                    }
                }

                // Cache this script object for event callbacks if the
                // init function returns success.
                if (success)
                {
                    if (_scriptObjects.ContainsKey(scriptFile))
                    {
                        // BUGBUG: What if we have scripts that register events? We need to tell
                        // them to unregister first. Add an interface for this.
                        NLua.Lua oldScript = _scriptObjects[scriptFile];
                        oldScript.Dispose();

                        _scriptObjects.Remove(scriptFile);
                    }
                    _scriptObjects.Add(scriptFile, lua);
                }

                if (manifest.InstallToToolbar)
                {
                    ToolbarDataItem item = new ToolbarDataItem
                    {
                        type = "button",
                        name = "Script",
                        label = manifest.Name,
                        tooltip = manifest.Description,
                        data = scriptFile,
                        image = manifest.IconFile
                    };
                    CRToolbarItemCollection.DefaultCollection.Add(item);
                }
            }
            catch (Exception e)
            {
                LogFile.WriteLine("Error loading script {0} : {1}", scriptFile, e.Message);
                success = false;
            }
            if (success)
            {
                LogFile.WriteLine("Loaded and initialised script {0}", scriptFile);
            }
            else
            {
                lua.Dispose();
            }
        }
开发者ID:cixonline,项目名称:cixreader,代码行数:68,代码来源:ScriptManager.cs


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