Esempio n. 1
0
        public void HandleFile(string file)
        {
            if (!System.IO.File.Exists(file))
                return;
			try
			{
				FileStream fileStream = System.IO.File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

				using (StreamReader reader = new StreamReader(fileStream))
				{
					var parser = new Parser(LuaGrammar.Instance);
					var tree = parser.Parse(reader.ReadToEnd());
					var root = tree.Root;
					if (root != null)
					{
						File = new LuaFile(file, tree.Tokens);
						RefreshTree(root);
						FileManager.Instance.AddFile(File);
					}
					else
					{
						System.Diagnostics.Debug.Print("***********error***********" + file);
					}
				}
			}
			catch(Exception e) 
			{
				BabePackage.Setting.LogError("open file failed:" + e.GetType().FullName);
			}
        }
 public INamedLuaFunction CreateAndRegisterNamedFunction(
     LuaFunction function,
     string theEvent,
     Action <string> logCallback,
     LuaFile luaFile,
     [LuaArbitraryStringParam] string name = null)
 => null;
Esempio n. 3
0
 public LuaWinform(LuaFile ownerFile, PlatformEmuLuaLibrary luaImp)
 {
     _ownerFile = ownerFile;
     _luaImp    = luaImp;
     InitializeComponent();
     StartPosition = FormStartPosition.CenterParent;
     Closing      += (o, e) => CloseThis();
 }
Esempio n. 4
0
 public LuaWinform(LuaFile ownerFile, Action <IntPtr> formsWindowClosedCallback)
 {
     _ownerFile = ownerFile;
     InitializeComponent();
     Icon          = Properties.Resources.TextDocIcon;
     StartPosition = FormStartPosition.CenterParent;
     Closing      += (o, e) => formsWindowClosedCallback(Handle);
 }
Esempio n. 5
0
    byte[] OnLoad(string fn, ref string absoluteFn)
    {
        string path = LuaFile.FindFile(fn.Replace('.', '/'));

        byte[] bytes = LuaFile.ReadBytes(path);

        return bytes;
    }
Esempio n. 6
0
        private static void Extract(string name, string[] ignore = null)
        {
            DisplayMessage("Generating files for " + name + "...");

#if !DEBUG
            try
            {
#endif
            var xml = new XDocument(new XDeclaration("1.0", "utf-8", null), new XElement(name));
            var lua = new LuaFile(name);

            foreach (var obj in model[name])
            {
                if (!IsValidName(ignore ?? new string[] {}, obj))
                {
                    continue;
                }

                var xmlelement = new XElement("o");
                foreach (var pair in obj)
                {
                    //TODO: Level dictionaries are currently messed up on XML output
                    if (pair.Key.StartsWith("_"))
                    {
                        continue;
                    }

                    if (!(pair.Value is string) && pair.Value is IEnumerable)
                    {
                        xmlelement.SetAttributeValue(pair.Key, LuaAttribute.MakeValue(pair.Value));
                    }
                    else
                    {
                        xmlelement.SetAttributeValue(pair.Key, pair.Value);
                    }
                }

                xml.Root.Add(xmlelement);
                lua.Add(obj);
            }

            xml.Root.ReplaceNodes(xml.Root.Elements().OrderBy(e => (uint)((int?)e.Attribute("id") ?? 0)));

            xml.Save(Path.Combine("resources", "xml", FormattableString.Invariant($"{name}.xml")));
            lua.Save();

#if !DEBUG
        }

        catch
        {
            DisplayError();
            throw;
        }
#endif

            DisplaySuccess();
        }
Esempio n. 7
0
 public LuaWinform(LuaFile ownerFile, LuaLibraries luaImp)
 {
     _ownerFile = ownerFile;
     _luaImp    = luaImp;
     InitializeComponent();
     Icon          = Properties.Resources.TextDocIcon;
     StartPosition = FormStartPosition.CenterParent;
     Closing      += (o, e) => { _luaImp.WindowClosed(Handle); };
 }
Esempio n. 8
0
		public void AddFile(LuaFile file)
		{
			var index = Files.IndexOf(file);
			if (index != -1) Files[index] = file;
			else
			{
				Files.Add(file);
			}
		}
Esempio n. 9
0
 public LuaWinform(LuaFile ownerFile, LuaLibraries luaImp)
 {
     _ownerFile = ownerFile;
     _luaImp    = luaImp;
     InitializeComponent();
     Icon          = Properties.Resources.textdoc_MultiSize;
     StartPosition = FormStartPosition.CenterParent;
     Closing      += (o, e) => CloseThis();
 }
Esempio n. 10
0
        public void LoadLuaFile(string path)
        {
            var    processedPath = PathManager.TryMakeRelative(path);
            string pathToLoad    = Path.IsPathRooted(processedPath) ? processedPath : PathManager.MakeProgramRelativePath(processedPath);          //JUNIPIER SQUATCHBOX COMPLEX

            if (LuaAlreadyInSession(processedPath) == false)
            {
                var luaFile = new LuaFile(string.Empty, processedPath);

                _luaList.Add(luaFile);
                LuaListView.ItemCount = _luaList.Count;
                Global.Config.RecentLua.Add(processedPath);

                if (!Global.Config.DisableLuaScriptsOnLoad)
                {
                    try
                    {
                        LuaSandbox.Sandbox(null, () =>
                        {
                            luaFile.Thread = LuaImp.SpawnCoroutine(pathToLoad);
                            LuaSandbox.CreateSandbox(luaFile.Thread, Path.GetDirectoryName(pathToLoad));
                            luaFile.State = LuaFile.RunState.Running;
                        }, () =>
                        {
                            luaFile.State = LuaFile.RunState.Disabled;
                        });
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString());
                    }
                }
                else
                {
                    luaFile.State = LuaFile.RunState.Disabled;
                }

                if (Global.Config.LuaReloadOnScriptFileChange)
                {
                    CreateFileWatcher(processedPath);
                }

                //luaFile.Paused = false;
            }
            else
            {
                foreach (var file in _luaList.Where(file => processedPath == file.Path && file.Enabled == false && !Global.Config.DisableLuaScriptsOnLoad))
                {
                    file.Toggle();
                    break;
                }

                RunLuaScripts();
            }

            UpdateDialog();
        }
Esempio n. 11
0
 public void CallExitEvent(LuaFile lf)
 {
     foreach (var exitCallback in RegisteredFunctions
              .Where(l => l.Event == "OnExit" && (l.LuaFile.Path == lf.Path || l.LuaFile.Thread == lf.Thread)))
     {
         exitCallback.Call();
     }
     GuiAPI.ThisIsTheLuaAutounlockHack();
 }
Esempio n. 12
0
        static void Main(string[] args)
        {
            LasmParser p    = new LasmParser();
            LuaFile    file = p.Parse(@"
        .const ""print""
        .const ""Hello""
        getglobal 0 0
        loadk 1 1
        call 0 2 1
        return 0 1
        ");

            file.StripDebugInfo();
            string code = file.Compile();

            try
            {
                LuaFile f = Disassembler.Disassemble(code);
                System.IO.FileStream fs = new System.IO.FileStream("lasm.luac", System.IO.FileMode.Create);
                //foreach (char c in code)
                foreach (char c in f.Compile())
                {
                    fs.WriteByte((byte)c);
                }
                fs.Close();

                // Test chunk compiling/loading
                string s    = f.Main.Compile(f);
                Chunk  chnk = Disassembler.DisassembleChunk(s);

                // Test execution of code
                string s2 = f.Compile();
                LuaRuntime.Run(s2);
                LuaRuntime.Run(code);
                Console.WriteLine("The above line should say 'Hello'. If it doesn't there is an error.");
                Console.WriteLine(LASMDecompiler.Decompile(file));
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            try
            {
                LuaFile lf = p.Parse("breakpoint 0 0 0");
                LuaRuntime.Run(lf.Compile());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine("Test(s) done. Press any key to continue.");
            Console.ReadKey(true);
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            List <Terminal> l_terminals = new List <Terminal>();

            l_terminals.Add(new EOLTerminal());
            TokenParser.Instance.SetTerminals(l_terminals);
            string  l_filePath = "E:\\Work\\LuaUnity\\Assets\\Lua\\View\\Intents\\AdventureIntent.lua";
            LuaFile l_file     = new LuaFile(l_filePath);

            l_file.Parser();
        }
Esempio n. 14
0
        public void LoadLuaFile(string path)
        {
            var processedPath = PathManager.TryMakeRelative(path);

            if (LuaAlreadyInSession(processedPath) == false)
            {
                var luaFile = new LuaFile(string.Empty, processedPath);

                _luaList.Add(luaFile);
                LuaListView.ItemCount = _luaList.Count;
                Global.Config.RecentLua.Add(processedPath);


                if (!Global.Config.DisableLuaScriptsOnLoad)
                {
                    try
                    {
                        luaFile.Thread  = LuaImp.SpawnCoroutine(processedPath);
                        luaFile.Enabled = true;
                    }
                    catch (Exception e)
                    {
                        if (e.GetType() == typeof(LuaInterface.LuaScriptException))
                        {
                            luaFile.Enabled = false;
                            ConsoleLog(e.Message);
                        }
                        else
                        {
                            MessageBox.Show(e.ToString());
                        }
                    }
                }
                else
                {
                    luaFile.Enabled = false;
                }

                luaFile.Paused = false;
            }
            else
            {
                foreach (var file in _luaList.Where(file => processedPath == file.Path && file.Enabled == false && !Global.Config.DisableLuaScriptsOnLoad))
                {
                    file.Toggle();
                    break;
                }

                RunLuaScripts();
            }

            UpdateDialog();
        }
Esempio n. 15
0
    public static SpellAction ParseAndCreateSpell(string fileName)
    {
        if (allAbilites == null)
        {
            allAbilites = new Dictionary <string, SpellAction>();
        }

        LuaFile file = new LuaFile();

        file.Setup("Spells/" + fileName);
        SpellAction newSpell = new SpellAction();

        newSpell.name         = file.GetValue("Name").ToString();
        newSpell.targetType   = (TargetType)Convert.ToInt32(file.GetValue("TargetType"));
        newSpell.targetFilter = (TargetFilter)Convert.ToInt32(file.GetValue("TargetFilter"));
        newSpell.targetRange  = (TargetRange)Convert.ToInt32(file.GetValue("TargetRange"));
        newSpell.targetAOE    = (TargetAOE)Convert.ToInt32(file.GetValue("TargetAOE"));
        if (newSpell.targetRange == TargetRange.Range)
        {
            newSpell.range = Convert.ToInt32(file.GetValue("Range"));
        }
        else
        {
            newSpell.range = 1;
        }

        Table table = (Table)file.GetValue("Events");
        Table insideTable;

        foreach (DynValue dy in table.Values)
        {
            insideTable = dy.Table;
            switch (insideTable.Get("Type").String)
            {
            case "DamageEvent":
                newSpell.protoEvents.Add(DamageEventPrototype.Builder(insideTable));
                break;

            case "SpawnEvent":
                newSpell.protoEvents.Add(SpawnEventPrototype.Builder(insideTable));
                break;

            case "BuffCastEvent":
                newSpell.protoEvents.Add(BuffCastEventPrototype.Builder(insideTable));
                break;

            default:
                break;
            }
        }
        return(newSpell);
    }
Esempio n. 16
0
        public static LuaState InitTestEnv()
        {
            LuaFile.SetPathHook((fileName) => Path.Combine(LuaPath, fileName));
            ULDebug.Log      = Console.WriteLine;
            ULDebug.LogError = Console.Error.WriteLine;

            var luaState = new LuaState();

            luaState.L_OpenLibs();
            luaState.OpenToLua();

            return(luaState);
        }
Esempio n. 17
0
 void create_state()
 {
     if (_luaState == null)
     {
         LuaFile.SetPathHook(path_hook);
         _luaState = LuaAPI.NewState();
         _luaState.L_OpenLibs();
         _luaState.L_DoString(_waitFunc);
         register_default_functions();
         register_common_libs();
         register_libs();
     }
 }
Esempio n. 18
0
        public void LoadLuaFile(string path)
        {
            var processedPath = PathManager.TryMakeRelative(path);

            if (LuaAlreadyInSession(processedPath) == false)
            {
                var luaFile = new LuaFile(string.Empty, processedPath);

                _luaList.Add(luaFile);
                LuaListView.ItemCount = _luaList.Count;
                Global.Config.RecentLua.Add(processedPath);


                if (!Global.Config.DisableLuaScriptsOnLoad)
                {
                    try
                    {
                        LuaSandbox.Sandbox(() =>
                        {
                            luaFile.Thread = LuaImp.SpawnCoroutine(processedPath);
                            luaFile.State  = LuaFile.RunState.Running;
                        }, () =>
                        {
                            luaFile.State = LuaFile.RunState.Disabled;
                        });
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString());
                    }
                }
                else
                {
                    luaFile.State = LuaFile.RunState.Disabled;
                }

                //luaFile.Paused = false;
            }
            else
            {
                foreach (var file in _luaList.Where(file => processedPath == file.Path && file.Enabled == false && !Global.Config.DisableLuaScriptsOnLoad))
                {
                    file.Toggle();
                    break;
                }

                RunLuaScripts();
            }

            UpdateDialog();
        }
Esempio n. 19
0
    public static SLua.ByteArray LoadLuaAsset(string name)
    {
        string file = LuaFile.FindFile(name);

        if (string.IsNullOrEmpty(file) == false)
        {
            byte[]         bytes = LuaFile.ReadBytes(file);
            SLua.ByteArray array = new SLua.ByteArray();
            array.Write(bytes);

            return(array);
        }
        return(null);
    }
Esempio n. 20
0
        public void Refresh(ParseTree tree)
        {
            var root = tree.Root;
            if (root != null)
            {
                File = new LuaFile(FileManager.Instance.CurrentFile.File, tree.Tokens); ;

                RefreshTree(root);

                FileManager.Instance.CurrentFile = File;

                System.Diagnostics.Debug.Print("file refreshed.");
            }
        }
Esempio n. 21
0
        public Function(LuaFile luaFile)
        {
            LuaFile = luaFile;

            FunctionPos = luaFile.Reader.BaseStream.Position;
            luaFile.ReadFunctionHeader(this);

            for (int i = 0; i < InstructionCount; i++)
            {
                Instructions.Add(luaFile.ReadInstruction(this));
            }
            luaFile.ReadConstants(this);
            luaFile.ReadFunctionFooter(this);
            luaFile.ReadSubFunctions(this);
        }
Esempio n. 22
0
 private void CheckFileMode(LuaFile file, string format, LuaFileOpenMode expectedMode, LuaFileContentType expectedType)
 {
     if (file.ContentType != expectedType || file.OpenMode != expectedMode)
     {
         throw new LuaError(string.Format(
                                "Incorrect file mode for format {0}. Expected {1}, got {2}",
                                format,
                                GetFileModeString(expectedMode, expectedType),
                                GetFileModeString(file.OpenMode, file.ContentType)
                                ));
     }
     if (!file.IsOpen)
     {
         throw new LuaError("File is closed");
     }
 }
Esempio n. 23
0
    public static SpellAction ParseAndCreateSpell(string fileName)
    {
        if (allAbilites == null)
            allAbilites = new Dictionary<string, SpellAction>();

        LuaFile file = new LuaFile();
        file.Setup( "Spells/" + fileName);
        SpellAction newSpell = new SpellAction();
        newSpell.name = file.GetValue("Name").ToString();
        newSpell.targetType = (TargetType)Convert.ToInt32(file.GetValue("TargetType"));
        newSpell.targetFilter = (TargetFilter)Convert.ToInt32(file.GetValue("TargetFilter"));
        newSpell.targetRange = (TargetRange)Convert.ToInt32(file.GetValue("TargetRange"));
        newSpell.targetAOE = (TargetAOE)Convert.ToInt32(file.GetValue("TargetAOE"));
        if(newSpell.targetRange == TargetRange.Range)
        {
            newSpell.range = Convert.ToInt32(file.GetValue("Range"));
        }
        else
        {
            newSpell.range = 1;
        }

        Table table = (Table)file.GetValue("Events");
        Table insideTable;
        foreach(DynValue dy in table.Values)
        {
            insideTable = dy.Table;
            switch (insideTable.Get("Type").String)
            {
                case "DamageEvent":
                    newSpell.protoEvents.Add(DamageEventPrototype.Builder(insideTable));
                    break;
                case "SpawnEvent":
                    newSpell.protoEvents.Add(SpawnEventPrototype.Builder(insideTable));
                    break;
                case "BuffCastEvent":
                    newSpell.protoEvents.Add(BuffCastEventPrototype.Builder(insideTable));
                    break;
                default:
                    break;
            }

        }
            return newSpell;
    }
Esempio n. 24
0
        private static void Extract(string name, string[] ignore = null)
        {
            DisplayMessage("Generating files for " + name + "...");

#if !DEBUG
            try
            {
#endif
            XDocument xml = new XDocument(new XDeclaration("1.0", "utf-8", null), new XElement(name));
            LuaFile lua   = new LuaFile(name);

            foreach (dynamic obj in model[name])
            {
                if (IsValidName(ignore ?? new string[] { }, obj))
                {
                    XElement xmlelement = new XElement("o");
                    foreach (var pair in obj)
                    {
                        //TODO: Level dictionaries are currently messed up on XML output
                        xmlelement.SetAttributeValue(pair.Key, pair.Value);
                    }

                    xml.Root.Add(xmlelement);
                    lua.Add(obj);
                }
            }

            xml.Root.ReplaceNodes(xml.Root.Elements().OrderBy(e => (uint)((int?)e.Attribute("id") ?? 0)));

            xml.Save(Path.Combine("resources", "xml", string.Format(CultureInfo.InvariantCulture, "{0}.xml", name)));
            lua.Save();

#if !DEBUG
        }

        catch
        {
            DisplayError();
            throw;
        }
#endif

            DisplaySuccess();
        }
Esempio n. 25
0
    // Use this for initialization
    void Start()
    {
        if (LuaFile.assetmode == 1)
        {
            var luabundle = AssetBundle.LoadFromFile(Application.dataPath + "/../StreamingAssets/lua.unity3d");
            LuaFile.AddLuaBundle(luabundle);
        }
        else
        {
            LuaFile.AddSearchPath(Application.dataPath + "/R/Lua",true); //lua逻辑代码目录

        }
        Application.logMessageReceived += OnLog;
        l = new LuaSvr();

        LuaSvr.mainState.loaderDelegate = OnLoad;

        l.init(OnTick, OnComplete, LuaSvrFlag.LSF_BASIC | LuaSvrFlag.LSF_EXTLIB);
    }
Esempio n. 26
0
        public override void Execute(System.Action action)
        {
            GameObject go;

            switch (type)
            {
            case Controller.ControllerType.Player:
                go = Resources.Load("Prefabs/PlayerController") as GameObject;
                go = Instantiate(go);
                ConflictController.Instance.Players.Add(team, go.GetComponent <PlayerController>());
                go.GetComponent <PlayerController>().Setup(team, guid);
                ConflictController.Instance.AddNewControllerToGame(go.GetComponent <PlayerController>());
                break;

            case Controller.ControllerType.AI:
                go = Resources.Load("Prefabs/AIController") as GameObject;
                go = Instantiate(go);
                ConflictController.Instance.Players.Add(team, go.GetComponent <AiController>());
                go.GetComponent <AiController>().Setup(team, guid);
                ConflictController.Instance.AddNewControllerToGame(go.GetComponent <AiController>());
                break;
            }
            LuaFile file;
            Table   table;

            for (int i = 0; i < teamList.Length; i++)
            {
                file = new LuaFile();
                file.Setup("Characters/" + teamList[i]);
                table = (Table)file.GetValue("Actions");


                List <string> abilites = new List <string>();
                foreach (DynValue dy in table.Values)
                {
                    abilites.Add(dy.String);
                }
                var newCharacter = new SpawnCharacterEvent(file.GetValue("Name").ToString() + ":" + team, Convert.ToInt32(file.GetValue("BaseHealth")), Convert.ToInt32(file.GetValue("BaseArmour")), Convert.ToInt32(file.GetValue("BaseActionPoints")), System.Guid.NewGuid(), abilites, GridController.Singelton.GetTeamSpawnPoints(team).position, team);
                RuneManager.Singelton.ExecuteRune((Rune)newCharacter);
            }
            action();
        }
Esempio n. 27
0
        public void LoadLuaFile(string path)
        {
            var    processedPath = PathManager.TryMakeRelative(path);
            string pathToLoad    = ProcessPath(processedPath);

            if (LuaAlreadyInSession(processedPath) == false)
            {
                var luaFile = new LuaFile("", processedPath);

                LuaImp.ScriptList.Add(luaFile);
                LuaListView.ItemCount = LuaImp.ScriptList.Count;
                Global.Config.RecentLua.Add(processedPath);

                if (!Global.Config.DisableLuaScriptsOnLoad)
                {
                    luaFile.State = LuaFile.RunState.Running;
                    EnableLuaFile(luaFile);
                }
                else
                {
                    luaFile.State = LuaFile.RunState.Disabled;
                }

                if (Global.Config.LuaReloadOnScriptFileChange)
                {
                    CreateFileWatcher(processedPath);
                }
            }
            else
            {
                foreach (var file in LuaImp.ScriptList.Where(file => processedPath == file.Path && file.Enabled == false && !Global.Config.DisableLuaScriptsOnLoad))
                {
                    file.Toggle();
                    break;
                }

                RunLuaScripts();
            }

            UpdateDialog();
        }
Esempio n. 28
0
        public override ResumeResult ResumeScript(LuaFile lf)
        {
            _currThread = lf.Thread;

            try
            {
                LuaLibraryBase.SetCurrentThread(lf);

                var execResult = _currThread.Resume(0);

                _lua.RunScheduledDisposes();

                // not sure how this is going to work out, so do this too
                _currThread.RunScheduledDisposes();

                _currThread = null;
                var result = new ResumeResult();
                if (execResult == 0)
                {
                    // terminated
                    result.Terminated = true;
                }
                else
                {
                    // yielded
                    result.WaitForFrame = FrameAdvanceRequested;
                }

                FrameAdvanceRequested = false;
                return(result);
            }
            finally
            {
                LuaLibraryBase.ClearCurrentThread();
            }
        }
Esempio n. 29
0
 public override void CallExitEvent(LuaFile lf)
 {
     EventsLibrary.CallExitEvent(lf);
 }
Esempio n. 30
0
 public abstract void SpawnAndSetFileThread(string pathToLoad, LuaFile lf);
Esempio n. 31
0
 public abstract EmuLuaLibrary.ResumeResult ResumeScript(LuaFile lf);
Esempio n. 32
0
 public abstract void CallExitEvent(LuaFile lf);
Esempio n. 33
0
 public override void SpawnAndSetFileThread(string pathToLoad, LuaFile lf)
 {
     lf.Thread = SpawnCoroutine(pathToLoad);
 }
Esempio n. 34
0
        private static void Extract(string name, string[] ignore = null)
        {
            DisplayMessage("Generating files for " + name + "...");

            #if !DEBUG
            try
            {
            #endif
                var xml = new XDocument(new XDeclaration("1.0", "utf-8", null), new XElement(name));
                if (xml.Root == null)
                {
                    throw new InvalidDataException("fixes.xml file corrupted.");
                }
                var lua = new LuaFile(name);

                foreach (var obj in model[name])
                {
                    if (!IsValidName(ignore ?? new string[] {}, obj))
                    {
                        continue;
                    }

                    var xmlelement = new XElement("o");
                    foreach (var pair in obj)
                    {
                        //TODO: Level dictionaries are currently messed up on XML output
                        xmlelement.SetAttributeValue(pair.Key, pair.Value);
                    }

                    xml.Root.Add(xmlelement);
                    lua.Add(obj);
                }

                xml.Root.ReplaceNodes(xml.Root.Elements().OrderBy(e => (uint)((int?)e.Attribute("id") ?? 0)));

                xml.Save(Path.Combine("resources", "xml", FormattableString.Invariant($"{name}.xml")));
                lua.Save();

            #if !DEBUG
            }
            catch
            {
                DisplayError();
                throw;
            }
            #endif

            DisplaySuccess();
        }
Esempio n. 35
0
		public IEnumerable<LuaMember> FindReferencesInFile(LuaFile file, string keyword)
		{
			if (file != null)
			{
				List<string> lines = new List<string>();
				try
				{
					using (StreamReader sr = new StreamReader(file.File))
					{
						while (sr.Peek() >= 0)
						{
							lines.Add(sr.ReadLine());
						}
					}
				}
				catch 
                {
                    yield break;
                }

                //for (int i = 0; i < file.Tokens.Count; i++)
                //{
                //    if(file.Tokens[i].Text.Equals(keyword))
                //    {
                //        var lm = new LuaMember(file.Tokens[i]);
                //        lm.Preview = lines[lm.Line];
                //        lm.File = file;
                //        yield return lm;
                //    }
                //}
                foreach (var token in file.Tokens)
                {
                    if (token.EditorInfo == null || token.EditorInfo.Type != Irony.Parsing.TokenType.String)
                    {
                        if (token.ValueString.Equals(keyword))
                        {
                            var lmp = new LuaMember(token);
                            lmp.Preview = lines[lmp.Line];
                            lmp.File = file;
                            yield return lmp;
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(token.ValueString)) continue;
                        int index = token.ValueString.IndexOf(keyword);
                        if (index != -1)
                        {

                            var lmp = new LuaMember(keyword, token.Location.Line, token.Location.Column + 1 + index);
                            lmp.Preview = lines[lmp.Line];
                            lmp.File = file;
                            yield return lmp;
                        }
                    }
                }
			}
		}
Esempio n. 36
0
        public INamedLuaFunction CreateAndRegisterNamedFunction(LuaFunction function, string theEvent, Action <string> logCallback, LuaFile luaFile, string name = null)
        {
            var nlf = new NamedLuaFunction(function, theEvent, logCallback, luaFile, name);

            RegisteredFunctions.Add(nlf);
            return(nlf);
        }
Esempio n. 37
0
		public LuaTable(LuaFile file, string basetable, string name, int line)
			: this(file, name, line)
		{
			Father = basetable;
		}
Esempio n. 38
0
		public List<LuaMember> SearchInFile(LuaFile file, string keyword)
		{
			List<LuaMember> members = new List<LuaMember>();

			if (file != null)
			{
				try
				{
					System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(System.Text.RegularExpressions.Regex.Escape(keyword));
					
					List<string> lines = new List<string>();
					using (StreamReader sr = new StreamReader(file.File))
					{
						while (sr.Peek() >= 0)
						{
							lines.Add(sr.ReadLine());
						}
					}

					for (int i = 0; i < lines.Count; i++)
					{
						var match = reg.Match(lines[i]);
						while (match.Success)
						{
							var lm = new LuaMember(keyword, i, match.Index);
							lm.Preview = lines[i];
							lm.File = file;
							members.Add(lm);
							match = match.NextMatch();
						}
					}

					//int index = -1;
					//for(int i = 0;i<lines.Count;i++)
					//{
					//	index = lines[i].IndexOf(keyword);
					//	while (index != -1)
					//	{
					//		var lm = new LuaMember(keyword, i, index);
					//		lm.Preview = lines[i];
					//		lm.File = file.File;
					//		members.Add(lm);
					//		index = lines[i].IndexOf(keyword, index + keyword.Length);
					//	}
					//}
				}
				catch { }
			}

			return members;
		}
Esempio n. 39
0
        private static void Extract(string name, string[] ignore = null)
        {
            DisplayMessage("Generating files for " + name + "...");

            #if !DEBUG
            try
            {
            #endif
                XDocument xml = new XDocument(new XDeclaration("1.0", "utf-8", null), new XElement(name));
                LuaFile lua = new LuaFile(name);

                foreach (dynamic obj in model[name])
                {
                    if (IsValidName(ignore ?? new string[] { }, obj))
                    {
                        XElement xmlelement = new XElement("o");
                        foreach (var pair in obj)
                        {
                            //TODO: Level dictionaries are currently messed up on XML output
                            xmlelement.SetAttributeValue(pair.Key, pair.Value);
                        }

                        xml.Root.Add(xmlelement);
                        lua.Add(obj);
                    }
                }

                xml.Root.ReplaceNodes(xml.Root.Elements().OrderBy(e => (uint)((int?)e.Attribute("id") ?? 0)));

                xml.Save(Path.Combine("resources", "xml", string.Format(CultureInfo.InvariantCulture, "{0}.xml", name)));
                lua.Save();

            #if !DEBUG
            }
            catch
            {
                DisplayError();
                throw;
            }
            #endif

            DisplaySuccess();
        }
Esempio n. 40
0
		public LuaFunction(LuaFile file, string name, int line, params string[] args)
			: this(name, line, args)
		{
			this.File = file;
		}
Esempio n. 41
0
		public LuaTable(LuaFile file, string name, int line):this(name,line)
		{
			this.File = file;
		}