Beispiel #1
0
        public override LuatValue Resolve(LuatScript script)
        {
            LuatValue value = base.Resolve(script);

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

            int index = 1;

            foreach (Identifier identifier in this.Parameters)
            {
                LuatVariable local = this.Block.AddLocal(script, identifier, null);
                local.Description = string.Format("parameter {0}", index++);
            }

            List <string> args = new List <string>();

            foreach (Identifier param in this.Parameters)
            {
                args.Add(param.Text);
            }

            LuatValue    returnValue = this.Block.ReturnValues[script];
            LuatFunction function    = new LuatFunction(returnValue, args.ToArray());

            function.Description = this.Description;
            function.ExpectsSelf = this.ExpectsSelf;
            value = function;

            this.ResolvedValues[script] = value;

            return(value);
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
        public override LuatValue Resolve(LuatScript script)
        {
            LuatValue value = base.Resolve(script);

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

            LuatValue funcValue = Owner.Resolve(script);

            if (null == funcValue)
            {
                return(null);
            }

            if (null != Name)
            {
                // funcValue isn't actually the function, but the owner.
                funcValue = funcValue.Index(Name.Text);
                if (null == funcValue)
                {
                    return(null);
                }
            }

            // Infer return type for value
            LuatFunction function = funcValue as LuatFunction;

            if (null == function)
            {
                LuatVariable variable = funcValue as LuatVariable;
                if (null != variable)
                {
                    foreach (LuatValue.IReference reference in variable.AssignmentsRecursive)
                    {
                        function = reference.Value as LuatFunction;

                        if (null != function)
                        {
                            break;
                        }
                    }
                }
            }

            if (null == function)
            {
                return(null);
            }

            if (function.ExpectsSelf != this.PassesSelf)
            {
                string warning = string.Format("Function expects to be called using '{0}' not '{1}'",
                                               function.ExpectsSelf ? ':' : '.',
                                               this.PassesSelf ? ':' : '.');
                AddWarning(script, WarningType.WrongFunctionCall, warning);
            }

            this.m_resolvedFunctions.Add(script, function);
            this.ResolvedValues[script] = function.ReturnValue;
            return(function);
        }