コード例 #1
0
        public static LuaValue Interpreter(string luaCode, LuaTable enviroment)
        {
            Chunk chunk = Parse(luaCode);

            chunk.Enviroment = enviroment;
            return(chunk.Execute());
        }
コード例 #2
0
 public static LuaValue Interpreter(string luaCode, LuaTable enviroment)
 {
     try
     {
         Chunk chunk = Parse(luaCode);
         chunk.Enviroment = enviroment;
         return(chunk.Execute());
     }
     finally
     {
         parser.ClearErrors();
     }
 }
コード例 #3
0
        public LuaValue Evaluate(LuaTable enviroment)
        {
            return(new LuaFunction(
                       new LuaFunc(delegate(LuaValue[] args)
            {
                var table = new LuaTable(enviroment);

                List <string> names = ParamList.NameList;

                if (names.Count > 0)
                {
                    int argCount = Math.Min(names.Count, args.Length);

                    for (int i = 0; i < argCount; i++)
                    {
                        table.SetNameValue(names[i], args[i]);
                    }

                    if (ParamList.HasVarArg)
                    {
                        if (argCount < args.Length)
                        {
                            LuaValue[] remainedArgs = new LuaValue[args.Length - argCount];
                            for (int i = 0; i < remainedArgs.Length; i++)
                            {
                                remainedArgs[i] = args[argCount + i];
                            }
                            table.SetNameValue("...", new LuaMultiValue(remainedArgs));
                        }
                    }
                }
                else if (ParamList.IsVarArg != null)
                {
                    table.SetNameValue("...", new LuaMultiValue(args));
                }

                Chunk.Enviroment = table;

                return Chunk.Execute();
            })
                       ));
        }