diff options
author | Li Jin <dragon-fly@qq.com> | 2023-03-30 09:20:55 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-03-30 09:20:55 +0800 |
commit | 85c45027dabaf46e81d56414bd60ec4d727a4edd (patch) | |
tree | a5f649542e79392771cabab9f6f66d2a9cd7be09 | |
parent | 0a55542c9a2eb958afe4fc6797b5400902c1e058 (diff) | |
download | yuescript-85c45027dabaf46e81d56414bd60ec4d727a4edd.tar.gz yuescript-85c45027dabaf46e81d56414bd60ec4d727a4edd.tar.bz2 yuescript-85c45027dabaf46e81d56414bd60ec4d727a4edd.zip |
fix package.path setting.
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 18 | ||||
-rw-r--r-- | src/yuescript/yue_compiler.h | 1 | ||||
-rw-r--r-- | src/yuescript/yuescript.h | 4 |
3 files changed, 22 insertions, 1 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 6b2b27d..a98d1c2 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -3852,10 +3852,21 @@ private: | |||
3852 | _useModule = true; | 3852 | _useModule = true; |
3853 | if (!L) { | 3853 | if (!L) { |
3854 | L = luaL_newstate(); | 3854 | L = luaL_newstate(); |
3855 | int top = lua_gettop(L); | ||
3856 | DEFER(lua_settop(L, top)); | ||
3855 | if (_luaOpen) { | 3857 | if (_luaOpen) { |
3856 | _luaOpen(static_cast<void*>(L)); | 3858 | _luaOpen(static_cast<void*>(L)); |
3857 | } | 3859 | } |
3858 | passOptions(); | 3860 | passOptions(); |
3861 | auto it = _config.options.find("path"s); | ||
3862 | if (it != _config.options.end()) { | ||
3863 | lua_getglobal(L, "package"); | ||
3864 | auto path = it->second + ';'; | ||
3865 | lua_pushlstring(L, path.c_str(), path.size()); | ||
3866 | lua_getfield(L, -2, "path"); | ||
3867 | lua_concat(L, 2); | ||
3868 | lua_setfield(L, -2, "path"); | ||
3869 | } | ||
3859 | _stateOwner = true; | 3870 | _stateOwner = true; |
3860 | } | 3871 | } |
3861 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE | 3872 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE |
@@ -8498,4 +8509,11 @@ CompileInfo YueCompiler::compile(std::string_view codes, const YueConfig& config | |||
8498 | return _compiler->compile(codes, config); | 8509 | return _compiler->compile(codes, config); |
8499 | } | 8510 | } |
8500 | 8511 | ||
8512 | void YueCompiler::clear(void* luaState) { | ||
8513 | auto L = static_cast<lua_State*>(luaState); | ||
8514 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE | ||
8515 | lua_pushnil(L); | ||
8516 | lua_rawset(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE] = nil | ||
8517 | } | ||
8518 | |||
8501 | } // namespace yue | 8519 | } // namespace yue |
diff --git a/src/yuescript/yue_compiler.h b/src/yuescript/yue_compiler.h index 860ddfb..bdffe08 100644 --- a/src/yuescript/yue_compiler.h +++ b/src/yuescript/yue_compiler.h | |||
@@ -82,6 +82,7 @@ public: | |||
82 | bool sameModule = false); | 82 | bool sameModule = false); |
83 | virtual ~YueCompiler(); | 83 | virtual ~YueCompiler(); |
84 | CompileInfo compile(std::string_view codes, const YueConfig& config = {}); | 84 | CompileInfo compile(std::string_view codes, const YueConfig& config = {}); |
85 | static void clear(void* luaState); | ||
85 | 86 | ||
86 | private: | 87 | private: |
87 | std::unique_ptr<YueCompilerImpl> _compiler; | 88 | std::unique_ptr<YueCompilerImpl> _compiler; |
diff --git a/src/yuescript/yuescript.h b/src/yuescript/yuescript.h index 271a982..19e636c 100644 --- a/src/yuescript/yuescript.h +++ b/src/yuescript/yuescript.h | |||
@@ -64,7 +64,9 @@ local function find_modulepath(name) | |||
64 | end | 64 | end |
65 | local file_exist, file_path | 65 | local file_exist, file_path |
66 | local tried = {} | 66 | local tried = {} |
67 | local paths = {package.path, yue.options.path} | 67 | local paths = {} |
68 | paths[#paths + 1] = yue.options.path | ||
69 | paths[#paths + 1] = package.path | ||
68 | for i = 1, #paths do | 70 | for i = 1, #paths do |
69 | local yue_path = paths[i] | 71 | local yue_path = paths[i] |
70 | for path in yue_path:gmatch("[^;]+") do | 72 | for path in yue_path:gmatch("[^;]+") do |