internal static int loader(IntPtr L) { LuaState state = LuaState.get(L); string fileName = LuaDLL.lua_tostring(L, 1); fileName = "Lua/" + fileName; //放在Lua目录里 string absoluteFn = ""; byte[] bytes = state.loadFile(fileName, ref absoluteFn); if (bytes != null) { #if LUA_DEBUG if (absoluteFn != "") { fileName = absoluteFn; } #endif if (LuaDLL.luaL_loadbuffer(L, bytes, bytes.Length, "@" + fileName) == 0) { LuaObject.pushValue(L, true); LuaDLL.lua_insert(L, -2); return(2); } else { string errstr = LuaDLL.lua_tostring(L, -1); return(LuaObject.error(L, errstr)); } } LuaObject.pushValue(L, true); LuaDLL.lua_pushnil(L); return(2); }
string fetchLuaSource(string fileName, int line = -1, int range = 3) { if (!luaSource.ContainsKey(fileName)) { byte[] bytes = LuaState.loadFile(fileName); if (bytes == null) { return(null); } string text = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length); text = text.Replace("\r\n", "\n"); string[] splitLines = text.Split(new char[] { '\n' }); luaSource.Add(fileName, splitLines); } var lines = luaSource[fileName]; int start, end; if (line >= 0) { start = line - range; end = line + range; if (start < 0) { start = 0; } if (end >= lines.Length) { end = lines.Length; } } else { start = 0; end = lines.Length; } string ret = ""; for (int n = start; n < end; n++) { ret += string.Format("{0}{1}\t", n + 1, n == line ? ">" : ""); ret += lines[n]; ret += "\n"; } return(ret); }
internal static int loader(IntPtr L) { LuaState state = LuaState.get(L); string fileName = LuaDLL.lua_tostring(L, 1); byte[] bytes = state.loadFile(fileName); if (bytes != null) { if (LuaDLL.luaL_loadbuffer(L, bytes, bytes.Length, "@" + fileName) == 0) { LuaObject.pushValue(L, true); LuaDLL.lua_insert(L, -2); return(2); } else { string errstr = LuaDLL.lua_tostring(L, -1); return(LuaObject.error(L, errstr)); } } LuaObject.pushValue(L, true); LuaDLL.lua_pushnil(L); return(2); }