/* * Excutes a Lua file and returns all the chunk's return * values in an array */ public object[] DoFile(string fileName) { int oldTop = LuaLib.lua_gettop(luaState); if (LuaLib.luaL_loadfile(luaState, fileName) == 0) { executing = true; try { if (LuaLib.lua_pcall(luaState, 0, -1, 0) == 0) { return(translator.popValues(luaState, oldTop)); } else { ThrowExceptionFromError(oldTop); } } finally { executing = false; } } else { ThrowExceptionFromError(oldTop); } return(null); // Never reached - keeps compiler happy }
/* * Calls the object as a function with the provided arguments and * casting returned values to the types in returnTypes before returning * them in an array */ internal object[] callFunction(object function, object[] args, Type[] returnTypes) { int nArgs = 0; int oldTop = LuaLib.lua_gettop(luaState); if (!LuaLib.lua_checkstack(luaState, args.Length + 6)) { throw new LuaException("Lua stack overflow"); } translator.push(luaState, function); if (!args.IsNull()) { nArgs = args.Length; for (int i = 0; i < args.Length; i++) { translator.push(luaState, args[i]); } } executing = true; try { int error = LuaLib.lua_pcall(luaState, nArgs, -1, 0); if (error != 0) { ThrowExceptionFromError(oldTop); } } finally { executing = false; } return(!returnTypes.IsNull() ? translator.popValues(luaState, oldTop, returnTypes) : translator.popValues(luaState, oldTop)); }