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


C# Lua.DoFile方法代码示例

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


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

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

示例2: Init

 public void Init(string strAPIInfoFile)
 {
     m_strCode = "";
     m_strAPIInfoFile = strAPIInfoFile;
     m_lua = new Lua();
     m_lua.DoFile(m_strAPIInfoFile);
     m_luatable = m_lua.GetTable("APIInfo");
     m_nClassCount = m_luatable.Keys.Count;
     m_strClass = new string[m_nClassCount];
     m_strClassInCode = new string[m_nClassCount];
     m_strIniFileName = Application.StartupPath + "\\Plugins\\LuaCheck\\API.temp.lua";
     m_lua1 = new Lua();
     m_lua1.DoFile(m_strIniFileName);
     int n = 0;
     foreach (string str in m_luatable.Keys)
     {
         m_strClass[n] = (string)(((LuaTable)m_luatable[str])["Name"]);
         n++;
     }
     
     //object ob;
     //foreach (ob in m_luatable)
     //{
     //    strClass[] = ((LuaTable)ob)["Name"];
     
     //}
     //object ob = m_luatable["1"];
     //object ob1 = ((LuaTable)ob)["Name"];
 }
开发者ID:viticm,项目名称:pap2,代码行数:29,代码来源:CodeBuilder.cs

示例3: GUIAddon

        public GUIAddon(string a_filePath)
        {
            m_lua = new Lua();
            ((GameState)Game.getInstance().getCurrentState()).getGUI().registerFunctions(m_lua);
            m_lua.DoFile(a_filePath);

            m_onLoad = m_lua.GetFunction("OnLoad");
            m_onUpdate = m_lua.GetFunction("OnUpdate");
            m_onDraw = m_lua.GetFunction("OnDraw");
        }
开发者ID:Joxe,项目名称:TacticsRPG,代码行数:10,代码来源:GuiElement.cs

示例4: Init

 /// <summary>
 /// 初始化数据
 /// </summary>
 private void Init()
 {
     string luaFile = Path.Combine(Application.StartupPath, "ConfigEdit.lua");
     FileInfo fi = new FileInfo(luaFile);
     if(fi.Exists)
     {
         lua = new Lua();
         lua.DoFile(luaFile);
     }
 }
开发者ID:viticm,项目名称:pap2,代码行数:13,代码来源:LogicManager.cs

示例5: Reload

        public static bool Reload(string assets_root)
        {
            FLua = new Lua();

            string path = assets_root + "scripts/dt_all.lua";

            Directory.SetCurrentDirectory(assets_root + "../");

            FLua.DoFile(path);

            return true;
        }
开发者ID:lythm,项目名称:orb3d,代码行数:12,代码来源:LuaUtil.cs

示例6: Start

 internal bool Start(string initfile)
 {
     lua = new LuaInterface.Lua();
     lua["server"] = server;
     lua.RegisterFunction("Is",this,this.GetType().GetMethod("Is"));
     if (!File.Exists(initfile)) {
         server.Log("Initfile '"+initfile+"' not found.");
         return false;
     } try { lua.DoFile(initfile); }
     catch (Exception e) { Error(e); return false; }
     return true;
 }
开发者ID:welterde,项目名称:obsidian,代码行数:12,代码来源:Lua.cs

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

示例8: 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:lenzener,项目名称:LuaInterface,代码行数:51,代码来源:LuaNetRunner.cs

示例9: API

        public API()
        {
            Log.log("API constructed");

            try
            {
                lua = new Lua();

                Log.log("Setting script path...");
                string lua_script_path = Plugin.getBothPath() + "LuaScripts/";
                lua["script_path"] = lua_script_path;
                Log.log("Done");

                // Print to screen
                lua.RegisterFunction("__csharp_print_to_log", this, typeof(API).GetMethod("__csharp_print_to_log"));

                // Game functions
                // Query for cards
                lua.RegisterFunction("__csharp_cards", this, typeof(API).GetMethod("getCards"));
                lua.RegisterFunction("__csharp_card", this, typeof(API).GetMethod("getCard"));
                // Query the number of crystals
                lua.RegisterFunction("__csharp_crystals", this, typeof(API).GetMethod("getCrystals"));

                // Query about entities
                lua.RegisterFunction("__csharp_entity_bool", this, typeof(API).GetMethod("getEntityBool"));
                lua.RegisterFunction("__csharp_entity_value", this, typeof(API).GetMethod("getEntityValue"));

                // Utility functions
                lua.RegisterFunction("__csharp_convert_to_entity", this, typeof(API).GetMethod("__csharp_convert_to_entity"));

                // Function for creating actions (returned by turn_action function)
                lua.RegisterFunction("__csharp_play_card", this, typeof(API).GetMethod("PlayCard"));
                lua.RegisterFunction("__csharp_attack_enemy", this, typeof(API).GetMethod("AttackEnemy"));

                Log.log("Loading Main.lua...");
                lua.DoFile(lua_script_path + "Main.lua");
                Log.log("Done");
            }
            catch(LuaException e)
            {
                Log.error("EXCEPTION");
                Log.error(e.ToString());
                Log.error(e.Message);
            }
            catch(Exception e)
            {
                Log.error(e.ToString());
            }
            Log.log("Scripts loaded constructed");
        }
开发者ID:resaka,项目名称:HearthstoneBot,代码行数:50,代码来源:API.cs

示例10: ScriptNode

        public ScriptNode(GameEntity gameEntity, string url)
        {
            mUrl = url;
            mScript = new Lua();

            AddFunctions(typeof(ScriptFunctions));
            AddFunctions(typeof(MilkHooks));

            mScript["gameObject"] = gameEntity;
            mScript["scene"] = Scene;
            attatchListeners(gameEntity);

            mScript.DoFile("Scripts//" + mUrl);
        }
开发者ID:eickegao,项目名称:MilkShake,代码行数:14,代码来源:ScriptNode.cs

示例11: load

        /// <summary>
        /// Loads a world from a lua file
        /// </summary>
        /// <param name="filename">file to load the world from</param>
        /// <returns>true on success</returns>
        public bool load(string filename)
        {
            this.fname = filename;

            Lua lua = new Lua();
            var result = lua.DoFile(filename);
            foreach (DictionaryEntry member in lua.GetTable("world_data"))
            {
                if (member.Key.ToString() == "width")
                {
                    this.width = Convert.ToInt32(member.Value);
                }
                else if (member.Key.ToString() == "height")
                {
                    this.height = Convert.ToInt32(member.Value);
                }
                if (member.Key.ToString() == "paths")
                {
                    collision_segment = new ArrayList();
                    LuaTable paths = (LuaTable)member.Value;
                    foreach (DictionaryEntry path in paths)
                    {
                        ArrayList collision_path = new ArrayList();
                        LuaTable p = (LuaTable)path.Value;
                        foreach (DictionaryEntry point in p)
                        {
                            LuaTable point_data = (LuaTable)point.Value;
                            int x = Convert.ToInt32(point_data.Values.Cast<double>().ElementAt(0) * ppu);
                            int y = Convert.ToInt32(point_data.Values.Cast<double>().ElementAt(1) * ppu);
                            Console.WriteLine("X:" + x + ", Y:" + y);
                            collision_path.Add(new Point(x, y));
                        }
                        collision_segment.Add(collision_path);
                    }

                }
            }
            return true;
        }
开发者ID:didius,项目名称:platinumEditor,代码行数:44,代码来源:World.cs

示例12: IsBotTemplate

        private bool IsBotTemplate(string file)
        {
            LuaInterface.Lua lua = new LuaInterface.Lua();

            try
            {

                lua.DoFile(file);

                LuaFunction on_event = lua.GetFunction("OnEvent");

                if(on_event == null)
                    return false;

                return true;
            }
            catch (Exception e)
            {
                AppContext.WriteLog(e.Message);
                return false;
            }
        }
开发者ID:lythm,项目名称:orb3d,代码行数:22,代码来源:BotTemplateList.cs

示例13: Initialise

        public static void Initialise(string script_name)
        {
            try
            {
                Console.WriteLine("Initializing lua...");

                _manager = new Lua();
                _functions = new LuaFunctions();

                try
                {
                    _manager.RegisterFunction("PrintToConsole", _functions, _functions.GetType().GetMethod("PrintToConsole"));
                    _manager.RegisterFunction("PrintToChat", _functions, _functions.GetType().GetMethod("PrintToChat"));
                }
                catch
                {
                    Console.WriteLine("Oof. Registering functions shouldnt have failed.");
                }

                try
                {
                    _manager.DoFile(script_name);
                }
                catch
                {
                    Console.WriteLine("Error opening the script.");
                }
                _initialised = true;
                _filename = script_name;
            }
            catch
            {
                Console.WriteLine("Error initialising lua");
                _initialised = false;
            }
        }
开发者ID:Genesis999,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:36,代码来源:LuaManager.cs

示例14: OnActivate

        public void OnActivate()
        {
            // Create the lua state
            luastate = new Lua();

            // Setup hooks
            dctHooks = new Dictionary<string, List<LuaFunction>>();

            // Bind functions
            BindFunction("print", "print");

            luastate.NewTable("hook");
            BindFunction("hook.Add", "hook_Add");

            luastate.NewTable("library");
            BindFunction("library.AddWeapon", "library_AddWeapon");
            BindFunction("library.AddSystem", "library_AddSystem");
            BindFunction("library.AddRace", "library_AddRace");
            BindFunction("library.AddShipGenerator", "library_AddShipGenerator");
            BindFunction("library.AddSectorMapGenerator", "library_AddSectorMapGenerator");
            BindFunction("library.GetWeapon", "library_GetWeapon");
            BindFunction("library.GetSystem", "library_GetSystem");
            BindFunction("library.GetRace", "library_GetRace");
            BindFunction("library.GetShip", "library_GetShipGenerator");
            BindFunction("library.GetSectorMapGenerator", "library_GetSectorMapGenerator");
            BindFunction("library.CreateAnimation", "library_CreateAnimation");

            luastate.NewTable("ships");
            BindFunction("ships.NewDoor", "ships_NewDoor"); // Is there any way to call the constructor directly from lua code?

            // Load lua files
            if (!Directory.Exists("lua")) Directory.CreateDirectory("lua");
            foreach (string name in Directory.GetFiles("lua"))
                luastate.DoFile("lua/" + name);
        }
开发者ID:danielrh,项目名称:ftl-overdrive,代码行数:35,代码来源:ModdingAPI.cs

示例15: RunLua

        private void RunLua(object obj)
        {
            try
            {
                string luaFile = obj as string;
                Lua luaVM = new Lua();

                luaVM.RegisterFunction("FMSignal", this, this.GetType().GetMethod("FMSignal"));
                luaVM.RegisterFunction("Single", this, this.GetType().GetMethod("Single"));
                luaVM.RegisterFunction("Output", this, this.GetType().GetMethod("Output"));
                luaVM.RegisterFunction("OutputLine", this, this.GetType().GetMethod("OutputLine"));
                luaVM.RegisterFunction("Sleep", this, this.GetType().GetMethod("Sleep"));
                luaVM.RegisterFunction("SetAcVolt", this, this.GetType().GetMethod("SetAcVolt"));
                luaVM.RegisterFunction("SetDcVolt", this, this.GetType().GetMethod("SetDcVolt"));
                luaVM.RegisterFunction("SetAcCurrent", this, this.GetType().GetMethod("SetAcCurrent"));
                luaVM.RegisterFunction("SetDcCurrent", this, this.GetType().GetMethod("SetDcCurrent"));
                luaVM.RegisterFunction("MeterValue", this, this.GetType().GetMethod("MeterValue"));

                luaVM.DoFile(luaFile);


                luaVM.Close();
            }
            catch (Exception)
            {

            }
            finally
            {
                /*
                this.Invoke(new MethodInvoker(delegate
                {

                     this.buttonLuaRun.Text = "运行脚本";
                }));
                 * */
                if (this.IsHandleCreated)
                {
                    MethodInvoker meth = new MethodInvoker(delegate
                    {
                        this.buttonLuaRun.Text = "运行脚本";
                    });

                    this.BeginInvoke(meth);
                }

            }

        }
开发者ID:tsinfeng,项目名称:EnjoyTest,代码行数:49,代码来源:AFGWin.cs


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