diff options
author | Li Jin <dragon-fly@qq.com> | 2025-01-31 23:17:45 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2025-01-31 23:19:02 +0800 |
commit | d1878f2b8eb1644205c5e0b641fd092e8b222766 (patch) | |
tree | 17f1108e35d845364f928e8f9c2178c7d2d0d902 | |
parent | 8124020b3827a8f86970ef8f1efb164e5e110755 (diff) | |
download | yuescript-d1878f2b8eb1644205c5e0b641fd092e8b222766.tar.gz yuescript-d1878f2b8eb1644205c5e0b641fd092e8b222766.tar.bz2 yuescript-d1878f2b8eb1644205c5e0b641fd092e8b222766.zip |
Aligned Lua inserter macro behavior with common Yue macro.v0.27.0
-rw-r--r-- | CMakeLists.txt | 30 | ||||
-rwxr-xr-x | doc/docs/doc/README.md | 12 | ||||
-rwxr-xr-x | doc/docs/zh/doc/README.md | 8 | ||||
-rw-r--r-- | spec/outputs/ambiguous.lua | 4 | ||||
-rw-r--r-- | spec/outputs/codes_from_doc.lua | 18 | ||||
-rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 14 | ||||
-rw-r--r-- | spec/outputs/macro.lua | 18 | ||||
-rw-r--r-- | spec/outputs/unicode/ambiguous.lua | 4 | ||||
-rw-r--r-- | spec/outputs/unicode/macro.lua | 14 | ||||
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 14 |
10 files changed, 74 insertions, 62 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9149ec5..613019e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -1,36 +1,6 @@ | |||
1 | cmake_minimum_required(VERSION 3.10) | 1 | cmake_minimum_required(VERSION 3.10) |
2 | project(yue CXX) | 2 | project(yue CXX) |
3 | 3 | ||
4 | include(FetchContent) | ||
5 | |||
6 | execute_process( | ||
7 | COMMAND ${LUA} -v | ||
8 | OUTPUT_VARIABLE LUA_VERSION_OUTPUT | ||
9 | ERROR_VARIABLE LUA_VERSION_OUTPUT | ||
10 | OUTPUT_STRIP_TRAILING_WHITESPACE | ||
11 | ) | ||
12 | |||
13 | string(REGEX MATCH "Lua ([0-9]+)\\.([0-9]+)\\.([0-9]+)" LUA_VERSION_MATCH ${LUA_VERSION_OUTPUT}) | ||
14 | set(LUA_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}") | ||
15 | |||
16 | set(LUA_TARBALL_URL "https://www.lua.org/ftp/lua-${LUA_VERSION}.tar.gz") | ||
17 | |||
18 | message(STATUS "Detected Lua version: ${LUA_VERSION}") | ||
19 | message(STATUS "Downloading Lua source from: ${LUA_TARBALL_URL}") | ||
20 | |||
21 | FetchContent_Declare( | ||
22 | lua_source | ||
23 | URL ${LUA_TARBALL_URL} | ||
24 | ) | ||
25 | |||
26 | FetchContent_MakeAvailable(lua_source) | ||
27 | |||
28 | set(LUA_SOURCE_DIR "${lua_source_SOURCE_DIR}") | ||
29 | |||
30 | include_directories(${LUA_SOURCE_DIR}/src) | ||
31 | |||
32 | message(STATUS "Lua source directory: ${LUA_SOURCE_DIR}/src") | ||
33 | |||
34 | set(LUA_LIBDIR ${LUA_INCDIR}/../lib ${LUA_INCDIR}/../../lib) | 4 | set(LUA_LIBDIR ${LUA_INCDIR}/../lib ${LUA_INCDIR}/../../lib) |
35 | set(LUA_INCLUDE_DIR "${LUA_INCDIR}") | 5 | set(LUA_INCLUDE_DIR "${LUA_INCDIR}") |
36 | 6 | ||
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 4eec2d5..89bd643 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md | |||
@@ -282,16 +282,14 @@ A macro function can either return a YueScript string or a config table containi | |||
282 | ```moonscript | 282 | ```moonscript |
283 | macro yueFunc = (var) -> "local #{var} = ->" | 283 | macro yueFunc = (var) -> "local #{var} = ->" |
284 | $yueFunc funcA | 284 | $yueFunc funcA |
285 | funcA = -> "fail to assign to the Yue defined variable" | 285 | funcA = -> "fail to assign to the Yue macro defined variable" |
286 | 286 | ||
287 | -- YueScript knows the | ||
288 | -- local variables you declared in Lua code | ||
289 | macro luaFunc = (var) -> { | 287 | macro luaFunc = (var) -> { |
290 | code: "local function #{var}() end" | 288 | code: "local function #{var}() end" |
291 | type: "lua" | 289 | type: "lua" |
292 | } | 290 | } |
293 | $luaFunc funcB | 291 | $luaFunc funcB |
294 | funcB = -> "assign to the Lua defined variable" | 292 | funcB = -> "fail to assign to the Lua macro defined variable" |
295 | 293 | ||
296 | macro lua = (code) -> { | 294 | macro lua = (code) -> { |
297 | :code | 295 | :code |
@@ -310,16 +308,14 @@ end | |||
310 | <pre> | 308 | <pre> |
311 | macro yueFunc = (var) -> "local #{var} = ->" | 309 | macro yueFunc = (var) -> "local #{var} = ->" |
312 | $yueFunc funcA | 310 | $yueFunc funcA |
313 | funcA = -> "fail to assign to the Yue defined variable" | 311 | funcA = -> "fail to assign to the Yue macro defined variable" |
314 | 312 | ||
315 | -- YueScript knows the | ||
316 | -- local variables you declared in Lua codes | ||
317 | macro luaFunc = (var) -> { | 313 | macro luaFunc = (var) -> { |
318 | code: "local function #{var}() end" | 314 | code: "local function #{var}() end" |
319 | type: "lua" | 315 | type: "lua" |
320 | } | 316 | } |
321 | $luaFunc funcB | 317 | $luaFunc funcB |
322 | funcB = -> "assign to the Lua defined variable" | 318 | funcB = -> "fail to assign to the Lua macro defined variable" |
323 | 319 | ||
324 | macro lua = (code) -> { | 320 | macro lua = (code) -> { |
325 | :code | 321 | :code |
diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md index c3a5b76..1a2da96 100755 --- a/doc/docs/zh/doc/README.md +++ b/doc/docs/zh/doc/README.md | |||
@@ -277,19 +277,18 @@ if $and f1!, f2!, f3! | |||
277 | 277 | ||
278 | ### 直接插入代码 | 278 | ### 直接插入代码 |
279 | 279 | ||
280 | 宏函数可以返回一个包含月之脚本代码的字符串,或是一个包含Lua代码字符串的配置表。 | 280 | 宏函数可以返回一个包含月之脚本代码的字符串,或是一个包含 Lua 代码字符串的配置表。 |
281 | ```moonscript | 281 | ```moonscript |
282 | macro yueFunc = (var) -> "local #{var} = ->" | 282 | macro yueFunc = (var) -> "local #{var} = ->" |
283 | $yueFunc funcA | 283 | $yueFunc funcA |
284 | funcA = -> "无法访问宏生成月之脚本里定义的变量" | 284 | funcA = -> "无法访问宏生成月之脚本里定义的变量" |
285 | 285 | ||
286 | -- 月之脚本会知道你在 Lua 代码中声明的局部变量 | ||
287 | macro luaFunc = (var) -> { | 286 | macro luaFunc = (var) -> { |
288 | code: "local function #{var}() end" | 287 | code: "local function #{var}() end" |
289 | type: "lua" | 288 | type: "lua" |
290 | } | 289 | } |
291 | $luaFunc funcB | 290 | $luaFunc funcB |
292 | funcB = -> "访问宏生成Lua代码里定义的变量" | 291 | funcB = -> "无法访问宏生成 Lua 代码里定义的变量" |
293 | 292 | ||
294 | macro lua = (code) -> { | 293 | macro lua = (code) -> { |
295 | :code | 294 | :code |
@@ -310,13 +309,12 @@ macro yueFunc = (var) -> "local #{var} = ->" | |||
310 | $yueFunc funcA | 309 | $yueFunc funcA |
311 | funcA = -> "无法访问宏生成月之脚本里定义的变量" | 310 | funcA = -> "无法访问宏生成月之脚本里定义的变量" |
312 | 311 | ||
313 | -- 月之脚本会知道你在 Lua 代码中声明的局部变量 | ||
314 | macro luaFunc = (var) -> { | 312 | macro luaFunc = (var) -> { |
315 | code: "local function #{var}() end" | 313 | code: "local function #{var}() end" |
316 | type: "lua" | 314 | type: "lua" |
317 | } | 315 | } |
318 | $luaFunc funcB | 316 | $luaFunc funcB |
319 | funcB = -> "访问宏生成Lua代码里定义的变量" | 317 | funcB = -> "无法访问宏生成 Lua 代码里定义的变量" |
320 | 318 | ||
321 | macro lua = (code) -> { | 319 | macro lua = (code) -> { |
322 | :code | 320 | :code |
diff --git a/spec/outputs/ambiguous.lua b/spec/outputs/ambiguous.lua index 3c82a03..fc43d63 100644 --- a/spec/outputs/ambiguous.lua +++ b/spec/outputs/ambiguous.lua | |||
@@ -39,9 +39,11 @@ end | |||
39 | do | 39 | do |
40 | print() | 40 | print() |
41 | async_fn(function() | 41 | async_fn(function() |
42 | print(); | 42 | print() |
43 | do | ||
43 | --[[a comment to insert]] | 44 | --[[a comment to insert]] |
44 | (haha)() | 45 | (haha)() |
46 | end | ||
45 | return nil | 47 | return nil |
46 | end) | 48 | end) |
47 | end | 49 | end |
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index 5c262d3..74db469 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua | |||
@@ -59,16 +59,21 @@ do | |||
59 | end | 59 | end |
60 | local funcA | 60 | local funcA |
61 | funcA = function() | 61 | funcA = function() |
62 | return "fail to assign to the Yue defined variable" | 62 | return "fail to assign to the Yue macro defined variable" |
63 | end | 63 | end |
64 | do | ||
64 | local function funcB() end | 65 | local function funcB() end |
66 | end | ||
67 | local funcB | ||
65 | funcB = function() | 68 | funcB = function() |
66 | return "assign to the Lua defined variable" | 69 | return "fail to assign to the Lua macro defined variable" |
67 | end | 70 | end |
71 | do | ||
68 | -- raw Lua codes insertion | 72 | -- raw Lua codes insertion |
69 | if cond then | 73 | if cond then |
70 | print("output") | 74 | print("output") |
71 | end | 75 | end |
76 | end | ||
72 | print("yuescript") | 77 | print("yuescript") |
73 | print(3) | 78 | print(3) |
74 | print("Valid enum type:", "Static") | 79 | print("Valid enum type:", "Static") |
@@ -2065,16 +2070,21 @@ do | |||
2065 | end | 2070 | end |
2066 | local funcA | 2071 | local funcA |
2067 | funcA = function() | 2072 | funcA = function() |
2068 | return "fail to assign to the Yue defined variable" | 2073 | return "fail to assign to the Yue macro defined variable" |
2069 | end | 2074 | end |
2075 | do | ||
2070 | local function funcB() end | 2076 | local function funcB() end |
2077 | end | ||
2078 | local funcB | ||
2071 | funcB = function() | 2079 | funcB = function() |
2072 | return "assign to the Lua defined variable" | 2080 | return "fail to assign to the Lua macro defined variable" |
2073 | end | 2081 | end |
2082 | do | ||
2074 | -- raw Lua codes insertion | 2083 | -- raw Lua codes insertion |
2075 | if cond then | 2084 | if cond then |
2076 | print("output") | 2085 | print("output") |
2077 | end | 2086 | end |
2087 | end | ||
2078 | print("yuescript") | 2088 | print("yuescript") |
2079 | print(3) | 2089 | print(3) |
2080 | print("Valid enum type:", "Static") | 2090 | print("Valid enum type:", "Static") |
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index c6d5388..1a10555 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
@@ -61,14 +61,19 @@ local funcA | |||
61 | funcA = function() | 61 | funcA = function() |
62 | return "无法访问宏生成月之脚本里定义的变量" | 62 | return "无法访问宏生成月之脚本里定义的变量" |
63 | end | 63 | end |
64 | do | ||
64 | local function funcB() end | 65 | local function funcB() end |
66 | end | ||
67 | local funcB | ||
65 | funcB = function() | 68 | funcB = function() |
66 | return "访问宏生成Lua代码里定义的变量" | 69 | return "无法访问宏生成 Lua 代码里定义的变量" |
67 | end | 70 | end |
71 | do | ||
68 | -- 插入原始Lua代码 | 72 | -- 插入原始Lua代码 |
69 | if cond then | 73 | if cond then |
70 | print("输出") | 74 | print("输出") |
71 | end | 75 | end |
76 | end | ||
72 | print("yuescript") | 77 | print("yuescript") |
73 | print(3) | 78 | print(3) |
74 | print("有效的枚举类型:", "Static") | 79 | print("有效的枚举类型:", "Static") |
@@ -2061,14 +2066,19 @@ local funcA | |||
2061 | funcA = function() | 2066 | funcA = function() |
2062 | return "无法访问宏生成月之脚本里定义的变量" | 2067 | return "无法访问宏生成月之脚本里定义的变量" |
2063 | end | 2068 | end |
2069 | do | ||
2064 | local function funcB() end | 2070 | local function funcB() end |
2071 | end | ||
2072 | local funcB | ||
2065 | funcB = function() | 2073 | funcB = function() |
2066 | return "访问宏生成Lua代码里定义的变量" | 2074 | return "无法访问宏生成 Lua 代码里定义的变量" |
2067 | end | 2075 | end |
2076 | do | ||
2068 | -- 插入原始Lua代码 | 2077 | -- 插入原始Lua代码 |
2069 | if cond then | 2078 | if cond then |
2070 | print("输出") | 2079 | print("输出") |
2071 | end | 2080 | end |
2081 | end | ||
2072 | print("yuescript") | 2082 | print("yuescript") |
2073 | print(3) | 2083 | print(3) |
2074 | print("有效的枚举类型:", "Static") | 2084 | print("有效的枚举类型:", "Static") |
diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua index 7163077..aa74ed9 100644 --- a/spec/outputs/macro.lua +++ b/spec/outputs/macro.lua | |||
@@ -5,7 +5,9 @@ do | |||
5 | end | 5 | end |
6 | print(456) | 6 | print(456) |
7 | do | 7 | do |
8 | do | ||
8 | -- TODO: "todo in a do block" | 9 | -- TODO: "todo in a do block" |
10 | end | ||
9 | end | 11 | end |
10 | end | 12 | end |
11 | do | 13 | do |
@@ -201,13 +203,17 @@ do | |||
201 | print(a) | 203 | print(a) |
202 | end | 204 | end |
203 | local x = 0 | 205 | local x = 0 |
206 | do | ||
204 | local function f(a) | 207 | local function f(a) |
205 | return a + 1 | 208 | return a + 1 |
206 | end | 209 | end |
207 | x = x + f(3) | 210 | x = x + f(3) |
211 | end | ||
212 | do | ||
208 | function tb:func() | 213 | function tb:func() |
209 | print(123) | 214 | print(123) |
210 | end | 215 | end |
216 | end | ||
211 | print(x) | 217 | print(x) |
212 | local sel | 218 | local sel |
213 | sel = function(a, b, c) | 219 | sel = function(a, b, c) |
@@ -217,6 +223,7 @@ sel = function(a, b, c) | |||
217 | return c | 223 | return c |
218 | end | 224 | end |
219 | end | 225 | end |
226 | do | ||
220 | local function sel(a, b, c) | 227 | local function sel(a, b, c) |
221 | if a then | 228 | if a then |
222 | return b | 229 | return b |
@@ -224,10 +231,15 @@ local function sel(a, b, c) | |||
224 | return c | 231 | return c |
225 | end | 232 | end |
226 | end | 233 | end |
234 | end | ||
235 | do | ||
227 | local function dummy() | 236 | local function dummy() |
228 | 237 | ||
229 | end | 238 | end |
239 | end | ||
240 | do | ||
230 | -- a comment here | 241 | -- a comment here |
242 | end | ||
231 | local _ = require('underscore') | 243 | local _ = require('underscore') |
232 | local a = ((((_({ | 244 | local a = ((((_({ |
233 | 1, | 245 | 1, |
@@ -279,9 +291,11 @@ do | |||
279 | _6:Destroy() | 291 | _6:Destroy() |
280 | end | 292 | end |
281 | end | 293 | end |
294 | do | ||
282 | origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) | 295 | origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) |
283 | return x.name:EndsWith("(Clone)") | 296 | return x.name:EndsWith("(Clone)") |
284 | end):Destroy() | 297 | end):Destroy() |
298 | end | ||
285 | print((setmetatable({ | 299 | print((setmetatable({ |
286 | 'abc', | 300 | 'abc', |
287 | a = 123, | 301 | a = 123, |
@@ -313,7 +327,9 @@ print((setmetatable({ | |||
313 | })) | 327 | })) |
314 | print("current line: " .. tostring(323)) | 328 | print("current line: " .. tostring(323)) |
315 | do | 329 | do |
330 | do | ||
316 | -- TODO | 331 | -- TODO |
332 | end | ||
317 | end | 333 | end |
318 | do | 334 | do |
319 | print(1) | 335 | print(1) |
@@ -336,7 +352,9 @@ do | |||
336 | end | 352 | end |
337 | local f1 | 353 | local f1 |
338 | f1 = function() | 354 | f1 = function() |
355 | do | ||
339 | tb:func(123) | 356 | tb:func(123) |
357 | end | ||
340 | return | 358 | return |
341 | end | 359 | end |
342 | end | 360 | end |
diff --git a/spec/outputs/unicode/ambiguous.lua b/spec/outputs/unicode/ambiguous.lua index ac90016..704b311 100644 --- a/spec/outputs/unicode/ambiguous.lua +++ b/spec/outputs/unicode/ambiguous.lua | |||
@@ -39,9 +39,11 @@ end | |||
39 | do | 39 | do |
40 | _u6253_u5370() | 40 | _u6253_u5370() |
41 | _u5f02_u6b65_u51fd_u6570(function() | 41 | _u5f02_u6b65_u51fd_u6570(function() |
42 | _u6253_u5370(); | 42 | _u6253_u5370() |
43 | do | ||
43 | --[[a comment to insert]] | 44 | --[[a comment to insert]] |
44 | (haha)() | 45 | (haha)() |
46 | end | ||
45 | return nil | 47 | return nil |
46 | end) | 48 | end) |
47 | end | 49 | end |
diff --git a/spec/outputs/unicode/macro.lua b/spec/outputs/unicode/macro.lua index 069f429..e2195e4 100644 --- a/spec/outputs/unicode/macro.lua +++ b/spec/outputs/unicode/macro.lua | |||
@@ -179,13 +179,17 @@ do | |||
179 | _u6253_u5370(_u53d8_u91cfa) | 179 | _u6253_u5370(_u53d8_u91cfa) |
180 | end | 180 | end |
181 | local _u53d8_u91cfx = 0 | 181 | local _u53d8_u91cfx = 0 |
182 | do | ||
182 | local function f(a) | 183 | local function f(a) |
183 | return a + 1 | 184 | return a + 1 |
184 | end | 185 | end |
185 | x = x + f(3) | 186 | x = x + f(3) |
187 | end | ||
188 | do | ||
186 | function tb:func() | 189 | function tb:func() |
187 | print(123) | 190 | print(123) |
188 | end | 191 | end |
192 | end | ||
189 | _u6253_u5370(_u53d8_u91cfx) | 193 | _u6253_u5370(_u53d8_u91cfx) |
190 | local sel | 194 | local sel |
191 | sel = function(_u53c2_u6570a, _u53c2_u6570b, _u53c2_u6570c) | 195 | sel = function(_u53c2_u6570a, _u53c2_u6570b, _u53c2_u6570c) |
@@ -195,6 +199,7 @@ sel = function(_u53c2_u6570a, _u53c2_u6570b, _u53c2_u6570c) | |||
195 | return _u53c2_u6570c | 199 | return _u53c2_u6570c |
196 | end | 200 | end |
197 | end | 201 | end |
202 | do | ||
198 | local function sel(a, b, c) | 203 | local function sel(a, b, c) |
199 | if a then | 204 | if a then |
200 | return b | 205 | return b |
@@ -202,10 +207,15 @@ local function sel(a, b, c) | |||
202 | return c | 207 | return c |
203 | end | 208 | end |
204 | end | 209 | end |
210 | end | ||
211 | do | ||
205 | local function dummy() | 212 | local function dummy() |
206 | 213 | ||
207 | end | 214 | end |
215 | end | ||
216 | do | ||
208 | -- 这有个注释 | 217 | -- 这有个注释 |
218 | end | ||
209 | local _ = require('下划线') | 219 | local _ = require('下划线') |
210 | local _call_0 = (_({ | 220 | local _call_0 = (_({ |
211 | 1, | 221 | 1, |
@@ -275,11 +285,13 @@ do | |||
275 | _6["摧毁"](_6) | 285 | _6["摧毁"](_6) |
276 | end | 286 | end |
277 | end | 287 | end |
288 | do | ||
278 | local _call_0 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] | 289 | local _call_0 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] |
279 | _call_0["父节点"](_call_0):_u540e_u4ee3():_u9009_u62e9_u542f_u7528():_u9009_u62e9_u53ef_u89c1():_u6807_u7b7e_u7b49_u4e8e("fx"):_u5176_u4e2d(function(x) | 290 | _call_0["父节点"](_call_0):_u540e_u4ee3():_u9009_u62e9_u542f_u7528():_u9009_u62e9_u53ef_u89c1():_u6807_u7b7e_u7b49_u4e8e("fx"):_u5176_u4e2d(function(x) |
280 | local _call_0 = x["名称"] | 291 | local _call_0 = x["名称"] |
281 | return _call_0["结尾为"](_call_0, "(克隆)") | 292 | return _call_0["结尾为"](_call_0, "(克隆)") |
282 | end):_u6467_u6bc1() | 293 | end):_u6467_u6bc1() |
294 | end | ||
283 | _u6253_u5370((setmetatable({ | 295 | _u6253_u5370((setmetatable({ |
284 | 'abc', | 296 | 'abc', |
285 | ["字段a"] = 123, | 297 | ["字段a"] = 123, |
@@ -311,7 +323,9 @@ _u6253_u5370((setmetatable({ | |||
311 | })) | 323 | })) |
312 | _u6253_u5370("当前代码行数: " .. tostring(268)) | 324 | _u6253_u5370("当前代码行数: " .. tostring(268)) |
313 | do | 325 | do |
326 | do | ||
314 | -- 待实现 | 327 | -- 待实现 |
328 | end | ||
315 | end | 329 | end |
316 | do | 330 | do |
317 | _u6253_u5370(1) | 331 | _u6253_u5370(1) |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 446414d..e7fe0c0 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -24,7 +24,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI | |||
24 | 24 | ||
25 | extern "C" { | 25 | extern "C" { |
26 | #include "lauxlib.h" | 26 | #include "lauxlib.h" |
27 | #include "lparser.h" | ||
28 | #include "lua.h" | 27 | #include "lua.h" |
29 | #include "lualib.h" | 28 | #include "lualib.h" |
30 | } // extern "C" | 29 | } // extern "C" |
@@ -76,7 +75,7 @@ static std::unordered_set<std::string> Metamethods = { | |||
76 | "close"s // Lua 5.4 | 75 | "close"s // Lua 5.4 |
77 | }; | 76 | }; |
78 | 77 | ||
79 | const std::string_view version = "0.26.3"sv; | 78 | const std::string_view version = "0.27.0"sv; |
80 | const std::string_view extension = "yue"sv; | 79 | const std::string_view extension = "yue"sv; |
81 | 80 | ||
82 | class CompileError : public std::logic_error { | 81 | class CompileError : public std::logic_error { |
@@ -6567,17 +6566,10 @@ private: | |||
6567 | if (luaL_loadbuffer(L, codes.c_str(), codes.size(), macroChunk.c_str()) != 0) { | 6566 | if (luaL_loadbuffer(L, codes.c_str(), codes.size(), macroChunk.c_str()) != 0) { |
6568 | std::string err = lua_tostring(L, -1); | 6567 | std::string err = lua_tostring(L, -1); |
6569 | throw CompileError("lua macro is not expanding to valid block\n"s + err, x); | 6568 | throw CompileError("lua macro is not expanding to valid block\n"s + err, x); |
6570 | } else { | ||
6571 | Proto* f = ((LClosure*)lua_topointer(L, -1))->p; | ||
6572 | for (int i = 0; i < f->sizelocvars; i++) { | ||
6573 | localVars.push_back(getstr(f->locvars[i].varname)); | ||
6574 | } | ||
6575 | } | 6569 | } |
6576 | if (!codes.empty()) { | 6570 | if (!codes.empty()) { |
6577 | if (_config.reserveLineNumber) { | 6571 | codes.insert(0, indent() + "do"s + nll(chainValue)); |
6578 | codes.insert(0, nll(chainValue).substr(1)); | 6572 | codes.append(_newLine + indent() + "end"s + nlr(chainValue)); |
6579 | } | ||
6580 | codes.append(nlr(chainValue)); | ||
6581 | } | 6573 | } |
6582 | return {nullptr, nullptr, std::move(codes), std::move(localVars)}; | 6574 | return {nullptr, nullptr, std::move(codes), std::move(localVars)}; |
6583 | } else { | 6575 | } else { |