From 9eb846a1e1e11f7ce2f6b89120b2835af470daa6 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 3 Mar 2022 15:32:24 +0800 Subject: fix loader order. fix script not found error message. --- src/yuescript/yue_compiler.cpp | 2 +- src/yuescript/yuescript.h | 36 ++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) (limited to 'src') 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; typedef std::list str_list; -const std::string_view version = "0.10.3"sv; +const std::string_view version = "0.10.4"sv; const std::string_view extension = "yue"sv; class 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) local dirsep = yue.options.dirsep local name_path = name:match("[\\/]") and name or name:gsub("%.", dirsep) local file_exist, file_path + local tried = {} for path in package.path:gmatch("[^;]+") do file_path = path:gsub("?", name_path):gsub("%.lua$", suffix) file_exist = yue.file_exist(file_path) if file_exist then break + else + tried[#tried + 1] = file_path end end if file_exist then return file_path else - return nil - end -end -local function load_text(name) - local file_path = find_modulepath(name) - if file_path then - return yue.read_file(file_path), file_path + return nil, tried end - return nil, nil end local yue_loadstring local function yue_loader(name) - local text, file_path = load_text(name) - if text then - local res, err = yue_loadstring(text, file_path) - if not res then - error(file_path .. ": " .. err) + local file_path, tried = yue.find_modulepath(name) + if file_path then + local text = yue.read_file(file_path) + if text then + local res, err = yue_loadstring(text, file_path) + if not res then + error(file_path .. ": " .. err) + end + return res + else + return "no file '" .. file_path .. "'" end - return res end - return nil, "Could not find yue file" + for i = 1, #tried do + tried[i] = "no file '" .. tried[i] .. "'" + end + return concat(tried, "\n\t") end local function yue_call(f, ...) local args = { @@ -126,7 +130,7 @@ local function yue_dofile(...) end local function insert_loader(pos) if pos == nil then - pos = 2 + pos = 3 end local loaders = package.loaders or package.searchers for i = 1, #loaders do -- cgit v1.2.3-55-g6feb