Пример #1
0
        public void Add(ISledLuaVarBaseType luaVar)
        {
            if (luaVar == null)
            {
                return;
            }

            m_dictCustomWatches[luaVar] = WatchedVariableService.ReceivingWatchedCustomVariables;

            if (luaVar.DomNode.Is <SledLuaVarGlobalType>())
            {
                Globals.Add(luaVar.DomNode.As <SledLuaVarGlobalType>());
            }
            else if (luaVar.DomNode.Is <SledLuaVarLocalType>())
            {
                Locals.Add(luaVar.DomNode.As <SledLuaVarLocalType>());
            }
            else if (luaVar.DomNode.Is <SledLuaVarUpvalueType>())
            {
                Upvalues.Add(luaVar.DomNode.As <SledLuaVarUpvalueType>());
            }
            else if (luaVar.DomNode.Is <SledLuaVarEnvType>())
            {
                EnvVars.Add(luaVar.DomNode.As <SledLuaVarEnvType>());
            }
        }
Пример #2
0
        public override void Load(string code = "")
        {
            try {
                context = ScriptContext.CurrentContext;
                context.Include(rpath + "\\" + Name + ".php", true);
                Class      = (PhpObject)context.NewObject(Name);
                PHPGlobals = context.GlobalVariables;
                context.GlobalVariables.Add("Commands", chatCommands);
                context.GlobalVariables.Add("DataStore", DataStore.GetInstance());
                context.GlobalVariables.Add("Find", Find.GetInstance());
                context.GlobalVariables.Add("GlobalData", GlobalData);
                context.GlobalVariables.Add("Plugin", this);
                context.GlobalVariables.Add("Server", Pluton.Server.GetInstance());
                context.GlobalVariables.Add("ServerConsoleCommands", consoleCommands);
                context.GlobalVariables.Add("Util", Util.GetInstance());
                context.GlobalVariables.Add("Web", Web.GetInstance());
                context.GlobalVariables.Add("World", World.GetInstance());

                AssignVariables();

                foreach (var x in PHPGlobals)
                {
                    Globals.Add(x.Key.ToString());
                }

                State = PluginState.Loaded;
            } catch (Exception ex) {
                Logger.LogException(ex);
                State = PluginState.FailedToLoad;
            }

            PluginLoader.GetInstance().OnPluginLoaded(this);
        }
Пример #3
0
 void PrepareReservedGlobalBuilders([ItemNotNull][NotNull] string[] reservedGlobals)
 {
     // implicitly defined globals
     // NOTE: the parameter to DoFunnyGlobals() above must match the number of globals implicitly defined here
     foreach (var name in reservedGlobals)
     {
         var glb  = Game.DefineGlobal(name);
         var atom = Context.RootObList[name];
         Globals.Add(atom, glb);
     }
 }
Пример #4
0
        public void TestGlobalsChange()
        {
            TemplateInfo ti    = Cache.CompileTemplate(@"<template></template>", Globals, RefAssemblies);
            string       hash1 = ti.TemplateKey;

            Globals.Add("the_string_2", typeof(string));

            ti = Cache.CompileTemplate(@"<template></template>", Globals, RefAssemblies);
            string hash2 = ti.TemplateKey;

            Assert.AreNotEqual(hash1, hash2, "Template re-generation if Globals types change failed. Hash1: {0}, Hash2: {1}", hash1, hash2);
        }
Пример #5
0
 private void ExtractGlobals(PropertyGroup propertyGroup)
 {
     if (propertyGroup.Items != null && propertyGroup.ItemsElementName != null)
     {
         if (propertyGroup.Items.Length == propertyGroup.ItemsElementName.Length)
         {
             for (var i = 0; i < propertyGroup.Items.Length; i++)
             {
                 Globals.Add(propertyGroup.ItemsElementName[i].ToString(), propertyGroup.Items[i].ToString());
             }
         }
     }
 }
Пример #6
0
 void PrepareHardGlobalBuilders([ItemNotNull][NotNull] Queue <System.Action> globalInitializers)
 {
     // builders and values for globals (which may refer to constants)
     foreach (var global in Context.ZEnvironment.Globals)
     {
         if (global.StorageType == GlobalStorageType.Hard)
         {
             var glb = Game.DefineGlobal(global.Name.Text);
             Globals.Add(global.Name, glb);
             var globalSave = global;
             globalInitializers.Enqueue(() => glb.DefaultValue = GetGlobalDefaultValue(globalSave));
         }
     }
 }
Пример #7
0
 void HandleZValChangedWhileCompilingRoutine([NotNull] object sender, [NotNull] ZValEventArgs e)
 {
     switch (e.NewValue)
     {
     case ZilGlobal g:
         if (!Globals.ContainsKey(g.Name))
         {
             var glb = Game.DefineGlobal(g.Name.Text);
             glb.DefaultValue = GetGlobalDefaultValue(g);
             Globals.Add(g.Name, glb);
         }
         break;
     }
 }
        private void PopulateAllVariables()
        {
            for (int i = 0, enumIndex = 0; i < TheEditor.GetNumGlobals(); i++, enumIndex++)
            {
                while (TheEditor.GetIndexOfGlobal((GlobalVariable)enumIndex) < i)
                {
                    enumIndex++;
                }

                string name = Enum.GetName(typeof(GlobalVariable), enumIndex);
                Globals.Add(new GlobalVariableInfo()
                {
                    Index      = i,
                    IntValue   = TheEditor.GetGlobal(i),
                    FloatValue = TheEditor.GetGlobalAsFloat(i),
                    Name       = name
                });
            }
        }
        private void PopulateSavedVariables()
        {
            foreach (GlobalVariable var in Enum.GetValues(typeof(GlobalVariable)))
            {
                int index = TheEditor.GetIndexOfGlobal(var);
                if (index == -1)
                {
                    continue;
                }

                Globals.Add(new GlobalVariableInfo()
                {
                    Index      = index,
                    IntValue   = TheEditor.GetGlobal(var),
                    FloatValue = TheEditor.GetGlobalAsFloat(var),
                    Name       = var.ToString()
                });
            }
        }
Пример #10
0
        public override void Load(string code = "")
        {
            try {
                if (CoreConfig.GetInstance().GetBoolValue("lua", "checkHash") && !code.VerifyMD5Hash())
                {
                    Logger.LogDebug($"[{GetType().Name}] MD5Hash not found for: {Name}");
                    State = PluginState.HashNotFound;
                }
                else
                {
                    UserData.RegistrationPolicy = InteropRegistrationPolicy.Automatic;
                    script = new Script();
                    script.Globals["Plugin"]     = this;
                    script.Globals["Util"]       = Util.GetInstance();
                    script.Globals["DataStore"]  = DataStore.GetInstance();
                    script.Globals["GlobalData"] = GlobalData;
                    script.Globals["Web"]        = Web.GetInstance();

                    AssignVariables();

                    script.DoString(code);

                    Author  = script.Globals.Get("Author").String;
                    About   = script.Globals.Get("About").String;
                    Version = script.Globals.Get("Version").String;

                    State = PluginState.Loaded;
                    foreach (DynValue v in script.Globals.Keys)
                    {
                        Globals.Add(v.ToString().Replace("\"", ""));
                    }
                    Tables = script.Globals;
                }
            } catch (Exception ex) {
                Logger.LogException(ex);
                State = PluginState.FailedToLoad;
            }

            PluginLoader.GetInstance().OnPluginLoaded(this);
        }
Пример #11
0
        public override void Load(string code = "")
        {
            try
            {
                UserData.RegistrationPolicy = InteropRegistrationPolicy.Automatic;
                script = new Script();
                script.DoString(code);
                script.Globals.Set("Util", UserData.Create(Fougerite.Util.GetUtil()));
                script.Globals.Set("Plugin", UserData.Create(this));
                script.Globals.Set("Server", UserData.Create(Fougerite.Server.GetServer()));
                script.Globals.Set("DataStore", UserData.Create(Fougerite.DataStore.GetInstance()));
                script.Globals.Set("Data", UserData.Create(Fougerite.Data.GetData()));
                script.Globals.Set("Web", UserData.Create(new Fougerite.Web()));
                script.Globals.Set("World", UserData.Create(Fougerite.World.GetWorld()));
                #pragma warning disable 618
                script.Globals.Set("PluginCollector", UserData.Create(GlobalPluginCollector.GetPluginCollector()));
                #pragma warning restore 618
                script.Globals.Set("Loom", UserData.Create(Loom.Current));
                script.Globals.Set("JSON", UserData.Create(JsonAPI.GetInstance));
                script.Globals.Set("MySQL", UserData.Create(MySQLConnector.GetInstance));
                script.Globals.Set("SQLite", UserData.Create(Fougerite.SQLiteConnector.GetInstance));
                foreach (DynValue v in script.Globals.Keys)
                {
                    Globals.Add(v.ToString().Replace("\"", ""));
                }
                Author  = string.IsNullOrEmpty(script.Globals.Get("Author").String) ? "Unknown" : script.Globals.Get("Author").String;
                Version = string.IsNullOrEmpty(script.Globals.Get("Version").String) ? "1.0" : script.Globals.Get("Version").String;
                About   = script.Globals.Get("About").String;

                State  = PluginState.Loaded;
                Tables = script.Globals;
            }
            catch (Exception ex)
            {
                Logger.LogError("[Error] Failed to load Lua plugin: " + ex);
                State = PluginState.FailedToLoad;
            }

            PluginLoader.GetInstance().OnPluginLoaded(this);
        }
Пример #12
0
        public override void Load(string code = "")
        {
            try
            {
                UserData.RegistrationPolicy = InteropRegistrationPolicy.Automatic;
                script = new Script();
                script.Globals["Plugin"]                = this;
                script.Globals["Util"]                  = Util.GetInstance();
                script.Globals["Server"]                = Server.GetInstance();
                script.Globals["DataStore"]             = DataStore.GetInstance();
                script.Globals["Commands"]              = chatCommands;
                script.Globals["GlobalData"]            = GlobalData;
                script.Globals["ServerConsoleCommands"] = consoleCommands;
                script.Globals["Web"]   = Web.GetInstance();
                script.Globals["World"] = World.GetInstance();
                script.DoString(code);

                Author  = script.Globals.Get("Author").String;
                About   = script.Globals.Get("About").String;
                Version = script.Globals.Get("Version").String;

                State = PluginState.Loaded;
                foreach (DynValue v in script.Globals.Keys)
                {
                    Globals.Add(v.ToString().Replace("\"", ""));
                }
                Tables = script.Globals;
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                State = PluginState.FailedToLoad;
            }

            PluginLoader.GetInstance().OnPluginLoaded(this);
        }
Пример #13
0
        /// <summary>
        /// Analyzes the set of defined global variables and, if there are too many to fit in Z-machine variables ("hard globals"),
        /// does the necessary planning and allocation to move some of them into a table ("soft globals").
        /// </summary>
        /// <remarks>
        /// <para>This method sets <see cref="ZilGlobal.StorageType"/> for all globals,
        /// whether or not it ends up moving any of them.</para>
        /// <para>If it does decide to move some globals, it allocates the <see cref="SoftGlobalsTable"/> (<c>T?GLOBAL-VARS-TABLE</c>),
        /// assigns offsets within the table, and fills the table with the initial values.</para>
        /// </remarks>
        /// <param name="reservedGlobals">The number of hard globals that are reserved for other purposes (i.e. parser tables).
        ///     Subtracting <paramref name="reservedGlobals"/> from 240 gives the number of hard globals that are actually available
        ///     for storing <see cref="ZEnvironment.Globals"/>.</param>
        /// <param name="globalInitializers"></param>
        /// <exception cref="CompilerError"></exception>
        void DoFunnyGlobals(int reservedGlobals, Queue <System.Action> globalInitializers)
        {
            // if all the globals fit into Z-machine globals, no need for a table
            int remaining = 240 - reservedGlobals;

            if (Context.ZEnvironment.Globals.Count <= remaining)
            {
                foreach (var g in Context.ZEnvironment.Globals)
                {
                    g.StorageType = GlobalStorageType.Hard;
                }

                return;
            }

            // reserve one slot for GLOBAL-VARS-TABLE
            remaining--;

            // in V3, the status line variables need to be Z-machine globals
            if (Context.ZEnvironment.ZVersion < 4)
            {
                foreach (var g in Context.ZEnvironment.Globals)
                {
                    switch (g.Name.StdAtom)
                    {
                    case StdAtom.HERE:
                    case StdAtom.SCORE:
                    case StdAtom.MOVES:
                        g.StorageType = GlobalStorageType.Hard;
                        break;
                    }
                }
            }

            // variables used as operands need to be Z-machine globals too
            var globalsByName = Context.ZEnvironment.Globals.ToDictionary(g => g.Name);

            foreach (var r in Context.ZEnvironment.Routines)
            {
                r.WalkRoutineForms(f =>
                {
                    var args = f.Rest;
                    if (args != null && !args.IsEmpty)
                    {
                        // skip the first argument to operations that operate on a variable
                        if (f.First is ZilAtom firstAtom)
                        {
                            switch (firstAtom.StdAtom)
                            {
                            case StdAtom.SET:
                            case StdAtom.SETG:
                            case StdAtom.VALUE:
                            case StdAtom.GVAL:
                            case StdAtom.LVAL:
                            case StdAtom.INC:
                            case StdAtom.DEC:
                            case StdAtom.IGRTR_P:
                            case StdAtom.DLESS_P:
                                args = args.Rest;
                                break;
                            }
                        }

                        while (args != null && !args.IsEmpty)
                        {
                            if (args.First is ZilAtom atom && globalsByName.TryGetValue(atom, out var g))
                            {
                                g.StorageType = GlobalStorageType.Hard;
                            }

                            args = args.Rest;
                        }
                    }
                });
            }

            // determine which others to keep in Z-machine globals
            var lookup = Context.ZEnvironment.Globals.ToLookup(g => g.StorageType);

            var hardGlobals = new List <ZilGlobal>(remaining);

            if (lookup.Contains(GlobalStorageType.Hard))
            {
                hardGlobals.AddRange(lookup[GlobalStorageType.Hard]);

                if (hardGlobals.Count > remaining)
                {
                    throw new CompilerError(
                              CompilerMessages.Too_Many_0_1_Defined_Only_2_Allowed,
                              "hard globals",
                              hardGlobals.Count,
                              remaining);
                }
            }

            var softGlobals = new Queue <ZilGlobal>(Context.ZEnvironment.Globals.Count - hardGlobals.Count);

            if (lookup.Contains(GlobalStorageType.Any))
            {
                foreach (var g in lookup[GlobalStorageType.Any])
                {
                    softGlobals.Enqueue(g);
                }
            }

            if (lookup.Contains(GlobalStorageType.Soft))
            {
                foreach (var g in lookup[GlobalStorageType.Soft])
                {
                    softGlobals.Enqueue(g);
                }
            }

            while (hardGlobals.Count < remaining && softGlobals.Count > 0)
            {
                hardGlobals.Add(softGlobals.Dequeue());
            }

            // assign final StorageTypes
            foreach (var g in hardGlobals)
            {
                g.StorageType = GlobalStorageType.Hard;
            }

            foreach (var g in softGlobals)
            {
                g.StorageType = GlobalStorageType.Soft;
            }

            // create SoftGlobals entries, fill table, and assign offsets
            int byteOffset = 0;
            var table      = Game.DefineTable("T?GLOBAL-VARS-TABLE", false);

            var tableGlobal = Game.DefineGlobal("GLOBAL-VARS-TABLE");

            tableGlobal.DefaultValue = table;
            Globals.Add(Context.GetStdAtom(StdAtom.GLOBAL_VARS_TABLE), tableGlobal);
            SoftGlobalsTable = tableGlobal;

            foreach (var g in softGlobals)
            {
                if (!g.IsWord)
                {
                    var entry = new SoftGlobal
                    {
                        IsWord = false,
                        Offset = byteOffset
                    };
                    SoftGlobals.Add(g.Name, entry);

                    var gSave = g;
                    globalInitializers.Enqueue(() => table.AddByte(GetGlobalDefaultValue(gSave) ?? Game.Zero));

                    byteOffset++;
                }
            }

            if (byteOffset % 2 != 0)
            {
                byteOffset++;
                globalInitializers.Enqueue(() => table.AddByte(Game.Zero));
            }

            foreach (var g in softGlobals)
            {
                if (g.IsWord)
                {
                    var entry = new SoftGlobal
                    {
                        IsWord = true,
                        Offset = byteOffset / 2
                    };
                    SoftGlobals.Add(g.Name, entry);

                    var gSave = g;
                    globalInitializers.Enqueue(() => table.AddShort(GetGlobalDefaultValue(gSave) ?? Game.Zero));

                    byteOffset += 2;
                }
            }
        }