예제 #1
0
        public LuaTable Text(int width, int height)
        {
            var canvas = new LuaCanvas(width, height);

            canvas.Show();
            return(LuaHelper.ToLuaTable(Lua, canvas));
        }
예제 #2
0
        public LuaTable Text(int width, int height, int?x = null, int?y = null)
        {
            var canvas = new LuaCanvas(width, height, x, y);

            canvas.Show();
            return(Lua.TableFromObject(canvas));
        }
예제 #3
0
        public Win32LuaLibraries(
            LuaFileList scriptList,
            LuaFunctionList registeredFuncList,
            IEmulatorServiceProvider serviceProvider,
            MainForm mainForm,
            DisplayManagerBase displayManager,
            InputManager inputManager,
            Config config,
            IEmulator emulator,
            IGameInfo game)
        {
            void EnumerateLuaFunctions(string name, Type type, LuaLibraryBase instance)
            {
                if (instance != null)
                {
                    _lua.NewTable(name);
                }
                foreach (var method in type.GetMethods())
                {
                    var foundAttrs = method.GetCustomAttributes(typeof(LuaMethodAttribute), false);
                    if (foundAttrs.Length == 0)
                    {
                        continue;
                    }
                    if (instance != null)
                    {
                        _lua.RegisterFunction($"{name}.{((LuaMethodAttribute) foundAttrs[0]).Name}", instance, method);
                    }
                    Docs.Add(new LibraryFunction(
                                 name,
                                 type.GetCustomAttributes(typeof(DescriptionAttribute), false).Cast <DescriptionAttribute>()
                                 .Select(descAttr => descAttr.Description).FirstOrDefault() ?? string.Empty,
                                 method
                                 ));
                }
            }

            if (true /*NLua.Lua.WhichLua == "NLua"*/)
            {
                _lua["keepalives"] = _lua.NewTable();
            }
            _th                 = new NLuaTableHelper(_lua, LogToLuaConsole);
            _displayManager     = displayManager;
            _inputManager       = inputManager;
            _mainForm           = mainForm;
            LuaWait             = new AutoResetEvent(false);
            PathEntries         = config.PathEntries;
            RegisteredFunctions = registeredFuncList;
            ScriptList          = scriptList;
            Docs.Clear();
            _apiContainer = ApiManager.RestartLua(serviceProvider, LogToLuaConsole, _mainForm, _displayManager, _inputManager, _mainForm.MovieSession, _mainForm.Tools, config, emulator, game);

            // Register lua libraries
            foreach (var lib in Client.Common.ReflectionCache.Types.Concat(EmuHawk.ReflectionCache.Types)
                     .Where(t => typeof(LuaLibraryBase).IsAssignableFrom(t) && t.IsSealed && ServiceInjector.IsAvailable(serviceProvider, t)))
            {
                bool addLibrary = true;
                var  attributes = lib.GetCustomAttributes(typeof(LuaLibraryAttribute), false);
                if (attributes.Any())
                {
                    addLibrary = VersionInfo.DeveloperBuild || ((LuaLibraryAttribute)attributes.First()).Released;
                }

                if (addLibrary)
                {
                    var instance = (LuaLibraryBase)Activator.CreateInstance(lib, this, _apiContainer, (Action <string>)LogToLuaConsole);
                    ServiceInjector.UpdateServices(serviceProvider, instance);

                    // TODO: make EmuHawk libraries have a base class with common properties such as this
                    // and inject them here
                    if (instance is ClientLuaLibrary clientLib)
                    {
                        clientLib.MainForm = _mainForm;
                    }
                    else if (instance is ConsoleLuaLibrary consoleLib)
                    {
                        consoleLib.Tools         = _mainForm.Tools;
                        _logToLuaConsoleCallback = consoleLib.Log;
                    }
                    else if (instance is GuiLuaLibrary guiLib)
                    {
                        // emu lib may be null now, depending on order of ReflectionCache.Types, but definitely won't be null when this is called
                        guiLib.CreateLuaCanvasCallback = (width, height, x, y) =>
                        {
                            var canvas = new LuaCanvas(EmulationLuaLibrary, width, height, x, y, _th, LogToLuaConsole);
                            canvas.Show();
                            return(_th.ObjectToTable(canvas));
                        };
                    }
                    else if (instance is TAStudioLuaLibrary tastudioLib)
                    {
                        tastudioLib.Tools = _mainForm.Tools;
                    }

                    EnumerateLuaFunctions(instance.Name, lib, instance);
                    Libraries.Add(lib, instance);
                }
            }

            _lua.RegisterFunction("print", this, typeof(Win32LuaLibraries).GetMethod(nameof(Print)));

            EmulationLuaLibrary.FrameAdvanceCallback = Frameadvance;
            EmulationLuaLibrary.YieldCallback        = EmuYield;

            EnumerateLuaFunctions(nameof(LuaCanvas), typeof(LuaCanvas), null);             // add LuaCanvas to Lua function reference table
        }
예제 #4
0
 public LuaTable Text(int width, int height)
 {
     var canvas = new LuaCanvas(width, height);
     canvas.Show();
     return LuaHelper.ToLuaTable(Lua, canvas);
 }