summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-03-03 15:32:24 +0800
committerLi Jin <dragon-fly@qq.com>2022-03-03 15:32:24 +0800
commit9eb846a1e1e11f7ce2f6b89120b2835af470daa6 (patch)
treec3feb8364bb1eddf34555e138f700c6ce482a9b1 /src
parent6c78271c841baf43365cc7924c0ca2da867f9e79 (diff)
downloadyuescript-9eb846a1e1e11f7ce2f6b89120b2835af470daa6.tar.gz
yuescript-9eb846a1e1e11f7ce2f6b89120b2835af470daa6.tar.bz2
yuescript-9eb846a1e1e11f7ce2f6b89120b2835af470daa6.zip
fix loader order. fix script not found error message.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/yuescript/yue_compiler.cpp2
-rw-r--r--src/yuescript/yuescript.h36
2 files changed, 21 insertions, 17 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 274027b..6ae4771 100755
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -60,7 +60,7 @@ using namespace parserlib;
60 60
61typedef std::list<std::string> str_list; 61typedef std::list<std::string> str_list;
62 62
63const std::string_view version = "0.10.3"sv; 63const std::string_view version = "0.10.4"sv;
64const std::string_view extension = "yue"sv; 64const std::string_view extension = "yue"sv;
65 65
66class YueCompilerImpl { 66class YueCompilerImpl {
diff --git a/src/yuescript/yuescript.h b/src/yuescript/yuescript.h
index 769eb8a..1430758 100644
--- a/src/yuescript/yuescript.h
+++ b/src/yuescript/yuescript.h
@@ -58,37 +58,41 @@ local function find_modulepath(name)
58 local dirsep = yue.options.dirsep 58 local dirsep = yue.options.dirsep
59 local name_path = name:match("[\\/]") and name or name:gsub("%.", dirsep) 59 local name_path = name:match("[\\/]") and name or name:gsub("%.", dirsep)
60 local file_exist, file_path 60 local file_exist, file_path
61 local tried = {}
61 for path in package.path:gmatch("[^;]+") do 62 for path in package.path:gmatch("[^;]+") do
62 file_path = path:gsub("?", name_path):gsub("%.lua$", suffix) 63 file_path = path:gsub("?", name_path):gsub("%.lua$", suffix)
63 file_exist = yue.file_exist(file_path) 64 file_exist = yue.file_exist(file_path)
64 if file_exist then 65 if file_exist then
65 break 66 break
67 else
68 tried[#tried + 1] = file_path
66 end 69 end
67 end 70 end
68 if file_exist then 71 if file_exist then
69 return file_path 72 return file_path
70 else 73 else
71 return nil 74 return nil, tried
72 end
73end
74local function load_text(name)
75 local file_path = find_modulepath(name)
76 if file_path then
77 return yue.read_file(file_path), file_path
78 end 75 end
79 return nil, nil
80end 76end
81local yue_loadstring 77local yue_loadstring
82local function yue_loader(name) 78local function yue_loader(name)
83 local text, file_path = load_text(name) 79 local file_path, tried = yue.find_modulepath(name)
84 if text then 80 if file_path then
85 local res, err = yue_loadstring(text, file_path) 81 local text = yue.read_file(file_path)
86 if not res then 82 if text then
87 error(file_path .. ": " .. err) 83 local res, err = yue_loadstring(text, file_path)
84 if not res then
85 error(file_path .. ": " .. err)
86 end
87 return res
88 else
89 return "no file '" .. file_path .. "'"
88 end 90 end
89 return res
90 end 91 end
91 return nil, "Could not find yue file" 92 for i = 1, #tried do
93 tried[i] = "no file '" .. tried[i] .. "'"
94 end
95 return concat(tried, "\n\t")
92end 96end
93local function yue_call(f, ...) 97local function yue_call(f, ...)
94 local args = { 98 local args = {
@@ -126,7 +130,7 @@ local function yue_dofile(...)
126end 130end
127local function insert_loader(pos) 131local function insert_loader(pos)
128 if pos == nil then 132 if pos == nil then
129 pos = 2 133 pos = 3
130 end 134 end
131 local loaders = package.loaders or package.searchers 135 local loaders = package.loaders or package.searchers
132 for i = 1, #loaders do 136 for i = 1, #loaders do