Ejemplo n.º 1
0
 void ProcessRet()
 {
     if (m_scriptInstruction.operand0 == null)
     {
         InvokeReturnValue(null);
     }
     else
     {
         ScriptObject ret = ResolveOperand(m_scriptInstruction.operand0);
         if (ret is ScriptScriptFunction)
         {
             ScriptScriptFunction ssf = ret as ScriptScriptFunction;
             ssf.isCloure = true;
             CodeObject co = m_scriptInstruction.operand0;
             if (co is CodeMember)
             {
                 CodeMember member = co as CodeMember;
                 if (member.Parent == null)
                 {
                     ssf.SetTable(m_script.GetGlobalTable());
                 }
                 else
                 {
                     ScriptObject sotable = ResolveOperand(member.Parent);
                     if (sotable is ScriptTable)
                     {
                         ssf.SetTable(sotable as ScriptTable);
                     }
                 }
             }
         }
         InvokeReturnValue(ret);
     }
 }
Ejemplo n.º 2
0
        public override ScriptObject AssignCompute(TokenType type, ScriptObject value)
        {
            if (type != TokenType.AssignPlus)
            {
                return(base.AssignCompute(type, value));
            }
            ScriptTable table = value as ScriptTable;

            if (table == null)
            {
                throw new ExecutionException(Script, "table [+=] 操作只支持两个table " + value.Type);
            }
            ScriptObject         obj  = null;
            ScriptScriptFunction func = null;

            foreach (KeyValuePair <object, ScriptObject> pair in table.m_listObject)
            {
                obj = pair.Value.Clone();
                if (obj is ScriptScriptFunction)
                {
                    func = (ScriptScriptFunction)obj;
                    if (!func.IsStatic)
                    {
                        func.SetTable(this);
                    }
                }
                m_listObject[pair.Key] = obj;
            }
            return(this);
        }
Ejemplo n.º 3
0
        public override ScriptObject Clone()
        {
            ScriptTable          ret  = Script.CreateTable();
            ScriptObject         obj  = null;
            ScriptScriptFunction func = null;

            foreach (KeyValuePair <object, ScriptObject> pair in m_listObject)
            {
                if (pair.Value == this)
                {
                    ret.m_listObject[pair.Key] = ret;
                }
                else
                {
                    obj = pair.Value.Clone();
                    if (obj is ScriptScriptFunction)
                    {
                        func = (ScriptScriptFunction)obj;
                        if (!func.IsStatic)
                        {
                            func.SetTable(ret);
                        }
                    }
                    ret.m_listObject[pair.Key] = obj;
                }
            }
            return(ret);
        }
Ejemplo n.º 4
0
        ScriptTable ParseTable(CodeTable table)
        {
            ScriptContext context = new ScriptContext(m_script, null, this, Executable_Block.None);
            ScriptTable   ret     = m_script.CreateTable();

            foreach (ScriptScriptFunction func in table.Functions)
            {
                func.SetTable(ret);
                ret.SetValue(func.Name, func);
                context.SetVariableForce(func.Name, func);
            }
            foreach (CodeTable.TableVariable variable in table.Variables)
            {
                ScriptObject value = context.ResolveOperand(variable.value);
                if (value is ScriptScriptFunction)
                {
                    ScriptScriptFunction func = (ScriptScriptFunction)value;
                    if (func.IsStaticFunction)
                    {
                        func.SetTable(ret);
                    }
                }
                ret.SetValue(variable.key, value);
                context.SetVariableForce(variable.key.ToString(), value);
            }
            return(ret);
        }
Ejemplo n.º 5
0
        public override ScriptObject Clone()
        {
            ScriptTable          table    = base.m_Script.CreateTable();
            ScriptObject         obj2     = null;
            ScriptScriptFunction function = null;

            foreach (KeyValuePair <object, ScriptObject> pair in this.m_listObject)
            {
                if (pair.Value == this)
                {
                    table.m_listObject[pair.Key] = table;
                }
                else
                {
                    obj2 = pair.Value.Clone();
                    if (obj2 is ScriptScriptFunction)
                    {
                        function = (ScriptScriptFunction)obj2;
                        if (!function.IsStaticFunction)
                        {
                            function.SetTable(table);
                        }
                    }
                    table.m_listObject[pair.Key] = obj2;
                }
            }
            return(table);
        }
Ejemplo n.º 6
0
        public override ScriptObject AssignCompute(Scorpio.Compiler.TokenType type, ScriptObject value)
        {
            if (type != Scorpio.Compiler.TokenType.AssignPlus)
            {
                return(base.AssignCompute(type, value));
            }
            ScriptTable table = value as ScriptTable;

            if (table == null)
            {
                throw new ExecutionException(base.m_Script, this, "table [+=] 操作只限两个[table]之间,传入数据类型:" + value.Type);
            }
            ScriptObject         obj2     = null;
            ScriptScriptFunction function = null;

            foreach (KeyValuePair <object, ScriptObject> pair in table.m_listObject)
            {
                obj2 = pair.Value.Clone();
                if (obj2 is ScriptScriptFunction)
                {
                    function = (ScriptScriptFunction)obj2;
                    if (!function.IsStaticFunction)
                    {
                        function.SetTable(this);
                    }
                }
                this.m_listObject[pair.Key] = obj2;
            }
            return(this);
        }
Ejemplo n.º 7
0
        public override ScriptObject Compute(TokenType type, ScriptObject value)
        {
            if (type != TokenType.Plus)
            {
                return(base.Compute(type, value));
            }
            ScriptTable table = value as ScriptTable;

            if (table == null)
            {
                throw new ExecutionException(m_Script, this, "table [+] 操作只限两个[table]之间,传入数据类型:" + value.Type);
            }
            ScriptTable          ret  = m_Script.CreateTable();
            ScriptObject         obj  = null;
            ScriptScriptFunction func = null;

            foreach (KeyValuePair <object, ScriptObject> pair in m_listObject)
            {
                obj = pair.Value.Clone();
                if (obj is ScriptScriptFunction)
                {
                    func = (ScriptScriptFunction)obj;
                    if (!func.IsStaticFunction)
                    {
                        func.SetTable(ret);
                    }
                }
                ret.m_listObject[pair.Key] = obj;
            }
            foreach (KeyValuePair <object, ScriptObject> pair in table.m_listObject)
            {
                obj = pair.Value.Clone();
                if (obj is ScriptScriptFunction)
                {
                    func = (ScriptScriptFunction)obj;
                    if (!func.IsStaticFunction)
                    {
                        func.SetTable(ret);
                    }
                }
                ret.m_listObject[pair.Key] = obj;
            }
            return(ret);
        }
Ejemplo n.º 8
0
        ScriptObject ParseCall(CodeCallFunction scriptFunction, bool needRet)
        {
            ScriptObject obj = ResolveOperand(scriptFunction.Member);

            // 安装function this 信息
            if (obj is ScriptScriptFunction)
            {
                ScriptScriptFunction suf = obj as ScriptScriptFunction;
                if (!suf.isCloure)
                {
                    if (scriptFunction.Member is CodeMember)
                    {
                        CodeMember member = scriptFunction.Member as CodeMember;
                        if (member.Parent == null)
                        {
                            suf.SetTable(m_script.GetGlobalTable());
                        }
                        else
                        {
                            ScriptObject sotable = ResolveOperand(member.Parent);
                            if (sotable is ScriptTable)
                            {
                                suf.SetTable(sotable as ScriptTable);
                            }
                        }
                    }
                }
            }

            int num = scriptFunction.ParametersCount;

            ScriptObject[] parameters = new ScriptObject[num];
            for (int i = 0; i < num; ++i)
            {
                //此处要调用Assign 如果传入number string等基础类型  在函数内自运算的话 会影响 传入的值
                parameters[i] = ResolveOperand(scriptFunction.Parameters[i]).Assign();

                // 创建闭包
                if (parameters[i] is ScriptScriptFunction)
                {
                    ScriptScriptFunction ssf = parameters[i] as ScriptScriptFunction;
                    ssf.isCloure = true;
                    if (scriptFunction.Parameters[i] is CodeMember)
                    {
                        CodeMember member = scriptFunction.Parameters[i] as CodeMember;
                        if (member.Parent == null)
                        {
                            ssf.SetTable(m_script.GetGlobalTable());
                        }
                        else
                        {
                            ScriptObject sotable = ResolveOperand(member.Parent);
                            if (sotable is ScriptTable)
                            {
                                ssf.SetTable(sotable as ScriptTable);
                            }
                        }
                    }
                    else if (scriptFunction.Parameters[i] is CodeFunction)
                    {
                        if (obj is ScriptScriptFunction)
                        {
                            ScriptScriptFunction suf = obj as ScriptScriptFunction;
                            ssf.SetTable((ScriptTable)suf.GetValue("this"));
                        }
                    }
                }
            }
            m_script.PushStackInfo();

            object ret = obj.Call(parameters);

            m_script.PopStackInfo();
            return(needRet ? m_script.CreateObject(ret) : null);
        }