From 0a12e60a369b54a8aa8a82d5a118fdaf704974fd Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sun, 24 Jan 2010 19:07:34 +0000 Subject: [PATCH] Add the Automation include path to lua's module load path. Originally committed to SVN as r4038. --- aegisub/src/auto4_lua.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/aegisub/src/auto4_lua.cpp b/aegisub/src/auto4_lua.cpp index ee791af8f..2b3bdfa35 100644 --- a/aegisub/src/auto4_lua.cpp +++ b/aegisub/src/auto4_lua.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #endif @@ -58,6 +59,7 @@ #include "auto4_lua_factory.h" #include "auto4_lua_scriptreader.h" #include "options.h" +#include "standard_paths.h" #include "text_file_reader.h" #include "vfr.h" #include "video_context.h" @@ -188,6 +190,26 @@ namespace Automation4 { lua_pushcfunction(L, LuaInclude); lua_setglobal(L, "include"); + // add include_path to the module load path + lua_getglobal(L, "package"); + lua_pushstring(L, "path"); + lua_pushstring(L, "path"); + lua_gettable(L, -3); + + wxStringTokenizer toker(Options.AsText(_T("Automation Include Path")), _T("|"), wxTOKEN_STRTOK); + while (toker.HasMoreTokens()) { + 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_concat(L, 2); + } + } + + lua_settable(L, -3); + lua_pop(L, 1); // pop package + _stackcheck.check_stack(0); + // prepare stuff in the registry // reference to the script object lua_pushlightuserdata(L, this); @@ -386,7 +408,6 @@ namespace Automation4 { return 4; } - /// @brief DOCME /// @param L /// @return @@ -1152,5 +1173,3 @@ namespace Automation4 { }; #endif // WITH_AUTO4_LUA - -