/// <summary> /// Executes a Lua chnk and returns all the chunk's return values in an array. /// </summary> /// <param name="chunk">Chunk to execute</param> /// <param name="chunkName">Name to associate with the chunk</param> /// <returns></returns> public object[] DoString(string chunk, string chunkName, LuaTable env) { int oldTop = LuaDLL.lua_gettop(L); byte[] bt = Encoding.UTF8.GetBytes(chunk); if (LuaDLL.luaL_loadbuffer(L, bt, bt.Length, chunkName) == 0) { if (env != null) { env.push(L); //LuaDLL.lua_setfenv(L, -1); LuaDLL.lua_setfenv(L, -2); } if (LuaDLL.lua_pcall(L, 0, -1, 0) == 0) { return(translator.popValues(L, oldTop)); } else { ThrowExceptionFromError(oldTop); } } else { ThrowExceptionFromError(oldTop); } return(null); // Never reached - keeps compiler happy }
public int Resume(object[] args, LuaTable env) { int result = 0; int oldTop = LuaDLL.lua_gettop(L); // If thread isn't started, it needs to be restarted if (start) { start = false; func.push(L); if (env != null) { env.push(L); LuaDLL.lua_setfenv(L, -2); } result = resume(args, oldTop); } // If thread is suspended, resume it else if (IsSuspended()) { result = resume(args, oldTop); } return(result); }
/* * Excutes a Lua file and returns all the chunk's return * values in an array */ public object[] DoFile(string fileName, LuaTable env) { LuaDLL.lua_pushstdcallcfunction(L, tracebackFunction); int oldTop = LuaDLL.lua_gettop(L); // Load with Unity3D resources Debug.Log("fileName==" + fileName); byte[] text = LuaStatic.DefaultLoader(fileName); if (text == null) { Debug.LogError("lua dofile failed which path is:::" + fileName + "开始尝试Resources文件夹下加载"); text = ResLoadAsset(fileName); if (text == null) { LuaDLL.lua_pop(L, 1); Debug.LogError("lua dofile failed which path is:::" + fileName + "尝试Resources文件夹下加载失败!!!!,移动端路径错误!!!!"); return(null); } } else { Debug.LogError("text != null 长度:" + text.Length); } //Encoding.UTF8.GetByteCount(text) if (LuaDLL.luaL_loadbuffer(L, text, text.Length, fileName) == 0) { if (env != null) { env.push(L); //LuaDLL.lua_setfenv(L, -1); LuaDLL.lua_setfenv(L, -2); } if (LuaDLL.lua_pcall(L, 0, -1, -2) == 0) { object[] results = translator.popValues(L, oldTop); LuaDLL.lua_pop(L, 1); return(results); } else { ThrowExceptionFromError(oldTop); LuaDLL.lua_pop(L, 1); } } else { ThrowExceptionFromError(oldTop); LuaDLL.lua_pop(L, 1); } return(null); // Never reached - keeps compiler happy }
/* * Excutes a Lua file and returns all the chunk's return * values in an array */ public object[] DoFile(string fileName, LuaTable env) { LuaDLL.lua_pushstdcallcfunction(L, tracebackFunction); int oldTop = LuaDLL.lua_gettop(L); // Load with Unity3D resources byte[] text = LuaStatic.Load(fileName); // Debugger.LogWarning("---------------" + fileName); if (text == null) { if (!fileName.Contains("mobdebug")) { Debugger.LogError("Loader lua file failed: {0}", fileName); } LuaDLL.lua_pop(L, 1); return(null); } // string luafile = Util.LuaPath(fileName); //Encoding.UTF8.GetByteCount(text) int len = LuaStatic.getBytesLength(text); if (LuaDLL.luaL_loadbuffer(L, text, len, fileName) == 0) { if (env != null) { env.push(L); //LuaDLL.lua_setfenv(L, -1); LuaDLL.lua_setfenv(L, -2); } if (LuaDLL.lua_pcall(L, 0, -1, -2) == 0) { object[] results = translator.popValues(L, oldTop); LuaDLL.lua_pop(L, 1); return(results); } else { ThrowExceptionFromError(oldTop); LuaDLL.lua_pop(L, 1); } } else { ThrowExceptionFromError(oldTop); LuaDLL.lua_pop(L, 1); } return(null); // Never reached - keeps compiler happy }
/// <summary> /// 我添加的两个相应的函数 /// </summary> /// <param name="fileName"></param> /// <param name="chunk"></param> /// <returns></returns> public object[] DoStringFile(string fileName, string chunk) { LuaDLL.lua_pushstdcallcfunction(L, tracebackFunction); int oldTop = LuaDLL.lua_gettop(L); LuaTable env = null; // Load with Unity3D resources byte[] text = Encoding.UTF8.GetBytes(chunk); if (text == null) { Debugger.LogError("Loader lua file failed: {0}", fileName); LuaDLL.lua_pop(L, 1); return(null); } //Encoding.UTF8.GetByteCount(text) if (LuaDLL.luaL_loadbuffer(L, text, text.Length, fileName) == 0) { if (env != null) { env.push(L); //LuaDLL.lua_setfenv(L, -1); LuaDLL.lua_setfenv(L, -2); } if (LuaDLL.lua_pcall(L, 0, -1, -2) == 0) { object[] results = translator.popValues(L, oldTop); LuaDLL.lua_pop(L, 1); return(results); } else { ThrowExceptionFromError(oldTop); LuaDLL.lua_pop(L, 1); } } else { ThrowExceptionFromError(oldTop); LuaDLL.lua_pop(L, 1); } return(null); // Never reached - keeps compiler happy }
/* * Excutes a Lua file and returns all the chunk's return * values in an array */ public object[] DoFile(string fileName, LuaTable env) { LuaDLL.lua_pushstdcallcfunction(L, tracebackFunction); int oldTop = LuaDLL.lua_gettop(L); // Load with Unity3D resources byte[] text = LuaStatic.LoadLua(fileName); if (text == null) { ThrowExceptionFromError(oldTop); } //Encoding.UTF8.GetByteCount(text) if (LuaDLL.luaL_loadbuffer(L, text, text.Length, fileName) == 0) { if (env != null) { env.push(L); //LuaDLL.lua_setfenv(L, -1); LuaDLL.lua_setfenv(L, -2); } // lxc Test添加文件名参数作为模块名字 string moduleName = Path.GetFileNameWithoutExtension(fileName); translator.push(L, moduleName); //if (LuaDLL.lua_pcall(L, 0, -1, -2) == 0) if (LuaDLL.lua_pcall(L, 1, -1, -2) == 0) { object[] results = translator.popValues(L, oldTop); LuaDLL.lua_pop(L, 1); return(results); } else { ThrowExceptionFromError(oldTop); } } else { ThrowExceptionFromError(oldTop); } return(null); // Never reached - keeps compiler happy }
public object[] DoFile(string fileName, LuaTable env) { LuaDLL.lua_pushstdcallcfunction(this.L, this.tracebackFunction, 0); int oldTop = LuaDLL.lua_gettop(this.L); byte[] array = LuaStatic.Load(fileName); if (array == null) { if (!fileName.Contains("mobdebug")) { Debugger.LogError("Loader lua file failed: {0}", new object[] { fileName }); } LuaDLL.lua_pop(this.L, 1); return(null); } string name = Util.LuaPath(fileName); if (LuaDLL.luaL_loadbuffer(this.L, array, array.Length, name) == 0) { if (env != null) { env.push(this.L); LuaDLL.lua_setfenv(this.L, -2); } if (LuaDLL.lua_pcall(this.L, 0, -1, -2) == 0) { object[] result = this.translator.popValues(this.L, oldTop); LuaDLL.lua_pop(this.L, 1); return(result); } this.ThrowExceptionFromError(oldTop); LuaDLL.lua_pop(this.L, 1); } else { this.ThrowExceptionFromError(oldTop); LuaDLL.lua_pop(this.L, 1); } return(null); }
public LuaFunction LoadString(string chunk, string name, LuaTable env) { int oldTop = LuaDLL.lua_gettop(this.L); byte[] bytes = Encoding.UTF8.GetBytes(chunk); if (LuaDLL.luaL_loadbuffer(this.L, bytes, bytes.Length, name) != 0) { this.ThrowExceptionFromError(oldTop); } if (env != null) { env.push(this.L); LuaDLL.lua_setfenv(this.L, -2); } LuaFunction function = this.translator.getFunction(this.L, -1); this.translator.popValues(this.L, oldTop); return(function); }
/// <summary> /// /// </summary> /// <param name="chunk"></param> /// <param name="name"></param> /// <returns></returns> public LuaFunction LoadString(byte[] chunk, string name, LuaTable env) { int oldTop = LuaDLL.lua_gettop(L); if (LuaDLL.luaL_loadbuffer(L, chunk, chunk.Length, name) != 0) { ThrowExceptionFromError(oldTop); } if (env != null) { env.push(L); LuaDLL.lua_setfenv(L, -2); } LuaFunction result = translator.getFunction(L, -1); translator.popValues(L, oldTop); return(result); }
/* * Excutes a Lua file and returns all the chunk's return * values in an array */ public object[] DoFile(string fileName, LuaTable env) { LuaDLL.lua_pushstdcallcfunction(L, tracebackFunction); int oldTop = LuaDLL.lua_gettop(L); // Load with Unity3D resources TextAsset file = (TextAsset)Resources.Load(fileName); if (file == null) { ThrowExceptionFromError(oldTop); } if (LuaDLL.luaL_loadbuffer(L, file.bytes, file.bytes.Length, fileName) == 0) { if (env != null) { env.push(L); //LuaDLL.lua_setfenv(L, -1); LuaDLL.lua_setfenv(L, -2); } if (LuaDLL.lua_pcall(L, 0, -1, -2) == 0) { object[] results = translator.popValues(L, oldTop); LuaDLL.lua_pop(L, 1); return(results); } else { ThrowExceptionFromError(oldTop); } } else { ThrowExceptionFromError(oldTop); } return(null); // Never reached - keeps compiler happy }
public object[] DoString(string chunk, string chunkName, LuaTable env) { int oldTop = LuaDLL.lua_gettop(this.L); byte[] bytes = Encoding.UTF8.GetBytes(chunk); if (LuaDLL.luaL_loadbuffer(this.L, bytes, bytes.Length, chunkName) == 0) { if (env != null) { env.push(this.L); LuaDLL.lua_setfenv(this.L, -2); } if (LuaDLL.lua_pcall(this.L, 0, -1, 0) == 0) { return(this.translator.popValues(this.L, oldTop)); } this.ThrowExceptionFromError(oldTop); } else { this.ThrowExceptionFromError(oldTop); } return(null); }
public void LuaSetEnv(int idx) { LuaDLL.lua_setfenv(L, idx); }