Пример #1
0
        public override LuaValue Evaluate(LuaValue baseValue, LuaTable enviroment)
        {
            LuaValue    value    = LuaValue.GetKeyValue(baseValue, new LuaString(this.Method));
            LuaFunction function = value as LuaFunction;

            if (function != null)
            {
                if (this.Args.Table != null)
                {
                    return(function.Function.Invoke(new LuaValue[] { baseValue, this.Args.Table.Evaluate(enviroment) }));
                }
                else if (this.Args.String != null)
                {
                    return(function.Function.Invoke(new LuaValue[] { baseValue, this.Args.String.Evaluate(enviroment) }));
                }
                else
                {
                    //[PixelCrushers]List<LuaValue> args = this.Args.ArgList.ConvertAll(arg => arg.Evaluate(enviroment));
                    List <LuaValue> args = LuaInterpreterExtensions.EvaluateAll(this.Args.ArgList, enviroment);
                    args.Insert(0, baseValue);
                    return(function.Function.Invoke(args.ToArray()));
                }
            }
            else
            {
                throw new Exception("Invoke method call on non function value.");
            }
        }
Пример #2
0
        public override LuaValue Execute(LuaTable enviroment, out bool isBreak)
        {
            //[PixelCrushers]LuaValue[] values = this.ExprList.ConvertAll(expr => expr.Evaluate(enviroment)).ToArray();
            LuaValue[] values = LuaInterpreterExtensions.EvaluateAll(this.ExprList, enviroment).ToArray();

            LuaValue[] neatValues = LuaMultiValue.UnWrapLuaValues(values);

            for (int i = 0; i < Math.Min(this.VarList.Count, neatValues.Length); i++)
            {
                Var var = this.VarList[i];

                if (var.Accesses.Count == 0)
                {
                    VarName varName = var.Base as VarName;

                    if (varName != null)
                    {
                        SetKeyValue(enviroment, new LuaString(varName.Name), values[i]);
                        continue;
                    }
                }
                else
                {
                    LuaValue baseValue = var.Base.Evaluate(enviroment);

                    for (int j = 0; j < var.Accesses.Count - 1; j++)
                    {
                        Access access = var.Accesses[j];

                        baseValue = access.Evaluate(baseValue, enviroment);
                    }

                    Access lastAccess = var.Accesses[var.Accesses.Count - 1];

                    NameAccess nameAccess = lastAccess as NameAccess;
                    if (nameAccess != null)
                    {
                        if (baseValue == null || (baseValue is LuaNil))
                        {
                            throw new System.NullReferenceException("Cannot assign to a null value. Are you trying to assign to a nonexistent table element?.");
                        }
                        SetKeyValue(baseValue, new LuaString(nameAccess.Name), values[i]);
                        continue;
                    }

                    KeyAccess keyAccess = lastAccess as KeyAccess;
                    if (lastAccess != null)
                    {
                        SetKeyValue(baseValue, keyAccess.Key.Evaluate(enviroment), values[i]);
                    }
                }
            }

            isBreak = false;
            return(null);
        }
        public override LuaValue Execute(LuaTable enviroment, out bool isBreak)
        {
            //[PixelCrushers]LuaValue[] values = this.ExprList.ConvertAll(expr => expr.Evaluate(enviroment)).ToArray();
            LuaValue[] values = LuaInterpreterExtensions.EvaluateAll(this.ExprList, enviroment).ToArray();

            LuaValue[] neatValues = LuaMultiValue.UnWrapLuaValues(values);

            LuaFunction func    = neatValues[0] as LuaFunction;
            LuaValue    state   = neatValues[1];
            LuaValue    loopVar = neatValues[2];

            var table = new LuaTable(enviroment);

            this.Body.Enviroment = table;

            while (true)
            {
                LuaValue      result     = func.Invoke(new LuaValue[] { state, loopVar });
                LuaMultiValue multiValue = result as LuaMultiValue;

                if (multiValue != null)
                {
                    neatValues = LuaMultiValue.UnWrapLuaValues(multiValue.Values);
                    loopVar    = neatValues[0];

                    for (int i = 0; i < Math.Min(this.NameList.Count, neatValues.Length); i++)
                    {
                        table.SetNameValue(this.NameList[i], neatValues[i]);
                    }
                }
                else
                {
                    loopVar = result;
                    table.SetNameValue(this.NameList[0], result);
                }

                if (loopVar == LuaNil.Nil)
                {
                    break;
                }

                var returnValue = this.Body.Execute(out isBreak);
                if (returnValue != null || isBreak == true)
                {
                    isBreak = false;
                    return(returnValue);
                }
            }

            isBreak = false;
            return(null);
        }
Пример #4
0
        public LuaValue InvokeMethod(LuaValue[] args)
        {
            if (Method == null || args == null)
            {
                return(LuaNil.Nil);
            }
            object[] objectArgs = new object[args.Length];
            for (int i = 0; i < args.Length; i++)
            {
                objectArgs[i] = LuaInterpreterExtensions.LuaValueToObject(args[i]);
            }
            object result = Method.Invoke(Target, objectArgs);

            return(LuaInterpreterExtensions.ObjectToLuaValue(result));
        }
        public override LuaValue Evaluate(LuaValue baseValue, LuaTable enviroment)
        {
            LuaFunction function = baseValue as LuaFunction;

            if (function != null)
            {
                //[PixelCrushers] Removed (not WinRT compatible, and not needed for Dialogue System)
                //if (function.Function.Method.DeclaringType.FullName == "Language.Lua.Library.BaseLib" &&
                //    (function.Function.Method.Name == "loadstring" || function.Function.Method.Name == "dofile"))
                //{
                //    if (this.Args.String != null)
                //    {
                //        return function.Function.Invoke(new LuaValue[] { this.Args.String.Evaluate(enviroment), enviroment });
                //    }
                //    else
                //    {
                //        return function.Function.Invoke(new LuaValue[] { this.Args.ArgList[0].Evaluate(enviroment), enviroment });
                //    }
                //}

                if (this.Args.Table != null)
                {
                    return(function.Function.Invoke(new LuaValue[] { this.Args.Table.Evaluate(enviroment) }));
                }
                else if (this.Args.String != null)
                {
                    return(function.Function.Invoke(new LuaValue[] { this.Args.String.Evaluate(enviroment) }));
                }
                else
                {
                    //[PixelCrushers] Was: List<LuaValue> args = this.Args.ArgList.ConvertAll(arg => arg.Evaluate(enviroment));
                    List <LuaValue> args = LuaInterpreterExtensions.EvaluateAll(this.Args.ArgList, enviroment);
                    return(function.Function.Invoke(LuaMultiValue.UnWrapLuaValues(args.ToArray())));
                }
            }
            else
            {
                //[PixelCrushers Was: throw new Exception("Invoke function call on non function value.");
                throw new Exception("Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?");
            }
        }
Пример #6
0
 public LuaValue InvokeMethod(LuaValue[] args)
 {
     if (Method == null || args == null)
     {
         return(LuaNil.Nil);
     }
     object[] objectArgs = new object[args.Length];
     for (int i = 0; i < args.Length; i++)
     {
         objectArgs[i] = LuaInterpreterExtensions.LuaValueToObject(args[i]);
     }
     try
     {
         object result = Method.Invoke(Target, objectArgs);
         return(LuaInterpreterExtensions.ObjectToLuaValue(result));
     }
     catch (Exception e)
     {
         UnityEngine.Debug.LogException(e);
         throw e;
     }
 }
        public override LuaValue Execute(LuaTable enviroment, out bool isBreak)
        {
            //[PixelCrushers]LuaValue[] values = this.ExprList.ConvertAll(expr => expr.Evaluate(enviroment)).ToArray();
            LuaValue[] values = LuaInterpreterExtensions.EvaluateAll(this.ExprList, enviroment).ToArray();

            LuaValue[] neatValues = LuaMultiValue.UnWrapLuaValues(values);

            for (int i = 0; i < Math.Min(this.NameList.Count, neatValues.Length); i++)
            {
                enviroment.RawSetValue(this.NameList[i], neatValues[i]);
            }

            if (neatValues.Length < this.NameList.Count)
            {
                for (int i = neatValues.Length; i < this.NameList.Count - neatValues.Length; i++)
                {
                    enviroment.RawSetValue(this.NameList[i], LuaNil.Nil);
                }
            }

            isBreak = false;
            return(null);
        }