aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2023-03-23 16:40:02 +0800
committerLi Jin <dragon-fly@qq.com>2023-03-23 16:40:02 +0800
commitb3d021e2bbb08d01961d2a597715faff5e78b715 (patch)
treef8937553f9d39e9e5db76fb0b376f92c12e1f7fa
parent694068b6dc92269b0221d671bf15b5965ccddff7 (diff)
downloadyuescript-0.15.29.tar.gz
yuescript-0.15.29.tar.bz2
yuescript-0.15.29.zip
fixing build.v0.15.29
-rw-r--r--src/yuescript/yuescript.cpp23
-rw-r--r--src/yuescript/yuescript.h13
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) {
62 return 1; 62 return 1;
63} 63}
64 64
65static yue::YueConfig get_config(lua_State* L) { 65static void get_config(lua_State* L, yue::YueConfig& config) {
66 yue::YueConfig config;
67 lua_pushliteral(L, "lint_global"); 66 lua_pushliteral(L, "lint_global");
68 lua_gettable(L, -2); 67 lua_gettable(L, -2);
69 if (lua_isboolean(L, -1) != 0) { 68 if (lua_isboolean(L, -1) != 0) {
@@ -100,17 +99,18 @@ static yue::YueConfig get_config(lua_State* L) {
100 config.options["target"] = lua_tostring(L, -1); 99 config.options["target"] = lua_tostring(L, -1);
101 } 100 }
102 lua_pop(L, 1); 101 lua_pop(L, 1);
103 return config;
104} 102}
105 103
106static int yuetolua(lua_State* L) { 104static int yuetolua(lua_State* L) {
107 size_t len = 0; 105 size_t len = 0;
108 std::string codes(luaL_checklstring(L, 1, &len), len); 106 auto input = luaL_checklstring(L, 1, &len);
107 std::string_view codes(input, len);
109 yue::YueConfig config; 108 yue::YueConfig config;
110 bool sameModule = false; 109 bool sameModule = false;
111 if (lua_gettop(L) == 2) { 110 if (lua_gettop(L) >= 2) {
112 luaL_checktype(L, 2, LUA_TTABLE); 111 luaL_checktype(L, 2, LUA_TTABLE);
113 config = get_config(L); 112 lua_pushvalue(L, 2);
113 get_config(L, config);
114 lua_pushliteral(L, "same_module"); 114 lua_pushliteral(L, "same_module");
115 lua_gettable(L, -2); 115 lua_gettable(L, -2);
116 if (lua_isboolean(L, -1) != 0) { 116 if (lua_isboolean(L, -1) != 0) {
@@ -128,7 +128,7 @@ static int yuetolua(lua_State* L) {
128 if (lua_isstring(L, -1) != 0) { 128 if (lua_isstring(L, -1) != 0) {
129 config.module = lua_tostring(L, -1); 129 config.module = lua_tostring(L, -1);
130 } 130 }
131 lua_pop(L, 1); 131 lua_pop(L, 2);
132 } 132 }
133 auto result = yue::YueCompiler(L, nullptr, sameModule).compile(codes, config); 133 auto result = yue::YueCompiler(L, nullptr, sameModule).compile(codes, config);
134 if (result.error) { 134 if (result.error) {
@@ -164,12 +164,15 @@ static int yuetolua(lua_State* L) {
164 164
165static int yuecheck(lua_State* L) { 165static int yuecheck(lua_State* L) {
166 size_t len = 0; 166 size_t len = 0;
167 std::string codes{luaL_checklstring(L, 1, &len), len}; 167 auto input = luaL_checklstring(L, 1, &len);
168 std::string_view codes(input, len);
168 yue::YueConfig config; 169 yue::YueConfig config;
169 config.lintGlobalVariable = true; 170 config.lintGlobalVariable = true;
170 if (lua_gettop(L) == 2) { 171 if (lua_gettop(L) >= 2) {
171 luaL_checktype(L, 2, LUA_TTABLE); 172 luaL_checktype(L, 2, LUA_TTABLE);
172 config = get_config(L); 173 lua_pushvalue(L, 2);
174 get_config(L, config);
175 lua_pop(L, 1);
173 } 176 }
174 auto result = yue::YueCompiler(L).compile(codes, config); 177 auto result = yue::YueCompiler(L).compile(codes, config);
175 lua_createtable(L, 0, 0); 178 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)
104 return concat(tried, "\n\t") 104 return concat(tried, "\n\t")
105end 105end
106local function yue_call(f, ...) 106local function yue_call(f, ...)
107 local args = { 107 return xpcall(f, function(err)
108 ...
109 }
110 return xpcall((function()
111 return f(unpack(args))
112 end), function(err)
113 return yue.traceback(err, 1) 108 return yue.traceback(err, 1)
114 end) 109 end, ...)
115end 110end
116yue_loadstring = function(...) 111yue_loadstring = function(...)
117 local options, str, chunk_name, mode, env = get_options(...) 112 local options, str, chunk_name, mode, env = get_options(...)
@@ -166,9 +161,7 @@ local function yue_traceback(err, level)
166end 161end
167local function yue_require(name) 162local function yue_require(name)
168 insert_loader() 163 insert_loader()
169 local success, res = xpcall(function() 164 local success, res = xpcall(require, function(err)
170 return require(name)
171 end, function(err)
172 return yue_traceback(err, 2) 165 return yue_traceback(err, 2)
173 end) 166 end)
174 if success then 167 if success then