diff options
author | Li Jin <dragon-fly@qq.com> | 2022-07-13 14:46:55 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-07-13 14:46:55 +0800 |
commit | a1d341085eed96d567329a30f2cf57c95fe6f071 (patch) | |
tree | 37d359a02b99cf94fa52cfc43eb9c5c80ecfeb89 /src/yuescript/yue_compiler.cpp | |
parent | aa194667c7cb7bb70f2a58477555d1419ae33eb0 (diff) | |
download | yuescript-a1d341085eed96d567329a30f2cf57c95fe6f071.tar.gz yuescript-a1d341085eed96d567329a30f2cf57c95fe6f071.tar.bz2 yuescript-a1d341085eed96d567329a30f2cf57c95fe6f071.zip |
auto add search path for cmd tools.
Diffstat (limited to '')
-rwxr-xr-x | src/yuescript/yue_compiler.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index c7ceeb4..c68746c 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -56,7 +56,7 @@ using namespace parserlib; | |||
56 | 56 | ||
57 | typedef std::list<std::string> str_list; | 57 | typedef std::list<std::string> str_list; |
58 | 58 | ||
59 | const std::string_view version = "0.13.2"sv; | 59 | const std::string_view version = "0.13.3"sv; |
60 | const std::string_view extension = "yue"sv; | 60 | const std::string_view extension = "yue"sv; |
61 | 61 | ||
62 | class YueCompilerImpl { | 62 | class YueCompilerImpl { |
@@ -6887,13 +6887,23 @@ private: | |||
6887 | DEFER(lua_settop(L, top)); | 6887 | DEFER(lua_settop(L, top)); |
6888 | pushYue("find_modulepath"sv); // cur find_modulepath | 6888 | pushYue("find_modulepath"sv); // cur find_modulepath |
6889 | lua_pushlstring(L, moduleName.c_str(), moduleName.size()); // cur find_modulepath moduleName | 6889 | lua_pushlstring(L, moduleName.c_str(), moduleName.size()); // cur find_modulepath moduleName |
6890 | if (lua_pcall(L, 1, 1, 0) != 0) { | 6890 | if (lua_pcall(L, 1, 2, 0) != 0) { |
6891 | std::string err = lua_tostring(L, -1); | 6891 | std::string err = lua_tostring(L, -1); |
6892 | throw std::logic_error(_info.errorMessage("failed to resolve module path\n"s + err, x)); | 6892 | throw std::logic_error(_info.errorMessage("failed to resolve module path\n"s + err, x)); |
6893 | } | 6893 | } |
6894 | if (lua_isnil(L, -1) != 0) { | 6894 | if (lua_isnil(L, -2) != 0) { |
6895 | throw std::logic_error(_info.errorMessage("failed to find module '"s + moduleName + '\'', x)); | 6895 | str_list files; |
6896 | if (lua_istable(L, -1) != 0) { | ||
6897 | int size = static_cast<int>(lua_objlen(L, -1)); | ||
6898 | for (int i = 0; i < size; i++) { | ||
6899 | lua_rawgeti(L, -1, i + 1); | ||
6900 | files.push_back("no file \""s + lua_tostring(L, -1) + "\""s); | ||
6901 | lua_pop(L, 1); | ||
6902 | } | ||
6903 | } | ||
6904 | throw std::logic_error(_info.errorMessage("module '"s + moduleName + "\' not found:\n\t"s + join(files, "\n\t"sv), x)); | ||
6896 | } | 6905 | } |
6906 | lua_pop(L, 1); | ||
6897 | std::string moduleFullName = lua_tostring(L, -1); | 6907 | std::string moduleFullName = lua_tostring(L, -1); |
6898 | lua_pop(L, 1); // cur | 6908 | lua_pop(L, 1); // cur |
6899 | if (!isModuleLoaded(moduleFullName)) { | 6909 | if (!isModuleLoaded(moduleFullName)) { |