public static LuaValue Interpreter(string luaCode, LuaTable enviroment) { Chunk chunk = Parse(luaCode); chunk.Enviroment = enviroment; return(chunk.Execute()); }
public static LuaValue Interpreter(string luaCode, LuaTable enviroment) { try { Chunk chunk = Parse(luaCode); chunk.Enviroment = enviroment; return(chunk.Execute()); } finally { parser.ClearErrors(); } }
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(); }) )); }