From fced0c4f4101ad7c8d81432a0e8c45d38b72616c Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 15 Jan 2026 17:07:11 +0800 Subject: Added `import global` syntax. --- spec/outputs/codes_from_doc.lua | 142 +++++++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 60 deletions(-) (limited to 'spec/outputs/codes_from_doc.lua') diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index de5abdd..02f36d1 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua @@ -408,6 +408,17 @@ local tb = { } } } +do + local math = math + local print = print + print("hello") + math.random(3) +end +do + local print = print + print(FLAG) + FLAG = 123 +end do local insert, concat = table.insert, table.concat local C, Ct, Cmt @@ -737,36 +748,6 @@ end local first = select(1, ...) return print(ok, count, first) end)(fn(true)) -local f -f = function(...) - local t = { - n = select("#", ...), - ... - } - print("argument count:", t.n) - print("table length:", #t) - for i = 1, t.n do - print(t[i]) - end -end -f(1, 2, 3) -f("a", "b", "c", "d") -f() -local process -process = function(...) - local args = { - n = select("#", ...), - ... - } - local sum = 0 - for i = 1, args.n do - if args[i] ~= nil and type(args[i]) == "number" then - sum = sum + args[i] - end - end - return sum -end -process(1, nil, 3, nil, 5) Rx.Observable.fromRange(1, 8):filter(function(x) return x % 2 == 0 end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) @@ -1000,6 +981,36 @@ local arg1 = { a = 0 } f2(arg1, arg2) +local f +f = function(...) + local t = { + n = select("#", ...), + ... + } + print("argument count:", t.n) + print("table length:", #t) + for i = 1, t.n do + print(t[i]) + end +end +f(1, 2, 3) +f("a", "b", "c", "d") +f() +local process +process = function(...) + local args = { + n = select("#", ...), + ... + } + local sum = 0 + for i = 1, args.n do + if args[i] ~= nil and type(args[i]) == "number" then + sum = sum + args[i] + end + end + return sum +end +process(1, nil, 3, nil, 5) f(function() return print("hello") end) @@ -2916,6 +2927,17 @@ local tb = { } } } +do + local math = math + local print = print + print("hello") + math.random(3) +end +do + local print = print + print(FLAG) + FLAG = 123 +end do local insert, concat = table.insert, table.concat local C, Ct, Cmt @@ -3245,36 +3267,6 @@ end local first = select(1, ...) return print(ok, count, first) end)(fn(true)) -local f -f = function(...) - local t = { - n = select("#", ...), - ... - } - print("argument count:", t.n) - print("table length:", #t) - for i = 1, t.n do - print(t[i]) - end -end -f(1, 2, 3) -f("a", "b", "c", "d") -f() -local process -process = function(...) - local args = { - n = select("#", ...), - ... - } - local sum = 0 - for i = 1, args.n do - if args[i] ~= nil and type(args[i]) == "number" then - sum = sum + args[i] - end - end - return sum -end -process(1, nil, 3, nil, 5) Rx.Observable.fromRange(1, 8):filter(function(x) return x % 2 == 0 end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) @@ -3538,6 +3530,36 @@ findFirstEven = function(list) end return nil end +local f +f = function(...) + local t = { + n = select("#", ...), + ... + } + print("argument count:", t.n) + print("table length:", #t) + for i = 1, t.n do + print(t[i]) + end +end +f(1, 2, 3) +f("a", "b", "c", "d") +f() +local process +process = function(...) + local args = { + n = select("#", ...), + ... + } + local sum = 0 + for i = 1, args.n do + if args[i] ~= nil and type(args[i]) == "number" then + sum = sum + args[i] + end + end + return sum +end +process(1, nil, 3, nil, 5) f(function() return print("hello") end) -- cgit v1.2.3-55-g6feb