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;
public LuaWinform(LuaFile ownerFile, PlatformEmuLuaLibrary luaImp) { _ownerFile = ownerFile; _luaImp = luaImp; InitializeComponent(); StartPosition = FormStartPosition.CenterParent; Closing += (o, e) => CloseThis(); }
public LuaWinform(LuaFile ownerFile, Action <IntPtr> formsWindowClosedCallback) { _ownerFile = ownerFile; InitializeComponent(); Icon = Properties.Resources.TextDocIcon; StartPosition = FormStartPosition.CenterParent; Closing += (o, e) => formsWindowClosedCallback(Handle); }
byte[] OnLoad(string fn, ref string absoluteFn) { string path = LuaFile.FindFile(fn.Replace('.', '/')); byte[] bytes = LuaFile.ReadBytes(path); return bytes; }
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(); }
public LuaWinform(LuaFile ownerFile, LuaLibraries luaImp) { _ownerFile = ownerFile; _luaImp = luaImp; InitializeComponent(); Icon = Properties.Resources.TextDocIcon; StartPosition = FormStartPosition.CenterParent; Closing += (o, e) => { _luaImp.WindowClosed(Handle); }; }
public void AddFile(LuaFile file) { var index = Files.IndexOf(file); if (index != -1) Files[index] = file; else { Files.Add(file); } }
public LuaWinform(LuaFile ownerFile, LuaLibraries luaImp) { _ownerFile = ownerFile; _luaImp = luaImp; InitializeComponent(); Icon = Properties.Resources.textdoc_MultiSize; StartPosition = FormStartPosition.CenterParent; Closing += (o, e) => CloseThis(); }
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(); }
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(); }
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); }
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(); }
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(); }
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); }
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); }
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(); } }
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(); }
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); }
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."); } }
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); }
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"); } }
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; }
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(); }
// 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); }
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(); }
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(); }
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(); } }
public override void CallExitEvent(LuaFile lf) { EventsLibrary.CallExitEvent(lf); }
public abstract void SpawnAndSetFileThread(string pathToLoad, LuaFile lf);
public abstract EmuLuaLibrary.ResumeResult ResumeScript(LuaFile lf);
public abstract void CallExitEvent(LuaFile lf);
public override void SpawnAndSetFileThread(string pathToLoad, LuaFile lf) { lf.Thread = SpawnCoroutine(pathToLoad); }
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(); }
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; } } } } }
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); }
public LuaTable(LuaFile file, string basetable, string name, int line) : this(file, name, line) { Father = basetable; }
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; }
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(); }
public LuaFunction(LuaFile file, string name, int line, params string[] args) : this(name, line, args) { this.File = file; }
public LuaTable(LuaFile file, string name, int line):this(name,line) { this.File = file; }