Esempio n. 1
0
		public LuaFile(LuaFile file)
		{
			Name = file.Name;
			Path = file.Path;
			State = file.State;
			IsSeparator = file.IsSeparator;
			CurrentDirectory = file.CurrentDirectory;
		}
Esempio n. 2
0
 public LuaFile(LuaFile file)
 {
     Name             = file.Name;
     Path             = file.Path;
     State            = file.State;
     IsSeparator      = file.IsSeparator;
     CurrentDirectory = file.CurrentDirectory;
 }
Esempio n. 3
0
		public LuaFile(LuaFile file)
		{
			Name = file.Name;
			Path = file.Path;
			Enabled = file.Enabled;
			Paused = file.Paused;
			IsSeparator = file.IsSeparator;
			CurrentDirectory = file.CurrentDirectory;
		}
Esempio n. 4
0
 public LuaFile(LuaFile file)
 {
     Name             = file.Name;
     Path             = file.Path;
     Enabled          = file.Enabled;
     Paused           = file.Paused;
     IsSeparator      = file.IsSeparator;
     CurrentDirectory = file.CurrentDirectory;
 }
Esempio n. 5
0
        public void RemoveForFile(LuaFile file)
        {
            var functionsToRemove = this
                                    .ForFile(file)
                                    .ToList();

            foreach (var function in functionsToRemove)
            {
                Remove(function);
            }
        }
Esempio n. 6
0
        public void CallExitEvent(LuaFile luaFile)
        {
            var exitCallbacks = RegisteredFunctions
                                .ForFile(luaFile)
                                .ForEvent("OnExit");

            foreach (var exitCallback in exitCallbacks)
            {
                exitCallback.Call();
            }
        }
Esempio n. 7
0
        public void RemoveForFile(LuaFile file, IEmulator emulator)
        {
            var functionsToRemove = _functions
                                    .ForFile(file)
                                    .ToList();

            foreach (var function in functionsToRemove)
            {
                Remove(function, emulator);
            }
        }
Esempio n. 8
0
        public static void SetCurrentThread(LuaFile luaFile)
        {
            lock (ThreadMutex)
            {
                if (CurrentHostThread != null)
                {
                    throw new InvalidOperationException("Can't have lua running in two host threads at a time!");
                }

                CurrentHostThread = Thread.CurrentThread;
                CurrentFile       = luaFile;
            }
        }
Esempio n. 9
0
        public void DetachFromScript()
        {
            var thread = new Lua();

            // Current dir will have to do for now, but this will inevitably not be desired
            // Users will expect it to be the same directly as the thread that spawned this callback
            // But how do we know what that directory was?
            LuaSandbox.CreateSandbox(thread, ".");
            LuaFile = new LuaFile(".")
            {
                Thread = thread
            };
        }
Esempio n. 10
0
        public NamedLuaFunction(LuaFunction function, string theEvent, Action <string> logCallback, LuaFile luaFile, string name = null)
        {
            _function = function;
            Name      = name ?? "Anonymous";
            Event     = theEvent;
            LuaFile   = luaFile;
            Guid      = Guid.NewGuid();

            Callback = () =>
            {
                try
                {
                    _function.Call();
                }
                catch (Exception ex)
                {
                    logCallback($"error running function attached by the event {Event}\nError message: {ex.Message}");
                }
            };

            MemCallback = (address, value, flags) => Callback();
        }
Esempio n. 11
0
        public NamedLuaFunction(LuaFunction function, string theEvent, Action <string> logCallback, LuaFile luaFile, string name = null)
        {
            _function = function;
            Name      = name ?? "Anonymous";
            Event     = theEvent;

            // When would a file be null?
            // When a script is loaded with a callback, but no infinite loop so it closes
            // Then that callback proceeds to register more callbacks
            // In these situations, we will generate a thread for this new callback on the fly here
            // Scenarios like this suggest that a thread being managed by a LuaFile is a bad idea,
            // and we should refactor
            if (luaFile == null)
            {
                DetachFromScript();
            }
            else
            {
                LuaFile = luaFile;
            }

            Guid = Guid.NewGuid();

            Callback = args =>
            {
                try
                {
                    _function.Call(args);
                }
                catch (Exception ex)
                {
                    logCallback($"error running function attached by the event {Event}\nError message: {ex.Message}");
                }
            };
            InputCallback = () => Callback(Array.Empty <object>());
            MemCallback   = (addr, val, flags) => Callback(new object[] { addr, val, flags });
        }
Esempio n. 12
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. 13
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. 14
0
 public static IEnumerable <NamedLuaFunction> ForFile(this IEnumerable <NamedLuaFunction> list, LuaFile luaFile)
 {
     return(list
            .Where(l => l.LuaFile.Path == luaFile.Path ||
                   l.LuaFile.Thread == luaFile.Thread));
 }
Esempio n. 15
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();
		}