diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-15 17:07:11 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-15 17:07:11 +0800 |
| commit | fced0c4f4101ad7c8d81432a0e8c45d38b72616c (patch) | |
| tree | ed673461c7ef3c614cb5d56905c437f6a6b27454 /spec/outputs/import_global.lua | |
| parent | 4177d237e3ed642b2bba5bec13127a44d2b0524d (diff) | |
| download | yuescript-fced0c4f4101ad7c8d81432a0e8c45d38b72616c.tar.gz yuescript-fced0c4f4101ad7c8d81432a0e8c45d38b72616c.tar.bz2 yuescript-fced0c4f4101ad7c8d81432a0e8c45d38b72616c.zip | |
Added `import global` syntax.
Diffstat (limited to 'spec/outputs/import_global.lua')
| -rw-r--r-- | spec/outputs/import_global.lua | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/spec/outputs/import_global.lua b/spec/outputs/import_global.lua new file mode 100644 index 0000000..08a90e2 --- /dev/null +++ b/spec/outputs/import_global.lua | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | do | ||
| 2 | local math = math | ||
| 3 | local print = print | ||
| 4 | print("hello") | ||
| 5 | math.random(10) | ||
| 6 | end | ||
| 7 | do | ||
| 8 | local print = print | ||
| 9 | local value = 1 | ||
| 10 | value = value + 2 | ||
| 11 | print(value) | ||
| 12 | end | ||
| 13 | do | ||
| 14 | local print | ||
| 15 | print = function(msg) | ||
| 16 | return msg | ||
| 17 | end | ||
| 18 | do | ||
| 19 | local math = math | ||
| 20 | print("local") | ||
| 21 | math.random(1) | ||
| 22 | end | ||
| 23 | end | ||
| 24 | do | ||
| 25 | local print = print | ||
| 26 | local tostring | ||
| 27 | tostring = function(v) | ||
| 28 | return "local" | ||
| 29 | end | ||
| 30 | tostring("value") | ||
| 31 | print(tostring(123)) | ||
| 32 | end | ||
| 33 | do | ||
| 34 | local func | ||
| 35 | func = function(x, y) | ||
| 36 | local tostring = tostring | ||
| 37 | local print = print | ||
| 38 | local type = type | ||
| 39 | return type(x, tostring(y, print)) | ||
| 40 | end | ||
| 41 | func(1, 2) | ||
| 42 | end | ||
| 43 | do | ||
| 44 | local print = print | ||
| 45 | local tostring = tostring | ||
| 46 | local func = func | ||
| 47 | local world = world | ||
| 48 | local xpcall = xpcall | ||
| 49 | xpcall(function() | ||
| 50 | return func("hello " .. tostring(world)) | ||
| 51 | end, function(err) | ||
| 52 | return print(err) | ||
| 53 | end) | ||
| 54 | end | ||
| 55 | do | ||
| 56 | local print = print | ||
| 57 | print(FLAG) | ||
| 58 | FLAG = 123 | ||
| 59 | end | ||
| 60 | do | ||
| 61 | local print = print | ||
| 62 | Foo = 10 | ||
| 63 | print(Foo) | ||
| 64 | Foo = Foo + 2 | ||
| 65 | end | ||
| 66 | do | ||
| 67 | local print = print | ||
| 68 | Bar = 1 | ||
| 69 | Baz = 2 | ||
| 70 | print(Bar, Baz) | ||
| 71 | end | ||
| 72 | do | ||
| 73 | local y = y | ||
| 74 | x = 3434 | ||
| 75 | if y then | ||
| 76 | x = 10 | ||
| 77 | end | ||
| 78 | end | ||
| 79 | do | ||
| 80 | local tostring = tostring | ||
| 81 | local Uppercase = Uppercase | ||
| 82 | local lowercase = lowercase | ||
| 83 | local foobar = "all " .. tostring(lowercase) | ||
| 84 | FooBar = "pascal case" | ||
| 85 | FOOBAR = "all " .. tostring(Uppercase) | ||
| 86 | end | ||
| 87 | do | ||
| 88 | local print = print | ||
| 89 | local setmetatable = setmetatable | ||
| 90 | do | ||
| 91 | local _class_0 | ||
| 92 | local _base_0 = { } | ||
| 93 | if _base_0.__index == nil then | ||
| 94 | _base_0.__index = _base_0 | ||
| 95 | end | ||
| 96 | _class_0 = setmetatable({ | ||
| 97 | __init = function() end, | ||
| 98 | __base = _base_0, | ||
| 99 | __name = "A" | ||
| 100 | }, { | ||
| 101 | __index = _base_0, | ||
| 102 | __call = function(cls, ...) | ||
| 103 | local _self_0 = setmetatable({ }, _base_0) | ||
| 104 | cls.__init(_self_0, ...) | ||
| 105 | return _self_0 | ||
| 106 | end | ||
| 107 | }) | ||
| 108 | _base_0.__class = _class_0 | ||
| 109 | A = _class_0 | ||
| 110 | end | ||
| 111 | Flag = 1 | ||
| 112 | const, x, y = "const", 1, 2 | ||
| 113 | print(math, table) | ||
| 114 | end | ||
| 115 | do | ||
| 116 | local X = X | ||
| 117 | X:func(1, 2, 3) | ||
| 118 | X.tag = "abc" | ||
| 119 | return X | ||
| 120 | end | ||
