Пример #1
0
        private static void AddSledSpecificFunctions(LuatTable table)
        {
            if (table == null)
            {
                return;
            }

            // add libsleddebugger table
            {
                var debuggerTable = new LuatTable {
                    Description = "libsleddebugger injected functionality"
                };

                debuggerTable.AddChild("version", new LuatLiteral(LuatTypeString.Instance));
                debuggerTable.AddChild("instance", new LuatLiteral(LuatTypeNumber.Instance));

                table.AddChild("libsleddebugger", debuggerTable);
            }

            // add libsledluaplugin table
            {
                var luaPluginTable = new LuatTable {
                    Description = "libsledluaplugin injected functionality"
                };

                luaPluginTable.AddChild("version", new LuatLiteral(LuatTypeString.Instance));
                luaPluginTable.AddChild("instance", new LuatLiteral(LuatTypeNumber.Instance));

                {
                    var retVal   = new LuatVariable(null, LuatTypeNil.Instance, LuatVariableFlags.None);
                    var function = new LuatFunction(retVal, new[] { "message" })
                    {
                        ExpectsSelf = false
                    };
                    luaPluginTable.AddChild("tty", function);
                }

                {
                    var retVal   = new LuatVariable(null, LuatTypeNil.Instance, LuatVariableFlags.None);
                    var function = new LuatFunction(retVal, new[] { "condition", "message" })
                    {
                        ExpectsSelf = false
                    };
                    luaPluginTable.AddChild("assert", function);
                }

                {
                    var retVal   = new LuatVariable(null, LuatTypeNil.Instance, LuatVariableFlags.None);
                    var function = new LuatFunction(retVal, new[] { "error" })
                    {
                        ExpectsSelf = false
                    };
                    luaPluginTable.AddChild("errorhandler", function);
                }

                table.AddChild("libsledluaplugin", luaPluginTable);
            }
        }
Пример #2
0
        public LuatVariable AddLocal(LuatScript script, Identifier Name, string type)
        {
            string name = Name.Text;

            LuatVariable variable = Locals[script].Index(name, false) as LuatVariable;

            if (null == variable)
            {
                LuatTable localTable = Locals[script];

                if (null != type)
                {
                    variable = Database.Instance.CreateReflectedVariable(type, localTable);
                }

                if (null == variable)
                {
                    variable = new LuatVariable(localTable);
                }

                localTable.AddChild(name, variable);
            }
            else
            {
                Name.AddWarning(script, WarningType.DuplicateLocal, "Warning: Local '" + name + "' already defined");
            }

            return(variable);
        }
Пример #3
0
        private static void AddSledSpecificFunctions(LuatTable table)
        {
            if (table == null)
                return;

            // add libsleddebugger table
            {
                var debuggerTable = new LuatTable { Description = "libsleddebugger injected functionality" };

                debuggerTable.AddChild("version", new LuatLiteral(LuatTypeString.Instance));
                debuggerTable.AddChild("instance", new LuatLiteral(LuatTypeNumber.Instance));

                table.AddChild("libsleddebugger", debuggerTable);
            }

            // add libsledluaplugin table
            {
                var luaPluginTable = new LuatTable { Description = "libsledluaplugin injected functionality" };

                luaPluginTable.AddChild("version", new LuatLiteral(LuatTypeString.Instance));
                luaPluginTable.AddChild("instance", new LuatLiteral(LuatTypeNumber.Instance));

                {
                    var retVal = new LuatVariable(null, LuatTypeNil.Instance, LuatVariableFlags.None);
                    var function = new LuatFunction(retVal, new[] { "message" }) { ExpectsSelf = false };
                    luaPluginTable.AddChild("tty", function);
                }

                {
                    var retVal = new LuatVariable(null, LuatTypeNil.Instance, LuatVariableFlags.None);
                    var function = new LuatFunction(retVal, new[] { "condition", "message" }) { ExpectsSelf = false };
                    luaPluginTable.AddChild("assert", function);
                }

                {
                    var retVal = new LuatVariable(null, LuatTypeNil.Instance, LuatVariableFlags.None);
                    var function = new LuatFunction(retVal, new[] { "error" }) { ExpectsSelf = false };
                    luaPluginTable.AddChild("errorhandler", function);
                }

                table.AddChild("libsledluaplugin", luaPluginTable);
            }
        }
Пример #4
0
        public override LuatValue Resolve(LuatScript script)
        {
            LuatValue value = base.Resolve(script);

            if (null != value)
            {
                return(value);
            }

            LuatTable table      = new LuatTable(null);
            int       fieldIndex = 1;

            foreach (Field field in Fields)
            {
                string key;
                if (null == field.Key)
                {
                    key = (fieldIndex++).ToString();
                }
                else if (field.Key is StringExpression)
                {
                    key = (field.Key as StringExpression).String;
                }
                else if (field.Key is NumberExpression)
                {
                    key = (field.Key as NumberExpression).Number.ToString();
                }
                else if (field.Key is Identifier)
                {
                    key = (field.Key as Identifier).Text;
                }
                else
                {
                    continue;
                }

                if (null != table.Index(key, false))
                {
                    field.AddWarning(script, WarningType.DuplicateTableKey, string.Format("Table already contains key '{0}'", key));
                    continue;
                }

                LuatVariable entry = table.AddChild(key, new LuatVariable(table));
                entry.Description = Description;

                if (null != field.Value)
                {
                    entry.AddAssignment(new Parser.AST.Expression.Reference(script, field.Value, this.DisplayText));
                }
            }

            this.ResolvedValues[script] = table;
            return(table);
        }