mirror of https://github.com/odrling/Aegisub
Replace lua's default lua module loader with one which uses our UTF-8-supporting script reader.
Originally committed to SVN as r4060.
This commit is contained in:
parent
4343fb44ef
commit
b5064f8fc9
|
@ -201,13 +201,18 @@ namespace Automation4 {
|
|||
wxFileName path(StandardPaths::DecodePath(toker.GetNextToken()));
|
||||
if (path.IsOk() && !path.IsRelative() && path.DirExists()) {
|
||||
wxCharBuffer p = path.GetLongPath().utf8_str();
|
||||
lua_pushfstring(L, ";%s/?.lua;%s/?/init.lua", p.data(), p.data());
|
||||
lua_pushfstring(L, ";%s?.lua;%s?/init.lua", p.data(), p.data());
|
||||
lua_concat(L, 2);
|
||||
}
|
||||
}
|
||||
|
||||
lua_settable(L, -3);
|
||||
lua_pop(L, 1); // pop package
|
||||
|
||||
// Replace the default lua module loader with our utf-8 compatible one
|
||||
lua_getfield(L, -1, "loaders");
|
||||
lua_pushcfunction(L, LuaModuleLoader);
|
||||
lua_rawseti(L, -2, 2);
|
||||
lua_pop(L, 2);
|
||||
_stackcheck.check_stack(0);
|
||||
|
||||
// prepare stuff in the registry
|
||||
|
@ -408,6 +413,37 @@ namespace Automation4 {
|
|||
return 4;
|
||||
}
|
||||
|
||||
/// @brief Module loader which uses our include rather than Lua's, for unicode file support
|
||||
/// @param L The Lua state
|
||||
/// @return Always 1 per loader_Lua?
|
||||
int LuaScript::LuaModuleLoader(lua_State *L)
|
||||
{
|
||||
int pretop = lua_gettop(L);
|
||||
wxString module(lua_tostring(L, -1), wxConvUTF8);
|
||||
module.Replace(".", LUA_DIRSEP);
|
||||
|
||||
lua_getglobal(L, "package");
|
||||
lua_pushstring(L, "path");
|
||||
lua_gettable(L, -2);
|
||||
wxString package_paths(lua_tostring(L, -1), wxConvUTF8);
|
||||
lua_pop(L, 2);
|
||||
|
||||
wxStringTokenizer toker(package_paths, L";", wxTOKEN_STRTOK);
|
||||
while (toker.HasMoreTokens()) {
|
||||
wxString filename = toker.GetNextToken();
|
||||
filename.Replace(L"?", module);
|
||||
if (wxFileName::FileExists(filename)) {
|
||||
LuaScriptReader script_reader(filename);
|
||||
if (lua_load(L, script_reader.reader_func, &script_reader, filename.utf8_str())) {
|
||||
lua_pushfstring(L, "Error loading Lua module \"%s\":\n\n%s", filename.utf8_str().data(), lua_tostring(L, -1));
|
||||
lua_error(L);
|
||||
return lua_gettop(L) - pretop;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lua_gettop(L) - pretop;
|
||||
}
|
||||
|
||||
/// @brief DOCME
|
||||
/// @param L
|
||||
/// @return
|
||||
|
|
|
@ -293,6 +293,7 @@ namespace Automation4 {
|
|||
|
||||
static int LuaTextExtents(lua_State *L);
|
||||
static int LuaInclude(lua_State *L);
|
||||
static int LuaModuleLoader(lua_State *L);
|
||||
static int LuaFrameFromMs(lua_State *L);
|
||||
static int LuaMsFromFrame(lua_State *L);
|
||||
static int LuaVideoSize(lua_State *L);
|
||||
|
|
Loading…
Reference in New Issue