From b3d021e2bbb08d01961d2a597715faff5e78b715 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 23 Mar 2023 16:40:02 +0800 Subject: fixing build. --- src/yuescript/yuescript.cpp | 23 +++++++++++++---------- src/yuescript/yuescript.h | 13 +++---------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/yuescript/yuescript.cpp b/src/yuescript/yuescript.cpp index ef427ad..c8a7d42 100644 --- a/src/yuescript/yuescript.cpp +++ b/src/yuescript/yuescript.cpp @@ -62,8 +62,7 @@ static int init_stacktraceplus(lua_State* L) { return 1; } -static yue::YueConfig get_config(lua_State* L) { - yue::YueConfig config; +static void get_config(lua_State* L, yue::YueConfig& config) { lua_pushliteral(L, "lint_global"); lua_gettable(L, -2); if (lua_isboolean(L, -1) != 0) { @@ -100,17 +99,18 @@ static yue::YueConfig get_config(lua_State* L) { config.options["target"] = lua_tostring(L, -1); } lua_pop(L, 1); - return config; } static int yuetolua(lua_State* L) { size_t len = 0; - std::string codes(luaL_checklstring(L, 1, &len), len); + auto input = luaL_checklstring(L, 1, &len); + std::string_view codes(input, len); yue::YueConfig config; bool sameModule = false; - if (lua_gettop(L) == 2) { + if (lua_gettop(L) >= 2) { luaL_checktype(L, 2, LUA_TTABLE); - config = get_config(L); + lua_pushvalue(L, 2); + get_config(L, config); lua_pushliteral(L, "same_module"); lua_gettable(L, -2); if (lua_isboolean(L, -1) != 0) { @@ -128,7 +128,7 @@ static int yuetolua(lua_State* L) { if (lua_isstring(L, -1) != 0) { config.module = lua_tostring(L, -1); } - lua_pop(L, 1); + lua_pop(L, 2); } auto result = yue::YueCompiler(L, nullptr, sameModule).compile(codes, config); if (result.error) { @@ -164,12 +164,15 @@ static int yuetolua(lua_State* L) { static int yuecheck(lua_State* L) { size_t len = 0; - std::string codes{luaL_checklstring(L, 1, &len), len}; + auto input = luaL_checklstring(L, 1, &len); + std::string_view codes(input, len); yue::YueConfig config; config.lintGlobalVariable = true; - if (lua_gettop(L) == 2) { + if (lua_gettop(L) >= 2) { luaL_checktype(L, 2, LUA_TTABLE); - config = get_config(L); + lua_pushvalue(L, 2); + get_config(L, config); + lua_pop(L, 1); } auto result = yue::YueCompiler(L).compile(codes, config); lua_createtable(L, 0, 0); diff --git a/src/yuescript/yuescript.h b/src/yuescript/yuescript.h index 51622f8..b007797 100644 --- a/src/yuescript/yuescript.h +++ b/src/yuescript/yuescript.h @@ -104,14 +104,9 @@ local function yue_loader(name) return concat(tried, "\n\t") end local function yue_call(f, ...) - local args = { - ... - } - return xpcall((function() - return f(unpack(args)) - end), function(err) + return xpcall(f, function(err) return yue.traceback(err, 1) - end) + end, ...) end yue_loadstring = function(...) local options, str, chunk_name, mode, env = get_options(...) @@ -166,9 +161,7 @@ local function yue_traceback(err, level) end local function yue_require(name) insert_loader() - local success, res = xpcall(function() - return require(name) - end, function(err) + local success, res = xpcall(require, function(err) return yue_traceback(err, 2) end) if success then -- cgit v1.2.3-55-g6feb