From ffa06586ba5b04bf9c223b41fe66cdb813ba1b34 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 4 Feb 2026 16:18:19 +0800 Subject: Splited docs. --- spec/outputs/codes_from_doc.lua | 4962 +++++++++++++++++------------------ spec/outputs/codes_from_doc_zh.lua | 4970 ++++++++++++++++++------------------ spec/outputs/compile_doc.lua | 135 +- 3 files changed, 5098 insertions(+), 4969 deletions(-) (limited to 'spec/outputs') diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index b8985e7..889105a 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua @@ -76,6 +76,123 @@ end local _u1f31b = "月之脚本" _module_0["🌛"] = _u1f31b return _module_0 +local _module_0 = { } +local p, to_lua +do + local _obj_0 = require("yue") + p, to_lua = _obj_0.p, _obj_0.to_lua +end +local inventory = { + equipment = { + "sword", + "shield" + }, + items = { + { + name = "potion", + count = 10 + }, + { + name = "bread", + count = 3 + } + } +} +local map +map = function(arr, action) + local _accum_0 = { } + local _len_0 = 1 + for _index_0 = 1, #arr do + local item = arr[_index_0] + _accum_0[_len_0] = action(item) + _len_0 = _len_0 + 1 + end + return _accum_0 +end +local filter +filter = function(arr, cond) + local _accum_0 = { } + local _len_0 = 1 + for _index_0 = 1, #arr do + local item = arr[_index_0] + if cond(item) then + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 + end + end + return _accum_0 +end +local reduce +reduce = function(arr, init, action) + for _index_0 = 1, #arr do + local item = arr[_index_0] + init = action(init, item) + end + return init +end +print(reduce(filter(map({ + 1, + 2, + 3 +}, function(x) + return x * 2 +end), function(x) + return x > 4 +end), 0, function(a, b) + return a + b +end)) +local apple = setmetatable({ + size = 15, +}, { + __index = { + color = 0x00ffff + } +}) +if (getmetatable(apple) ~= nil) then + p(apple.size, apple.color, getmetatable(apple).__index) +end +local _u1f31b = "月之脚本" +_module_0["🌛"] = _u1f31b +return _module_0 +local area = 6.2831853071796 * 5 +print('hello world') +do + assert(item ~= nil) +end +local value = item +if (f1() and f2() and f3()) then + print("OK") +end +do + local funcA + funcA = function() end +end +local funcA +funcA = function() + return "fail to assign to the Yue macro defined variable" +end +do +local function funcB() end +end +local funcB +funcB = function() + return "fail to assign to the Lua macro defined variable" +end +do +-- raw Lua codes insertion +if cond then + print("output") +end +end +print("yuescript") +print(2) +print("Valid enum type:", "Static") +do + print(123, "hello") +end +do + print(123, "hello") +end local area = 6.2831853071796 * 5 print('hello world') do @@ -408,46 +525,339 @@ local tb = { } } } -do - local insert, concat = table.insert, table.concat - local C, Ct, Cmt - do - local _obj_0 = require("lpeg") - C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt +if tb ~= nil then + tb:func() +end +if tb ~= nil then + tb:func() +end +print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5) +local a = 5 +print(1 <= a and a <= 10) +local v +v = function(x) + print(x) + return x +end +print((function() + local _cond_0 = v(2) + if not (v(1) < _cond_0) then + return false + else + return _cond_0 <= v(3) end - local x, y, z - do - local _obj_0 = require('mymodule') - x, y, z = _obj_0.x, _obj_0.y, _obj_0.z +end)()) +print((function() + local _cond_0 = v(2) + if not (v(1) > _cond_0) then + return false + else + return _cond_0 <= v(3) end - local a, b, c - local _obj_0 = require('module') - a, b, c = _obj_0.a, _obj_0.b, _obj_0.c +end)()) +local tab = { } +tab[#tab + 1] = "Value" +local tbA = { + 1, + 2, + 3 +} +local tbB = { + 4, + 5, + 6 +} +local _len_0 = #tbA + 1 +for _index_0 = 1, #tbB do + local _elm_0 = tbB[_index_0] + tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 end +local parts = { + "shoulders", + "knees" +} +local lyrics do - local module = require('module') - local module_x = require('module_x') - local d_a_s_h_e_s = require("d-a-s-h-e-s") - local part = require("module.part") + local _tab_0 = { + "head" + } + local _idx_0 = 1 + for _key_0, _value_0 in pairs(parts) do + if _idx_0 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_0 = _idx_0 + 1 + else + _tab_0[_key_0] = _value_0 + end + end + _tab_0[#_tab_0 + 1] = "and" + _tab_0[#_tab_0 + 1] = "toes" + lyrics = _tab_0 end +local copy do - local PlayerModule = require("player") - local C, Ct, Cmt - do - local _obj_0 = require("lpeg") - C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt + local _tab_0 = { } + local _idx_0 = 1 + for _key_0, _value_0 in pairs(other) do + if _idx_0 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_0 = _idx_0 + 1 + else + _tab_0[_key_0] = _value_0 + end end - local one, two, ch - local _obj_0 = require("export") - one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] + copy = _tab_0 end -do - local tostring = tostring - local concat = table.concat - print(concat({ - "a", - tostring(1) - })) +local a = { + 1, + 2, + 3, + x = 1 +} +local b = { + 4, + 5, + y = 1 +} +local merge +local _tab_0 = { } +local _idx_0 = 1 +for _key_0, _value_0 in pairs(a) do + if _idx_0 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_0 = _idx_0 + 1 + else + _tab_0[_key_0] = _value_0 + end +end +local _idx_1 = 1 +for _key_0, _value_0 in pairs(b) do + if _idx_1 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_1 = _idx_1 + 1 + else + _tab_0[_key_0] = _value_0 + end +end +merge = _tab_0 +local last +do + local _item_0 = data.items + last = _item_0[#_item_0] +end +local second_last +do + local _item_0 = data.items + second_last = _item_0[#_item_0 - 1] +end +local _obj_0 = data.items +_obj_0[#_obj_0] = 1 +local mt = { } +local add +add = function(self, right) + return setmetatable({ + value = self.value + right.value + }, mt) +end +mt.__add = add +local a = setmetatable({ + value = 1 +}, mt) +local b = setmetatable({ + value = 2 +}, { + __add = add +}) +local c = setmetatable({ + value = 3 +}, { + __add = mt.__add +}) +local d = a + b + c +print(d.value) +local _ = setmetatable({ }, { + __close = function() + return print("out of scope") + end +}) +local tb = setmetatable({ }, { + ["value"] = 123 +}) +getmetatable(tb).__index = getmetatable(tb) +print(tb.value) +setmetatable(tb, { + __index = { + item = "hello" + } +}) +print(tb.item) +local item, new, close, getter +do + local _obj_0 = tb + item, new = _obj_0[1], _obj_0.new + do + local _obj_1 = getmetatable(_obj_0) + close, getter = _obj_1.__close, _obj_1.__index + end +end +print(item, new, close, getter) +do + local _obj_0 = func + if _obj_0 ~= nil then + _obj_0() + end +end +print((function() + local _obj_0 = abc + if _obj_0 ~= nil then + local _obj_1 = _obj_0["hello world"] + if _obj_1 ~= nil then + return _obj_1.xyz + end + return nil + end + return nil +end)()) +local x +do + local _obj_0 = tab + if _obj_0 ~= nil then + x = _obj_0.value + end +end +local len = (function() + local _obj_0 = utf8 + if _obj_0 ~= nil then + return _obj_0.len + end + return nil +end)() or (function() + local _obj_0 = string + if _obj_0 ~= nil then + return _obj_0.len + end + return nil +end)() or function(o) + return #o +end +if print and (x ~= nil) then + print(x) +end +local _with_0 = io.open("test.txt", "w") +if _with_0 ~= nil then + _with_0:write("hello") + _with_0:close() +end +print("hello") +print(1, 2) +print(1, 2, 3) +print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) +local a, b, c, d +if b ~= nil then + a = b +else + if c ~= nil then + a = c + else + a = d + end +end +func((function() + if a ~= nil then + return a + else + return { } + end +end)()) +if a == nil then + a = false +end +local list = { + 1, + 2, + 3 +} +func({ + 1, + 2, + 3 +}) +local f +f = function() + return { + 1, + 2, + 3 + } +end +local tb = { + name = "abc", + values = { + "a", + "b", + "c" + }, + objects = { + { + name = "a", + value = 1, + func = function(self) + return self.value + 1 + end, + tb = { + fieldA = 1 + } + }, + { + name = "b", + value = 2, + func = function(self) + return self.value + 2 + end, + tb = { } + } + } +} +do + local insert, concat = table.insert, table.concat + local C, Ct, Cmt + do + local _obj_0 = require("lpeg") + C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt + end + local x, y, z + do + local _obj_0 = require('mymodule') + x, y, z = _obj_0.x, _obj_0.y, _obj_0.z + end + local a, b, c + local _obj_0 = require('module') + a, b, c = _obj_0.a, _obj_0.b, _obj_0.c +end +do + local module = require('module') + local module_x = require('module_x') + local d_a_s_h_e_s = require("d-a-s-h-e-s") + local part = require("module.part") +end +do + local PlayerModule = require("player") + local C, Ct, Cmt + do + local _obj_0 = require("lpeg") + C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt + end + local one, two, ch + local _obj_0 = require("export") + one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] +end +do + local tostring = tostring + local concat = table.concat + print(concat({ + "a", + tostring(1) + })) end do local print = print @@ -539,37 +949,219 @@ _module_0 = function() return 123 end return _module_0 -local hello = "world" -local a, b, c = 1, 2, 3 -hello = 123 -local x = 1 -x = x + 1 -x = x - 1 -x = x * 10 -x = x / 10 -x = x % 10 -local s = s .. "world" -local arg = arg or "default value" -local a = 0 -local b = 0 -local c = 0 -local d = 0 -local e = 0 -local x = f() -local y = x -local z = x do - local a = 1 + local insert, concat = table.insert, table.concat + local C, Ct, Cmt + do + local _obj_0 = require("lpeg") + C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt + end local x, y, z - print("forward declare all variables as locals") - x = function() - return 1 + y + z + do + local _obj_0 = require('mymodule') + x, y, z = _obj_0.x, _obj_0.y, _obj_0.z end - y, z = 2, 3 - instance = Item:new() + local a, b, c + local _obj_0 = require('module') + a, b, c = _obj_0.a, _obj_0.b, _obj_0.c end do - local X = 1 + local module = require('module') + local module_x = require('module_x') + local d_a_s_h_e_s = require("d-a-s-h-e-s") + local part = require("module.part") +end +do + local PlayerModule = require("player") + local C, Ct, Cmt + do + local _obj_0 = require("lpeg") + C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt + end + local one, two, ch + local _obj_0 = require("export") + one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] +end +do + local tostring = tostring + local concat = table.concat + print(concat({ + "a", + tostring(1) + })) +end +do + local print = print + local math = math + print("hello") + math.random(3) +end +do + local print = print + print(FLAG) + FLAG = 123 +end +local _module_0 = { } +local a, b, c = 1, 2, 3 +_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c +local cool = "cat" +_module_0["cool"] = cool +local What +if this then + What = "abc" +else + What = "def" +end +_module_0["What"] = What +local y +y = function() + local hallo = 3434 +end +_module_0["y"] = y +local Something +local _class_0 +local _base_0 = { + umm = "cool" +} +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Something" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end +}) +_base_0.__class = _class_0 +Something = _class_0 +_module_0["Something"] = Something +return _module_0 +local _module_0 = { } +local loadstring, tolua +do + local _obj_0 = yue + loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua +end +_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua +local fieldA = tb.itemA.fieldA +if fieldA == nil then + fieldA = 'default' +end +_module_0["fieldA"] = fieldA +return _module_0 +local _module_0 = setmetatable({ }, { }) +_module_0.itemA = tb +getmetatable(_module_0).__index = items +_module_0["a-b-c"] = 123 +return _module_0 +local _module_0 = { } +local d, e, f = 3, 2, 1 +_module_0[#_module_0 + 1] = d +_module_0[#_module_0 + 1] = e +_module_0[#_module_0 + 1] = f +if this then + _module_0[#_module_0 + 1] = 123 +else + _module_0[#_module_0 + 1] = 456 +end +local _with_0 = tmp +local j = 2000 +_module_0[#_module_0 + 1] = _with_0 +return _module_0 +local _module_0 = nil +_module_0 = function() + print("hello") + return 123 +end +return _module_0 +local hello = "world" +local a, b, c = 1, 2, 3 +hello = 123 +local x = 1 +x = x + 1 +x = x - 1 +x = x * 10 +x = x / 10 +x = x % 10 +local s = s .. "world" +local arg = arg or "default value" +local a = 0 +local b = 0 +local c = 0 +local d = 0 +local e = 0 +local x = f() +local y = x +local z = x +do + local a = 1 + local x, y, z + print("forward declare all variables as locals") + x = function() + return 1 + y + z + end + y, z = 2, 3 + instance = Item:new() +end +do + local X = 1 + local B + print("only forward declare upper case variables") + local a = 1 + B = 2 +end +do + a = 1 + print("declare all variables as globals") + x = function() + return 1 + y + z + end + y, z = 2, 3 +end +do + X = 1 + print("only declare upper case variables as globals") + local a = 1 + B = 2 + local Temp = "a local value" +end +local hello = "world" +local a, b, c = 1, 2, 3 +hello = 123 +local x = 1 +x = x + 1 +x = x - 1 +x = x * 10 +x = x / 10 +x = x % 10 +local s = s .. "world" +local arg = arg or "default value" +local a = 0 +local b = 0 +local c = 0 +local d = 0 +local e = 0 +local x = f() +local y = x +local z = x +do + local a = 1 + local x, y, z + print("forward declare all variables as locals") + x = function() + return 1 + y + z + end + y, z = 2, 3 + instance = Item:new() +end +do + local X = 1 local B print("only forward declare upper case variables") local a = 1 @@ -707,66 +1299,242 @@ for _index_0 = 1, #tuples do local left, right = _des_0[1], _des_0[2] print(left, right) end -local user = database.find_user("moon") -if user then - print(user.name) -end -local hello = os.getenv("hello") -if hello then - print("You have hello", hello) -else - local world = os.getenv("world") - if world then - print("you have world", world) - else - print("nothing :(") - end -end -do - local success, result = pcall(function() - return "get result without problems" - end) - if success then - print(result) - end -end -print("OK") -repeat - local byte = stream:read_one() - if byte then - print(byte) - else - break - end -until false -local list = { +local thing = { 1, - 2, - 3, - 4, - 5 + 2 } -local fn -fn = function(ok) - return ok, table.unpack(list) -end -(function(_arg_0, ...) - local ok = _arg_0 - local count = select('#', ...) - local first = select(1, ...) - return print(ok, count, first) -end)(fn(true)) -local a = 1 -local b = 2 -print(a + b) -Rx.Observable.fromRange(1, 8):filter(function(x) - return x % 2 == 0 -end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) - return value .. '!' -end):subscribe(print) -local str = strA .. strB .. strC -func(3000, "192.168.1.1") -xpcall(function() +local a, b = thing[1], thing[2] +print(a, b) +local obj = { + hello = "world", + day = "tuesday", + length = 20 +} +local hello, the_day = obj.hello, obj.day +print(hello, the_day) +local day = obj.day +local obj2 = { + numbers = { + 1, + 2, + 3, + 4 + }, + properties = { + color = "green", + height = 13.5 + } +} +local first, second = obj2.numbers[1], obj2.numbers[2] +print(first, second, color) +local first, second, color +local _obj_0 = obj2 +first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color +local concat, insert +local _obj_0 = table +concat, insert = _obj_0.concat, _obj_0.insert +local mix, max, rand +local _obj_0 = math +mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random +local name, job +local _obj_0 = person +name, job = _obj_0.name, _obj_0.job +if name == nil then + name = "nameless" +end +if job == nil then + job = "jobless" +end +local two, four +local _obj_0 = items +two, four = _obj_0[2], _obj_0[4] +local orders = { + "first", + "second", + "third", + "fourth", + "last" +} +local first, bulk, last = orders[1], (function() + local _accum_0 = { } + local _len_0 = 1 + local _max_0 = #orders + -2 + 1 + for _index_0 = 2, _max_0 do + local _item_0 = orders[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 + end + return _accum_0 +end)(), orders[#orders] +print(first) +print(bulk) +print(last) +local first, rest +do + local _obj_0 = orders + first, rest = _obj_0[1], (function() + local _accum_0 = { } + local _len_0 = 1 + local _max_0 = #_obj_0 + for _index_0 = 2, _max_0 do + local _item_0 = _obj_0[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 + end + return _accum_0 + end)() +end +local start, last +do + local _obj_0 = orders + start, last = (function() + local _accum_0 = { } + local _len_0 = 1 + local _max_0 = #_obj_0 + -2 + 1 + for _index_0 = 1, _max_0 do + local _item_0 = _obj_0[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 + end + return _accum_0 + end)(), _obj_0[#_obj_0] +end +local _obj_0 = orders +first, last = _obj_0[1], _obj_0[#_obj_0] +local tuples = { + { + "hello", + "world" + }, + { + "egg", + "head" + } +} +for _index_0 = 1, #tuples do + local _des_0 = tuples[_index_0] + local left, right = _des_0[1], _des_0[2] + print(left, right) +end +local user = database.find_user("moon") +if user then + print(user.name) +end +local hello = os.getenv("hello") +if hello then + print("You have hello", hello) +else + local world = os.getenv("world") + if world then + print("you have world", world) + else + print("nothing :(") + end +end +do + local success, result = pcall(function() + return "get result without problems" + end) + if success then + print(result) + end +end +print("OK") +repeat + local byte = stream:read_one() + if byte then + print(byte) + else + break + end +until false +local user = database.find_user("moon") +if user then + print(user.name) +end +local hello = os.getenv("hello") +if hello then + print("You have hello", hello) +else + local world = os.getenv("world") + if world then + print("you have world", world) + else + print("nothing :(") + end +end +do + local success, result = pcall(function() + return "get result without problems" + end) + if success then + print(result) + end +end +print("OK") +repeat + local byte = stream:read_one() + if byte then + print(byte) + else + break + end +until false +local list = { + 1, + 2, + 3, + 4, + 5 +} +local fn +fn = function(ok) + return ok, table.unpack(list) +end +(function(_arg_0, ...) + local ok = _arg_0 + local count = select('#', ...) + local first = select(1, ...) + return print(ok, count, first) +end)(fn(true)) +local list = { + 1, + 2, + 3, + 4, + 5 +} +local fn +fn = function(ok) + return ok, table.unpack(list) +end +(function(_arg_0, ...) + local ok = _arg_0 + local count = select('#', ...) + local first = select(1, ...) + return print(ok, count, first) +end)(fn(true)) +local a = 1 +local b = 2 +print(a + b) +Rx.Observable.fromRange(1, 8):filter(function(x) + return x % 2 == 0 +end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) + return value .. '!' +end):subscribe(print) +local a = 1 +local b = 2 +print(a + b) +Rx.Observable.fromRange(1, 8):filter(function(x) + return x % 2 == 0 +end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) + return value .. '!' +end):subscribe(print) +local str = strA .. strB .. strC +func(3000, "192.168.1.1") +local str = strA .. strB .. strC +func(3000, "192.168.1.1") +xpcall(function() return func(1, 2, 3) end, function(err) return print(yue.traceback(err)) @@ -846,30 +1614,132 @@ f((function() return e end)) end)()) -local a = 123 -local _ = setmetatable({ }, { - __close = function() - return print("Out of scope.") - end -}) -local a, b, c, d -local _obj_0 = tb -a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] -Constant = 123 -local some_string = "Here is a string\n that has a line break in it." -print("I am " .. tostring(math.random() * 100) .. "% sure.") -local integer = 1000000 -local hex = 0xEFBBBF -local binary = 19 -local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) -local fn -fn = function() - local str = "foo:\n bar: baz" - return str -end -local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" -local my_function -my_function = function() end +xpcall(function() + return func(1, 2, 3) +end, function(err) + return print(yue.traceback(err)) +end) +local success, result = xpcall(function() + return func(1, 2, 3) +end, function(err) + return yue.traceback(err) +end) +xpcall(function() + return func(1, 2, 3) +end, function(err) + return print(yue.traceback(err)) +end) +success, result = pcall(function() + return func(1, 2, 3) +end) +pcall(function() + print("trying") + return func(1, 2, 3) +end) +success, result = xpcall(function() + return func(1, 2, 3) +end, function(err) + return print(yue.traceback(err)) +end) +if success then + print(result) +end +local a, b, c +do + local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() + return func() + end) + if _ok_0 then + a, b, c = _ret_0, _ret_1, _ret_2 + end +end +do + local _exp_0 = ((function() + return (function(_arg_0, ...) + local _ok_0 = _arg_0 + if _ok_0 then + return ... + end + end)(pcall(function() + return func() + end)) + end)()) + if _exp_0 ~= nil then + a = _exp_0 + else + a = "default" + end +end +f((function() + return (function(_arg_0, ...) + local _ok_0 = _arg_0 + if _ok_0 then + return ... + end + end)(pcall(function() + return func() + end)) +end)()) +f((function() + return (function(_arg_0, ...) + local _ok_0 = _arg_0 + if _ok_0 then + return ... + end + end)(xpcall(function() + print(123) + return func() + end, function(e) + print(e) + return e + end)) +end)()) +local a = 123 +local _ = setmetatable({ }, { + __close = function() + return print("Out of scope.") + end +}) +local a, b, c, d +local _obj_0 = tb +a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] +Constant = 123 +local a = 123 +local _ = setmetatable({ }, { + __close = function() + return print("Out of scope.") + end +}) +local a, b, c, d +local _obj_0 = tb +a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] +Constant = 123 +local some_string = "Here is a string\n that has a line break in it." +print("I am " .. tostring(math.random() * 100) .. "% sure.") +local integer = 1000000 +local hex = 0xEFBBBF +local binary = 19 +local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) +local fn +fn = function() + local str = "foo:\n bar: baz" + return str +end +local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" +local some_string = "Here is a string\n that has a line break in it." +print("I am " .. tostring(math.random() * 100) .. "% sure.") +local integer = 1000000 +local hex = 0xEFBBBF +local binary = 19 +local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) +local fn +fn = function() + local str = "foo:\n bar: baz" + return str +end +local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" +local my_function +my_function = function() end my_function() local func_a func_a = function() @@ -1052,70 +1922,345 @@ process = function(...) return sum end process(1, nil, 3, nil, 5) -f(function() - return print("hello") -end) -f(function(self) - return print(self.value) -end) -map(function(x) - return x * 2 -end, { - 1, - 2, - 3 -}) -local result, msg -do - result, msg = readAsync("filename.txt", function(data) - print(data) - return processAsync(data, function(info) - return check(info) - end) - end) +local my_function +my_function = function() end +my_function() +local func_a +func_a = function() + return print("hello world") end -print(result, msg) -local some_values = { - 1, - 2, - 3, - 4 -} -local some_values = { - name = "Bill", - age = 200, - ["favorite food"] = "rice" -} -local profile = { - height = "4 feet", - shoe_size = 13, - favorite_foods = { - "ice cream", - "donuts" - } -} -local values = { +local func_b +func_b = function() + local value = 100 + return print("The value:", value) +end +func_a() +func_b() +local sum +sum = function(x, y) + return print("sum", x + y) +end +sum(10, 20) +print(sum(10, 20)) +a(b(c("a", "b", "c"))) +print("x:", sum(10, 20), "y:", sum(30, 40)) +local sum +sum = function(x, y) + return x + y +end +print("The sum is ", sum(10, 20)) +local sum +sum = function(x, y) + return x + y +end +local mystery +mystery = function(x, y) + return x + y, x - y +end +local a, b = mystery(10, 20) +local func +func = function(self, num) + return self.value + num +end +local my_function +my_function = function(name, height) + if name == nil then + name = "something" + end + if height == nil then + height = 100 + end + print("Hello I am", name) + return print("My height is", height) +end +local some_args +some_args = function(x, y) + if x == nil then + x = 100 + end + if y == nil then + y = x + 1000 + end + return print(x + y) +end +local a = x - 10 +local b = x - 10 +local c = x(-y) +local d = x - z +local x = func("hello") + 100 +local y = func("hello" + 100) +my_func(5, 4, 3, 8, 9, 10) +cool_func(1, 2, 3, 4, 5, 6, 7, 8) +my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4) +local x = { 1, 2, 3, 4, - 5, - 6, - 7, + a_func(4, 5, 5, 6), 8, - name = "superman", - occupation = "crime fighting" + 9, + 10 } -my_function({ - dance = "Tango", - partner = "none" -}) local y = { - type = "dog", - legs = 4, - tails = 1 + my_func(1, 2, 3, 4, 5), + 5, + 6, + 7 } -local tbl = { +if func(1, 2, 3, "hello", "world") then + print("hello") + print("I am inside if") +end +if func(1, 2, 3, "hello", "world") then + print("hello") + print("I am inside if") +end +local f1 +f1 = function(_arg_0) + local a, b, c + a, b, c = _arg_0.a, _arg_0.b, _arg_0.c + return print(a, b, c) +end +f1({ + a = 1, + b = "2", + c = { } +}) +local f2 +f2 = function(_arg_0, c) + local a1, b + a1, b = _arg_0.a, _arg_0.b + if a1 == nil then + a1 = 123 + end + if b == nil then + b = 'abc' + end + if c == nil then + c = { } + end +end +print(a1, b, c) +local arg1 = { + a = 0 +} +f2(arg1, arg2) +local findFirstEven +findFirstEven = function(list) + for _index_0 = 1, #list do + local item = list[_index_0] + if type(item) == "table" then + for _index_1 = 1, #item do + local sub = item[_index_1] + if sub % 2 == 0 then + return sub + end + end + end + end + return nil +end +local findFirstEven +findFirstEven = function(list) + for _index_0 = 1, #list do + local item = list[_index_0] + if type(item) == "table" then + for _index_1 = 1, #item do + local sub = item[_index_1] + if sub % 2 == 0 then + return sub + end + end + end + 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(x) + return print("hello" .. x) +end) +f(function(self) + return print(self.value) +end) +map(function(x) + return x * 2 +end, { + 1, + 2, + 3 +}) +local result, msg +do + result, msg = readAsync("filename.txt", function(data) + print(data) + return processAsync(data, function(info) + return check(info) + end) + end) +end +print(result, msg) +f(function(x) + return print("hello" .. x) +end) +f(function(self) + return print(self.value) +end) +map(function(x) + return x * 2 +end, { + 1, + 2, + 3 +}) +local result, msg +do + result, msg = readAsync("filename.txt", function(data) + print(data) + return processAsync(data, function(info) + return check(info) + end) + end) +end +print(result, msg) +local some_values = { + 1, + 2, + 3, + 4 +} +local some_values = { + name = "Bill", + age = 200, + ["favorite food"] = "rice" +} +local profile = { + height = "4 feet", + shoe_size = 13, + favorite_foods = { + "ice cream", + "donuts" + } +} +local values = { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + name = "superman", + occupation = "crime fighting" +} +my_function({ + dance = "Tango", + partner = "none" +}) +local y = { + type = "dog", + legs = 4, + tails = 1 +} +local tbl = { + ["do"] = "something", + ["end"] = "hunger" +} +local hair = "golden" +local height = 200 +local person = { + hair = hair, + height = height, + shoe_size = 40 +} +print_table({ + hair = hair, + height = height +}) +local t = { + [1 + 2] = "hello", + ["hello world"] = true +} +local some_values = { + 1, + 2, + 3, + 4 +} +local list_with_one_element = { + 1 +} +local some_values = { + 1, + 2, + 3, + 4 +} +local some_values = { + name = "Bill", + age = 200, + ["favorite food"] = "rice" +} +local profile = { + height = "4 feet", + shoe_size = 13, + favorite_foods = { + "ice cream", + "donuts" + } +} +local values = { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + name = "superman", + occupation = "crime fighting" +} +my_function({ + dance = "Tango", + partner = "none" +}) +local y = { + type = "dog", + legs = 4, + tails = 1 +} +local tbl = { ["do"] = "something", ["end"] = "hunger" } @@ -1341,15 +2486,250 @@ for _index_0 = _min_0, 1, -1 do end reverse_slice = _accum_0 local sub_list -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -for _index_0 = 2, 4 do - local _item_0 = _list_0[_index_0] - _accum_0[_len_0] = _item_0 - _len_0 = _len_0 + 1 +do + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = items + for _index_0 = 2, 4 do + local _item_0 = _list_0[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 + end + sub_list = _accum_0 +end +local last_four_items +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _min_0 = #_list_0 + -4 + 1 +local _max_0 = #_list_0 + -1 + 1 +for _index_0 = _min_0, _max_0 do + local _item_0 = _list_0[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 +end +last_four_items = _accum_0 +local items = { + 1, + 2, + 3, + 4 +} +local doubled +local _accum_0 = { } +local _len_0 = 1 +for i, item in ipairs(items) do + _accum_0[_len_0] = item * 2 + _len_0 = _len_0 + 1 +end +doubled = _accum_0 +local slice +local _accum_0 = { } +local _len_0 = 1 +for i, item in ipairs(items) do + if i > 1 and i < 3 then + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 + end +end +slice = _accum_0 +local doubled +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item * 2 + _len_0 = _len_0 + 1 +end +doubled = _accum_0 +local data = { + a = { + 1, + 2, + 3 + }, + b = { + 4, + 5, + 6 + } +} +local flat +local _accum_0 = { } +for k, v in pairs(data) do + local _len_0 = #_accum_0 + 1 + for _index_0 = 1, #v do + local _elm_0 = v[_index_0] + _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1 + end +end +flat = _accum_0 +local x_coords = { + 4, + 5, + 6, + 7 +} +local y_coords = { + 9, + 2, + 3 +} +local points +local _accum_0 = { } +local _len_0 = 1 +for _index_0 = 1, #x_coords do + local x = x_coords[_index_0] + for _index_1 = 1, #y_coords do + local y = y_coords[_index_1] + _accum_0[_len_0] = { + x, + y + } + _len_0 = _len_0 + 1 + end +end +points = _accum_0 +local evens +local _accum_0 = { } +local _len_0 = 1 +for i = 1, 100 do + if i % 2 == 0 then + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end +end +evens = _accum_0 +local thing = { + color = "red", + name = "fast", + width = 123 +} +local thing_copy +local _tbl_0 = { } +for k, v in pairs(thing) do + _tbl_0[k] = v +end +thing_copy = _tbl_0 +local no_color +local _tbl_0 = { } +for k, v in pairs(thing) do + if k ~= "color" then + _tbl_0[k] = v + end +end +no_color = _tbl_0 +local numbers = { + 1, + 2, + 3, + 4 +} +local sqrts +local _tbl_0 = { } +for _index_0 = 1, #numbers do + local i = numbers[_index_0] + _tbl_0[i] = math.sqrt(i) +end +sqrts = _tbl_0 +local tuples = { + { + "hello", + "world" + }, + { + "foo", + "bar" + } +} +local tbl +local _tbl_0 = { } +for _index_0 = 1, #tuples do + local tuple = tuples[_index_0] + local _key_0, _val_0 = unpack(tuple) + _tbl_0[_key_0] = _val_0 +end +tbl = _tbl_0 +local slice +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +for _index_0 = 1, 5 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 +end +slice = _accum_0 +local slice +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _max_0 = #_list_0 +for _index_0 = 2, _max_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 +end +slice = _accum_0 +local slice +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _max_0 = #_list_0 +for _index_0 = 1, _max_0, 2 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 +end +slice = _accum_0 +local slice +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _min_0 = #_list_0 + -4 + 1 +local _max_0 = #_list_0 + -1 + 1 +for _index_0 = _min_0, _max_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 +end +slice = _accum_0 +local reverse_slice +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _min_0 = #_list_0 + -1 + 1 +for _index_0 = _min_0, 1, -1 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 +end +reverse_slice = _accum_0 +local sub_list +do + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = items + for _index_0 = 2, 4 do + local _item_0 = _list_0[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 + end + sub_list = _accum_0 +end +local last_four_items +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _min_0 = #_list_0 + -4 + 1 +local _max_0 = #_list_0 + -1 + 1 +for _index_0 = _min_0, _max_0 do + local _item_0 = _list_0[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 end -sub_list = _accum_0 +last_four_items = _accum_0 for i = 10, 20 do print(i) end @@ -1414,28 +2794,143 @@ func_b = function() end print(func_a()) print(func_b()) -local i = 10 -repeat - print(i) - i = i - 1 -until i == 0 -local i = 10 -while i > 0 do +for i = 10, 20 do print(i) - i = i - 1 -end -while running == true do - my_function() end -local i = 10 -while not (i == 0) do - print(i) - i = i - 1 +for k = 1, 15, 2 do + print(k) end -while not (running == false) do - my_function() +for key, value in pairs(object) do + print(key, value) end -local i = 0 +local _list_0 = items +for _index_0 = 2, 4 do + local item = _list_0[_index_0] + print(item) +end +local _list_0 = items +for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + print(item) +end +for j = 1, 10, 3 do + print(j) +end +local doubled_evens +local _accum_0 = { } +local _len_0 = 1 +for i = 1, 20 do + if i % 2 == 0 then + _accum_0[_len_0] = i * 2 + _len_0 = _len_0 + 1 + else + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end +end +doubled_evens = _accum_0 +local first_large +local _accum_0 +local _list_0 = numbers +for _index_0 = 1, #_list_0 do + local n = _list_0[_index_0] + if n > 10 then + _accum_0 = n + break + end +end +first_large = _accum_0 +local func_a +func_a = function() + for i = 1, 10 do + print(i) + end +end +local func_b +func_b = function() + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end + return _accum_0 +end +print(func_a()) +print(func_b()) +local i = 10 +while i > 0 do + print(i) + i = i - 1 +end +while running == true do + my_function() +end +local i = 10 +while not (i == 0) do + print(i) + i = i - 1 +end +while not (running == false) do + my_function() +end +local i = 10 +repeat + print(i) + i = i - 1 +until i == 0 +local i = 10 +while i > 0 do + print(i) + i = i - 1 +end +while running == true do + my_function() +end +local i = 10 +while not (i == 0) do + print(i) + i = i - 1 +end +while not (running == false) do + my_function() +end +local i = 10 +repeat + print(i) + i = i - 1 +until i == 0 +local i = 0 +while i < 10 do + i = i + 1 + if i % 2 == 0 then + goto _continue_0 + end + print(i) + ::_continue_0:: +end +local my_numbers = { + 1, + 2, + 3, + 4, + 5, + 6 +} +local odds +local _accum_0 = { } +local _len_0 = 1 +for _index_0 = 1, #my_numbers do + local x = my_numbers[_index_0] + if x % 2 == 1 then + goto _continue_0 + end + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + ::_continue_0:: +end +odds = _accum_0 +local i = 0 while i < 10 do i = i + 1 if i % 2 == 0 then @@ -1524,6 +3019,79 @@ end if not (math.random() > 0.1) then print("You're lucky!") end +local have_coins = false +if have_coins then + print("Got coins") +else + print("No coins") +end +local have_coins = false +if have_coins then + print("Got coins") +else + print("No coins") +end +local have_coins = false +print((function() + if have_coins then + return "Got coins" + else + return "No coins" + end +end)()) +local is_tall +is_tall = function(name) + if name == "Rob" then + return true + else + return false + end +end +local message +if is_tall("Rob") then + message = "I am very tall" +else + message = "I am not so tall" +end +print(message) +if not (os.date("%A") == "Monday") then + print("it is not Monday!") +end +if not (math.random() > 0.1) then + print("You're lucky!") +end +local a = 5 +if (1 == a or 3 == a or 5 == a or 7 == a) then + print("checking equality with discrete values") +end +if (function() + local _check_0 = list + for _index_0 = 1, #_check_0 do + if _check_0[_index_0] == a then + return true + end + end + return false +end)() then + print("checking if `a` is in a list") +end +if not (math.random() > 0.1) then + print("You're lucky!") +end +if name == "Rob" then + print("hello world") +end +local _list_0 = items +for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + print("item: ", item) +end +while game:isRunning() do + game:update() +end +while not reader:eof() do + reader:parse_line() +end if name == "Rob" then print("hello world") end @@ -1830,207 +3398,321 @@ if _tab_0 then print("Action:", action) end end -local Inventory -local _class_0 -local _base_0 = { - add_item = function(self, name) - if self.items[name] then - local _obj_0 = self.items - _obj_0[name] = _obj_0[name] + 1 - else - self.items[name] = 1 - end +local name = "Dan" +if "Robert" == name then + print("You are Robert") +elseif "Dan" == name or "Daniel" == name then + print("Your name, it's Dan") +else + print("I don't know about you with name " .. tostring(name)) +end +local b = 1 +local next_number +if 1 == b then + next_number = 2 +elseif 2 == b then + next_number = 3 +else + next_number = error("can't count that high!") +end +local msg +local _exp_0 = math.random(1, 5) +if 1 == _exp_0 then + msg = "you are lucky" +elseif 2 == _exp_0 then + msg = "you are almost lucky" +else + msg = "not so lucky" +end +do + local _exp_0 = math.random(1, 5) + if 1 == _exp_0 then + print("you are lucky") + else + print("not so lucky") end -} -if _base_0.__index == nil then - _base_0.__index = _base_0 end -_class_0 = setmetatable({ - __init = function(self) - self.items = { } - end, - __base = _base_0, - __name = "Inventory" -}, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end -}) -_base_0.__class = _class_0 -Inventory = _class_0 -local inv = Inventory() -inv:add_item("t-shirt") -inv:add_item("pants") -local Person -do - local _class_0 - local _base_0 = { - clothes = { }, - give_item = function(self, name) - return table.insert(self.clothes, name) - end +local _exp_0 = math.random(1, 5) +if 1 == _exp_0 then + print("you are lucky") +else + print("not so lucky") +end +local items = { + { + x = 100, + y = 200 + }, + { + width = 300, + height = 400 } - if _base_0.__index == nil then - _base_0.__index = _base_0 +} +for _index_0 = 1, #items do + local item = items[_index_0] + local _type_0 = type(item) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local x = item.x + local y = item.y + if x ~= nil and y ~= nil then + _match_0 = true + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) + end end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Person" - }, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 + if not _match_0 then + if _tab_0 then + local width = item.width + local height = item.height + if width ~= nil and height ~= nil then + print("size " .. tostring(width) .. ", " .. tostring(height)) + end end - }) - _base_0.__class = _class_0 - Person = _class_0 + end end -local a = Person() -local b = Person() -a:give_item("pants") -b:give_item("shirt") -local _list_0 = a.clothes -for _index_0 = 1, #_list_0 do - local item = _list_0[_index_0] - print(item) +local item = { } +local x, y = item.pos.x, item.pos.y +if x == nil then + x = 50 end -local Person -local _class_0 -local _base_0 = { } -if _base_0.__index == nil then - _base_0.__index = _base_0 +if y == nil then + y = 200 end -_class_0 = setmetatable({ - __init = function(self) - self.clothes = { } - end, - __base = _base_0, - __name = "Person" -}, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 +local _type_0 = type(item) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +if _tab_0 then + do + local _obj_0 = item.pos + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + x = _obj_0.x + end end -}) -_base_0.__class = _class_0 -Person = _class_0 -local BackPack -local _class_0 -local _parent_0 = Inventory -local _base_0 = { - size = 10, - add_item = function(self, name) - if #self.items > size then - error("backpack is full") + do + local _obj_0 = item.pos + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + y = _obj_0.y end - return _class_0.__parent.__base.add_item(self, name) end -} -for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 + if x == nil then + x = 50 + end + if y == nil then + y = 200 end + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end -if _base_0.__index == nil then - _base_0.__index = _base_0 +local _exp_0 = tb +local _type_0 = type(_exp_0) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +local _match_0 = false +if _tab_0 then + if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then + _match_0 = true + print("1, 2, 3") + end end -setmetatable(_base_0, _parent_0.__base) -_class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, - __base = _base_0, - __name = "BackPack", - __parent = _parent_0 -}, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] +if not _match_0 then + local _match_1 = false + if _tab_0 then + local b = _exp_0[2] + if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then + _match_1 = true + print("1, " .. tostring(b) .. ", 3") + end + end + if not _match_1 then + if _tab_0 then + local b = _exp_0[3] + if b == nil then + b = 3 + end + if 1 == _exp_0[1] and 2 == _exp_0[2] then + print("1, 2, " .. tostring(b)) end - else - return val end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 end -}) -_base_0.__class = _class_0 -if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) end -BackPack = _class_0 -local Shelf -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _exp_0 = tb +local _type_0 = type(_exp_0) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +local _match_0 = false +if _tab_0 then + local result = _exp_0.result + if true == _exp_0.success and result ~= nil then + _match_0 = true + print("success", result) end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Shelf" - }, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 +end +if not _match_0 then + local _match_1 = false + if _tab_0 then + if false == _exp_0.success then + _match_1 = true + print("failed", result) end - }) - _base_0.__class = _class_0 - local self = _class_0; - self.__inherited = function(self, child) - return print(self.__name, "was inherited by", child.__name) end - Shelf = _class_0 -end -local Cupboard -local _class_0 -local _parent_0 = Shelf -local _base_0 = { } -for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 + if not _match_1 then + print("invalid") end end -if _base_0.__index == nil then - _base_0.__index = _base_0 -end -setmetatable(_base_0, _parent_0.__base) -_class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, - __base = _base_0, - __name = "Cupboard", - __parent = _parent_0 -}, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end +local _exp_0 = tb +local _type_0 = type(_exp_0) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +local _match_0 = false +if _tab_0 then + local content + do + local _obj_0 = _exp_0.data + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + content = _obj_0.content + end + end + local _val_0 + do + local _obj_0 = _exp_0.data + if _obj_0 ~= nil then + _val_0 = _obj_0.type + end + end + if "success" == _val_0 and content ~= nil then + _match_0 = true + print("success", content) + end +end +if not _match_0 then + local _match_1 = false + if _tab_0 then + local content + do + local _obj_0 = _exp_0.data + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + content = _obj_0.content + end + end + local _val_0 + do + local _obj_0 = _exp_0.data + if _obj_0 ~= nil then + _val_0 = _obj_0.type + end + end + if "error" == _val_0 and content ~= nil then + _match_1 = true + print("failed", content) + end + end + if not _match_1 then + print("invalid") + end +end +local _exp_0 = tb +local _type_0 = type(_exp_0) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +if _tab_0 then + local fourth = _exp_0[4] + local _val_0 + do + local _obj_0 = _exp_0[1] + if _obj_0 ~= nil then + _val_0 = _obj_0.a + end + end + local _val_1 + do + local _obj_0 = _exp_0[1] + if _obj_0 ~= nil then + _val_1 = _obj_0.b + end + end + local _val_2 + do + local _obj_0 = _exp_0[2] + if _obj_0 ~= nil then + _val_2 = _obj_0.a + end + end + local _val_3 + do + local _obj_0 = _exp_0[2] + if _obj_0 ~= nil then + _val_3 = _obj_0.b + end + end + local _val_4 + do + local _obj_0 = _exp_0[3] + if _obj_0 ~= nil then + _val_4 = _obj_0.a + end + end + local _val_5 + do + local _obj_0 = _exp_0[3] + if _obj_0 ~= nil then + _val_5 = _obj_0.b + end + end + if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then + print("matched", fourth) + end +end +local segments = { + "admin", + "users", + "logs", + "view" +} +local _type_0 = type(segments) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +if _tab_0 then + local groups + do + local _accum_0 = { } + local _len_0 = 1 + local _max_0 = #segments + -3 + 1 + for _index_0 = 1, _max_0 do + local _item_0 = segments[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 + end + groups = _accum_0 + end + local resource = segments[#segments - 1] + local action = segments[#segments] + if resource ~= nil and action ~= nil then + print("Group:", groups) + print("Resource:", resource) + print("Action:", action) + end +end +local Inventory +local _class_0 +local _base_0 = { + add_item = function(self, name) + if self.items[name] then + local _obj_0 = self.items + _obj_0[name] = _obj_0[name] + 1 else - return val + self.items[name] = 1 end + end +} +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function(self) + self.items = { } end, + __base = _base_0, + __name = "Inventory" +}, { + __index = _base_0, __call = function(cls, ...) local _self_0 = setmetatable({ }, _base_0) cls.__init(_self_0, ...) @@ -2038,19 +3720,78 @@ _class_0 = setmetatable({ end }) _base_0.__class = _class_0 -if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) +Inventory = _class_0 +local inv = Inventory() +inv:add_item("t-shirt") +inv:add_item("pants") +local Person +do + local _class_0 + local _base_0 = { + clothes = { }, + give_item = function(self, name) + return table.insert(self.clothes, name) + end + } + if _base_0.__index == nil then + _base_0.__index = _base_0 + end + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Person" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_0.__class = _class_0 + Person = _class_0 end -Cupboard = _class_0 -local MyClass +local a = Person() +local b = Person() +a:give_item("pants") +b:give_item("shirt") +local _list_0 = a.clothes +for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + print(item) +end +local Person local _class_0 -local _parent_0 = ParentClass +local _base_0 = { } +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function(self) + self.clothes = { } + end, + __base = _base_0, + __name = "Person" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end +}) +_base_0.__class = _class_0 +Person = _class_0 +local BackPack +local _class_0 +local _parent_0 = Inventory local _base_0 = { - a_method = function(self) - _class_0.__parent.__base.a_method(self, "hello", "world") - _class_0.__parent.a_method(self, "hello", "world") - _class_0.__parent.a_method(self, "hello", "world") - return assert(_class_0.__parent == ParentClass) + size = 10, + add_item = function(self, name) + if #self.items > size then + error("backpack is full") + end + return _class_0.__parent.__base.add_item(self, name) end } for _key_0, _val_0 in pairs(_parent_0.__base) do @@ -2067,7 +3808,7 @@ _class_0 = setmetatable({ return _class_0.__parent.__init(self, ...) end, __base = _base_0, - __name = "MyClass", + __name = "BackPack", __parent = _parent_0 }, { __index = function(cls, name) @@ -2091,12 +3832,8 @@ _base_0.__class = _class_0 if _parent_0.__inherited then _parent_0.__inherited(_parent_0, _class_0) end -MyClass = _class_0 -local b = BackPack() -assert(b.__class == BackPack) -print(BackPack.size) -print(BackPack.__name) -local Things +BackPack = _class_0 +local Shelf do local _class_0 local _base_0 = { } @@ -2106,7 +3843,7 @@ do _class_0 = setmetatable({ __init = function() end, __base = _base_0, - __name = "Things" + __name = "Shelf" }, { __index = _base_0, __call = function(cls, ...) @@ -2117,17 +3854,140 @@ do }) _base_0.__class = _class_0 local self = _class_0; - self.some_func = function(self) - return print("Hello from", self.__name) + self.__inherited = function(self, child) + return print(self.__name, "was inherited by", child.__name) end - Things = _class_0 + Shelf = _class_0 end -Things:some_func() -assert(Things().some_func == nil) -local Counter -do - local _class_0 - local _base_0 = { } +local Cupboard +local _class_0 +local _parent_0 = Shelf +local _base_0 = { } +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "Cupboard", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] + end + else + return val + end + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) +end +Cupboard = _class_0 +local MyClass +local _class_0 +local _parent_0 = ParentClass +local _base_0 = { + a_method = function(self) + _class_0.__parent.__base.a_method(self, "hello", "world") + _class_0.__parent.a_method(self, "hello", "world") + _class_0.__parent.a_method(self, "hello", "world") + return assert(_class_0.__parent == ParentClass) + end +} +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "MyClass", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] + end + else + return val + end + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) +end +MyClass = _class_0 +local b = BackPack() +assert(b.__class == BackPack) +print(BackPack.size) +print(BackPack.__name) +local Things +do + local _class_0 + local _base_0 = { } + if _base_0.__index == nil then + _base_0.__index = _base_0 + end + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Things" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_0.__class = _class_0 + local self = _class_0; + self.some_func = function(self) + return print("Hello from", self.__name) + end + Things = _class_0 +end +Things:some_func() +assert(Things().some_func == nil) +local Counter +do + local _class_0 + local _base_0 = { } if _base_0.__index == nil then _base_0.__index = _base_0 end @@ -2334,2062 +4194,122 @@ do else return val end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end - }) - _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) - end - BigBucket = _class_0 -end -assert(Bucket.__name == "BigBucket") -local x -local _class_0 -local _base_0 = { } -if _base_0.__index == nil then - _base_0.__index = _base_0 -end -_class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "x" -}, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end -}) -_base_0.__class = _class_0 -x = _class_0 -local MyIndex = { - __index = { - var = 1 - } -} -local X -do - local _class_0 - local _base_0 = { - func = function(self) - return print(123) - end - } - local _list_0 = { - MyIndex - } - for _index_0 = 1, #_list_0 do - local _item_0 = _list_0[_index_0] - local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0 - for _key_0, _val_0 in pairs(_mixin_0) do - if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then - _base_0[_key_0] = _val_0 - end - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "X" - }, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end - }) - _base_0.__class = _class_0 - X = _class_0 -end -local x = X() -print(x.var) -local Y -do - local _class_0 - local _base_0 = { } - local _list_0 = { - X - } - for _index_0 = 1, #_list_0 do - local _item_0 = _list_0[_index_0] - local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0 - for _key_0, _val_0 in pairs(_mixin_0) do - if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then - _base_0[_key_0] = _val_0 - end - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Y" - }, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end - }) - _base_0.__class = _class_0 - Y = _class_0 -end -local y = Y() -y:func() -assert(y.__class.__parent ~= X) -local _with_0 = Person() -_with_0.name = "Oswald" -_with_0:add_relative(my_dad) -_with_0:save() -print(_with_0.name) -local file -local _with_0 = File("favorite_foods.txt") -_with_0:set_encoding("utf8") -file = _with_0 -local create_person -create_person = function(name, relatives) - local _with_0 = Person() - _with_0.name = name - for _index_0 = 1, #relatives do - local relative = relatives[_index_0] - _with_0:add_relative(relative) - end - return _with_0 -end -local me = create_person("Leaf", { - dad, - mother, - sister -}) -local str = "Hello" -print("original:", str) -print("upper:", str:upper()) -local _with_0 = tb -_with_0[1] = 1 -print(_with_0[2]) -do - local _with_1 = _with_0[abc] - _with_1[3] = _with_1[2]:func() - _with_1["key-name"] = value -end -_with_0[#_with_0 + 1] = "abc" -local _with_0 = obj -if _with_0 ~= nil then - print(obj.name) -end -do - local var = "hello" - print(var) -end -print(var) -local counter -do - local i = 0 - counter = function() - i = i + 1 - return i - end -end -print(counter()) -print(counter()) -local tbl = { - key = (function() - print("assigning key!") - return 1234 - end)() -} -local my_object = { - value = 1000, - write = function(self) - return print("the value:", self.value) - end -} -local run_callback -run_callback = function(func) - print("running callback...") - return func() -end -run_callback(my_object.write) -run_callback((function() - local _base_0 = my_object - local _fn_0 = _base_0.write - return _fn_0 and function(...) - return _fn_0(_base_0, ...) - end -end)()) -local i = 100 -local my_func -my_func = function() - i = 10 - while i > 0 do - print(i) - i = i - 1 - end -end -my_func() -print(i) -local i = 100 -local my_func -my_func = function() - local i = "hello" -end -my_func() -print(i) -local tmp = 1213 -local i, k = 100, 50 -local my_func -my_func = function(add) - local tmp = tmp + add - i = i + tmp - k = k + tmp -end -my_func(22) -print(i, k) -local _module_0 = { } -local p, to_lua -do - local _obj_0 = require("yue") - p, to_lua = _obj_0.p, _obj_0.to_lua -end -local inventory = { - equipment = { - "sword", - "shield" - }, - items = { - { - name = "potion", - count = 10 - }, - { - name = "bread", - count = 3 - } - } -} -local map -map = function(arr, action) - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #arr do - local item = arr[_index_0] - _accum_0[_len_0] = action(item) - _len_0 = _len_0 + 1 - end - return _accum_0 -end -local filter -filter = function(arr, cond) - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #arr do - local item = arr[_index_0] - if cond(item) then - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - end - return _accum_0 -end -local reduce -reduce = function(arr, init, action) - for _index_0 = 1, #arr do - local item = arr[_index_0] - init = action(init, item) - end - return init -end -print(reduce(filter(map({ - 1, - 2, - 3 -}, function(x) - return x * 2 -end), function(x) - return x > 4 -end), 0, function(a, b) - return a + b -end)) -local apple = setmetatable({ - size = 15, -}, { - __index = { - color = 0x00ffff - } -}) -if (getmetatable(apple) ~= nil) then - p(apple.size, apple.color, getmetatable(apple).__index) -end -local _u1f31b = "月之脚本" -_module_0["🌛"] = _u1f31b -return _module_0 -local area = 6.2831853071796 * 5 -print('hello world') -do - assert(item ~= nil) -end -local value = item -if (f1() and f2() and f3()) then - print("OK") -end -do - local funcA - funcA = function() end -end -local funcA -funcA = function() - return "fail to assign to the Yue macro defined variable" -end -do -local function funcB() end -end -local funcB -funcB = function() - return "fail to assign to the Lua macro defined variable" -end -do --- raw Lua codes insertion -if cond then - print("output") -end -end -print("yuescript") -print(2) -print("Valid enum type:", "Static") -do - print(123, "hello") -end -do - print(123, "hello") -end -if tb ~= nil then - tb:func() -end -if tb ~= nil then - tb:func() -end -print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5) -local a = 5 -print(1 <= a and a <= 10) -local v -v = function(x) - print(x) - return x -end -print((function() - local _cond_0 = v(2) - if not (v(1) < _cond_0) then - return false - else - return _cond_0 <= v(3) - end -end)()) -print((function() - local _cond_0 = v(2) - if not (v(1) > _cond_0) then - return false - else - return _cond_0 <= v(3) - end -end)()) -local tab = { } -tab[#tab + 1] = "Value" -local tbA = { - 1, - 2, - 3 -} -local tbB = { - 4, - 5, - 6 -} -local _len_0 = #tbA + 1 -for _index_0 = 1, #tbB do - local _elm_0 = tbB[_index_0] - tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 -end -local parts = { - "shoulders", - "knees" -} -local lyrics -do - local _tab_0 = { - "head" - } - local _idx_0 = 1 - for _key_0, _value_0 in pairs(parts) do - if _idx_0 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_0 = _idx_0 + 1 - else - _tab_0[_key_0] = _value_0 - end - end - _tab_0[#_tab_0 + 1] = "and" - _tab_0[#_tab_0 + 1] = "toes" - lyrics = _tab_0 -end -local copy -do - local _tab_0 = { } - local _idx_0 = 1 - for _key_0, _value_0 in pairs(other) do - if _idx_0 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_0 = _idx_0 + 1 - else - _tab_0[_key_0] = _value_0 - end - end - copy = _tab_0 -end -local a = { - 1, - 2, - 3, - x = 1 -} -local b = { - 4, - 5, - y = 1 -} -local merge -local _tab_0 = { } -local _idx_0 = 1 -for _key_0, _value_0 in pairs(a) do - if _idx_0 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_0 = _idx_0 + 1 - else - _tab_0[_key_0] = _value_0 - end -end -local _idx_1 = 1 -for _key_0, _value_0 in pairs(b) do - if _idx_1 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_1 = _idx_1 + 1 - else - _tab_0[_key_0] = _value_0 - end -end -merge = _tab_0 -local last -do - local _item_0 = data.items - last = _item_0[#_item_0] -end -local second_last -do - local _item_0 = data.items - second_last = _item_0[#_item_0 - 1] -end -local _obj_0 = data.items -_obj_0[#_obj_0] = 1 -local mt = { } -local add -add = function(self, right) - return setmetatable({ - value = self.value + right.value - }, mt) -end -mt.__add = add -local a = setmetatable({ - value = 1 -}, mt) -local b = setmetatable({ - value = 2 -}, { - __add = add -}) -local c = setmetatable({ - value = 3 -}, { - __add = mt.__add -}) -local d = a + b + c -print(d.value) -local _ = setmetatable({ }, { - __close = function() - return print("out of scope") - end -}) -local tb = setmetatable({ }, { - ["value"] = 123 -}) -getmetatable(tb).__index = getmetatable(tb) -print(tb.value) -setmetatable(tb, { - __index = { - item = "hello" - } -}) -print(tb.item) -local item, new, close, getter -do - local _obj_0 = tb - item, new = _obj_0[1], _obj_0.new - do - local _obj_1 = getmetatable(_obj_0) - close, getter = _obj_1.__close, _obj_1.__index - end -end -print(item, new, close, getter) -do - local _obj_0 = func - if _obj_0 ~= nil then - _obj_0() - end -end -print((function() - local _obj_0 = abc - if _obj_0 ~= nil then - local _obj_1 = _obj_0["hello world"] - if _obj_1 ~= nil then - return _obj_1.xyz - end - return nil - end - return nil -end)()) -local x -do - local _obj_0 = tab - if _obj_0 ~= nil then - x = _obj_0.value - end -end -local len = (function() - local _obj_0 = utf8 - if _obj_0 ~= nil then - return _obj_0.len - end - return nil -end)() or (function() - local _obj_0 = string - if _obj_0 ~= nil then - return _obj_0.len - end - return nil -end)() or function(o) - return #o -end -if print and (x ~= nil) then - print(x) -end -local _with_0 = io.open("test.txt", "w") -if _with_0 ~= nil then - _with_0:write("hello") - _with_0:close() -end -print("hello") -print(1, 2) -print(1, 2, 3) -print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) -local a, b, c, d -if b ~= nil then - a = b -else - if c ~= nil then - a = c - else - a = d - end -end -func((function() - if a ~= nil then - return a - else - return { } - end -end)()) -if a == nil then - a = false -end -local list = { - 1, - 2, - 3 -} -func({ - 1, - 2, - 3 -}) -local f -f = function() - return { - 1, - 2, - 3 - } -end -local tb = { - name = "abc", - values = { - "a", - "b", - "c" - }, - objects = { - { - name = "a", - value = 1, - func = function(self) - return self.value + 1 - end, - tb = { - fieldA = 1 - } - }, - { - name = "b", - value = 2, - func = function(self) - return self.value + 2 - end, - tb = { } - } - } -} -do - local insert, concat = table.insert, table.concat - local C, Ct, Cmt - do - local _obj_0 = require("lpeg") - C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt - end - local x, y, z - do - local _obj_0 = require('mymodule') - x, y, z = _obj_0.x, _obj_0.y, _obj_0.z - end - local a, b, c - local _obj_0 = require('module') - a, b, c = _obj_0.a, _obj_0.b, _obj_0.c -end -do - local module = require('module') - local module_x = require('module_x') - local d_a_s_h_e_s = require("d-a-s-h-e-s") - local part = require("module.part") -end -do - local PlayerModule = require("player") - local C, Ct, Cmt - do - local _obj_0 = require("lpeg") - C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt - end - local one, two, ch - local _obj_0 = require("export") - one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] -end -do - local tostring = tostring - local concat = table.concat - print(concat({ - "a", - tostring(1) - })) -end -do - local print = print - local math = math - print("hello") - math.random(3) -end -do - local print = print - print(FLAG) - FLAG = 123 -end -local _module_0 = { } -local a, b, c = 1, 2, 3 -_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c -local cool = "cat" -_module_0["cool"] = cool -local What -if this then - What = "abc" -else - What = "def" -end -_module_0["What"] = What -local y -y = function() - local hallo = 3434 -end -_module_0["y"] = y -local Something -local _class_0 -local _base_0 = { - umm = "cool" -} -if _base_0.__index == nil then - _base_0.__index = _base_0 -end -_class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Something" -}, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end -}) -_base_0.__class = _class_0 -Something = _class_0 -_module_0["Something"] = Something -return _module_0 -local _module_0 = { } -local loadstring, tolua -do - local _obj_0 = yue - loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua -end -_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua -local fieldA = tb.itemA.fieldA -if fieldA == nil then - fieldA = 'default' -end -_module_0["fieldA"] = fieldA -return _module_0 -local _module_0 = setmetatable({ }, { }) -_module_0.itemA = tb -getmetatable(_module_0).__index = items -_module_0["a-b-c"] = 123 -return _module_0 -local _module_0 = { } -local d, e, f = 3, 2, 1 -_module_0[#_module_0 + 1] = d -_module_0[#_module_0 + 1] = e -_module_0[#_module_0 + 1] = f -if this then - _module_0[#_module_0 + 1] = 123 -else - _module_0[#_module_0 + 1] = 456 -end -local _with_0 = tmp -local j = 2000 -_module_0[#_module_0 + 1] = _with_0 -return _module_0 -local _module_0 = nil -_module_0 = function() - print("hello") - return 123 -end -return _module_0 -local hello = "world" -local a, b, c = 1, 2, 3 -hello = 123 -local x = 1 -x = x + 1 -x = x - 1 -x = x * 10 -x = x / 10 -x = x % 10 -local s = s .. "world" -local arg = arg or "default value" -local a = 0 -local b = 0 -local c = 0 -local d = 0 -local e = 0 -local x = f() -local y = x -local z = x -do - local a = 1 - local x, y, z - print("forward declare all variables as locals") - x = function() - return 1 + y + z - end - y, z = 2, 3 - instance = Item:new() -end -do - local X = 1 - local B - print("only forward declare upper case variables") - local a = 1 - B = 2 -end -do - a = 1 - print("declare all variables as globals") - x = function() - return 1 + y + z - end - y, z = 2, 3 -end -do - X = 1 - print("only declare upper case variables as globals") - local a = 1 - B = 2 - local Temp = "a local value" -end -local thing = { - 1, - 2 -} -local a, b = thing[1], thing[2] -print(a, b) -local obj = { - hello = "world", - day = "tuesday", - length = 20 -} -local hello, the_day = obj.hello, obj.day -print(hello, the_day) -local day = obj.day -local obj2 = { - numbers = { - 1, - 2, - 3, - 4 - }, - properties = { - color = "green", - height = 13.5 - } -} -local first, second = obj2.numbers[1], obj2.numbers[2] -print(first, second, color) -local first, second, color -local _obj_0 = obj2 -first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color -local concat, insert -local _obj_0 = table -concat, insert = _obj_0.concat, _obj_0.insert -local mix, max, rand -local _obj_0 = math -mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random -local name, job -local _obj_0 = person -name, job = _obj_0.name, _obj_0.job -if name == nil then - name = "nameless" -end -if job == nil then - job = "jobless" -end -local two, four -local _obj_0 = items -two, four = _obj_0[2], _obj_0[4] -local orders = { - "first", - "second", - "third", - "fourth", - "last" -} -local first, bulk, last = orders[1], (function() - local _accum_0 = { } - local _len_0 = 1 - local _max_0 = #orders + -2 + 1 - for _index_0 = 2, _max_0 do - local _item_0 = orders[_index_0] - _accum_0[_len_0] = _item_0 - _len_0 = _len_0 + 1 - end - return _accum_0 -end)(), orders[#orders] -print(first) -print(bulk) -print(last) -local first, rest -do - local _obj_0 = orders - first, rest = _obj_0[1], (function() - local _accum_0 = { } - local _len_0 = 1 - local _max_0 = #_obj_0 - for _index_0 = 2, _max_0 do - local _item_0 = _obj_0[_index_0] - _accum_0[_len_0] = _item_0 - _len_0 = _len_0 + 1 - end - return _accum_0 - end)() -end -local start, last -do - local _obj_0 = orders - start, last = (function() - local _accum_0 = { } - local _len_0 = 1 - local _max_0 = #_obj_0 + -2 + 1 - for _index_0 = 1, _max_0 do - local _item_0 = _obj_0[_index_0] - _accum_0[_len_0] = _item_0 - _len_0 = _len_0 + 1 - end - return _accum_0 - end)(), _obj_0[#_obj_0] -end -local _obj_0 = orders -first, last = _obj_0[1], _obj_0[#_obj_0] -local tuples = { - { - "hello", - "world" - }, - { - "egg", - "head" - } -} -for _index_0 = 1, #tuples do - local _des_0 = tuples[_index_0] - local left, right = _des_0[1], _des_0[2] - print(left, right) -end -local user = database.find_user("moon") -if user then - print(user.name) -end -local hello = os.getenv("hello") -if hello then - print("You have hello", hello) -else - local world = os.getenv("world") - if world then - print("you have world", world) - else - print("nothing :(") - end -end -do - local success, result = pcall(function() - return "get result without problems" - end) - if success then - print(result) - end -end -print("OK") -repeat - local byte = stream:read_one() - if byte then - print(byte) - else - break - end -until false -local list = { - 1, - 2, - 3, - 4, - 5 -} -local fn -fn = function(ok) - return ok, table.unpack(list) -end -(function(_arg_0, ...) - local ok = _arg_0 - local count = select('#', ...) - local first = select(1, ...) - return print(ok, count, first) -end)(fn(true)) -local a = 1 -local b = 2 -print(a + b) -Rx.Observable.fromRange(1, 8):filter(function(x) - return x % 2 == 0 -end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) - return value .. '!' -end):subscribe(print) -local str = strA .. strB .. strC -func(3000, "192.168.1.1") -xpcall(function() - return func(1, 2, 3) -end, function(err) - return print(yue.traceback(err)) -end) -local success, result = xpcall(function() - return func(1, 2, 3) -end, function(err) - return yue.traceback(err) -end) -xpcall(function() - return func(1, 2, 3) -end, function(err) - return print(yue.traceback(err)) -end) -success, result = pcall(function() - return func(1, 2, 3) -end) -pcall(function() - print("trying") - return func(1, 2, 3) -end) -success, result = xpcall(function() - return func(1, 2, 3) -end, function(err) - return print(yue.traceback(err)) -end) -if success then - print(result) -end -local a, b, c -do - local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() - return func() - end) - if _ok_0 then - a, b, c = _ret_0, _ret_1, _ret_2 - end -end -do - local _exp_0 = ((function() - return (function(_arg_0, ...) - local _ok_0 = _arg_0 - if _ok_0 then - return ... - end - end)(pcall(function() - return func() - end)) - end)()) - if _exp_0 ~= nil then - a = _exp_0 - else - a = "default" - end -end -f((function() - return (function(_arg_0, ...) - local _ok_0 = _arg_0 - if _ok_0 then - return ... - end - end)(pcall(function() - return func() - end)) -end)()) -f((function() - return (function(_arg_0, ...) - local _ok_0 = _arg_0 - if _ok_0 then - return ... - end - end)(xpcall(function() - print(123) - return func() - end, function(e) - print(e) - return e - end)) -end)()) -local a = 123 -local _ = setmetatable({ }, { - __close = function() - return print("Out of scope.") - end -}) -local a, b, c, d -local _obj_0 = tb -a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] -Constant = 123 -local some_string = "Here is a string\n that has a line break in it." -print("I am " .. tostring(math.random() * 100) .. "% sure.") -local integer = 1000000 -local hex = 0xEFBBBF -local binary = 19 -local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) -local fn -fn = function() - local str = "foo:\n bar: baz" - return str -end -local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" -local my_function -my_function = function() end -my_function() -local func_a -func_a = function() - return print("hello world") -end -local func_b -func_b = function() - local value = 100 - return print("The value:", value) -end -func_a() -func_b() -local sum -sum = function(x, y) - return print("sum", x + y) -end -sum(10, 20) -print(sum(10, 20)) -a(b(c("a", "b", "c"))) -print("x:", sum(10, 20), "y:", sum(30, 40)) -local sum -sum = function(x, y) - return x + y -end -print("The sum is ", sum(10, 20)) -local sum -sum = function(x, y) - return x + y -end -local mystery -mystery = function(x, y) - return x + y, x - y -end -local a, b = mystery(10, 20) -local func -func = function(self, num) - return self.value + num -end -local my_function -my_function = function(name, height) - if name == nil then - name = "something" - end - if height == nil then - height = 100 - end - print("Hello I am", name) - return print("My height is", height) -end -local some_args -some_args = function(x, y) - if x == nil then - x = 100 - end - if y == nil then - y = x + 1000 - end - return print(x + y) -end -local a = x - 10 -local b = x - 10 -local c = x(-y) -local d = x - z -local x = func("hello") + 100 -local y = func("hello" + 100) -my_func(5, 4, 3, 8, 9, 10) -cool_func(1, 2, 3, 4, 5, 6, 7, 8) -my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4) -local x = { - 1, - 2, - 3, - 4, - a_func(4, 5, 5, 6), - 8, - 9, - 10 -} -local y = { - my_func(1, 2, 3, 4, 5), - 5, - 6, - 7 -} -if func(1, 2, 3, "hello", "world") then - print("hello") - print("I am inside if") -end -if func(1, 2, 3, "hello", "world") then - print("hello") - print("I am inside if") -end -local f1 -f1 = function(_arg_0) - local a, b, c - a, b, c = _arg_0.a, _arg_0.b, _arg_0.c - return print(a, b, c) -end -f1({ - a = 1, - b = "2", - c = { } -}) -local f2 -f2 = function(_arg_0, c) - local a1, b - a1, b = _arg_0.a, _arg_0.b - if a1 == nil then - a1 = 123 - end - if b == nil then - b = 'abc' - end - if c == nil then - c = { } - end -end -print(a1, b, c) -local arg1 = { - a = 0 -} -f2(arg1, arg2) -local findFirstEven -findFirstEven = function(list) - for _index_0 = 1, #list do - local item = list[_index_0] - if type(item) == "table" then - for _index_1 = 1, #item do - local sub = item[_index_1] - if sub % 2 == 0 then - return sub - end - end - end - end - return nil -end -local findFirstEven -findFirstEven = function(list) - for _index_0 = 1, #list do - local item = list[_index_0] - if type(item) == "table" then - for _index_1 = 1, #item do - local sub = item[_index_1] - if sub % 2 == 0 then - return sub - end - end - end - 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) -f(function(self) - return print(self.value) -end) -map(function(x) - return x * 2 -end, { - 1, - 2, - 3 -}) -local result, msg -do - result, msg = readAsync("filename.txt", function(data) - print(data) - return processAsync(data, function(info) - return check(info) - end) - end) -end -print(result, msg) -local some_values = { - 1, - 2, - 3, - 4 -} -local some_values = { - name = "Bill", - age = 200, - ["favorite food"] = "rice" -} -local profile = { - height = "4 feet", - shoe_size = 13, - favorite_foods = { - "ice cream", - "donuts" - } -} -local values = { - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - name = "superman", - occupation = "crime fighting" -} -my_function({ - dance = "Tango", - partner = "none" -}) -local y = { - type = "dog", - legs = 4, - tails = 1 -} -local tbl = { - ["do"] = "something", - ["end"] = "hunger" -} -local hair = "golden" -local height = 200 -local person = { - hair = hair, - height = height, - shoe_size = 40 -} -print_table({ - hair = hair, - height = height -}) -local t = { - [1 + 2] = "hello", - ["hello world"] = true -} -local some_values = { - 1, - 2, - 3, - 4 -} -local list_with_one_element = { - 1 -} -local items = { - 1, - 2, - 3, - 4 -} -local doubled -local _accum_0 = { } -local _len_0 = 1 -for i, item in ipairs(items) do - _accum_0[_len_0] = item * 2 - _len_0 = _len_0 + 1 -end -doubled = _accum_0 -local slice -local _accum_0 = { } -local _len_0 = 1 -for i, item in ipairs(items) do - if i > 1 and i < 3 then - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end -end -slice = _accum_0 -local doubled -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -for _index_0 = 1, #_list_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item * 2 - _len_0 = _len_0 + 1 -end -doubled = _accum_0 -local data = { - a = { - 1, - 2, - 3 - }, - b = { - 4, - 5, - 6 - } -} -local flat -local _accum_0 = { } -for k, v in pairs(data) do - local _len_0 = #_accum_0 + 1 - for _index_0 = 1, #v do - local _elm_0 = v[_index_0] - _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1 - end -end -flat = _accum_0 -local x_coords = { - 4, - 5, - 6, - 7 -} -local y_coords = { - 9, - 2, - 3 -} -local points -local _accum_0 = { } -local _len_0 = 1 -for _index_0 = 1, #x_coords do - local x = x_coords[_index_0] - for _index_1 = 1, #y_coords do - local y = y_coords[_index_1] - _accum_0[_len_0] = { - x, - y - } - _len_0 = _len_0 + 1 - end -end -points = _accum_0 -local evens -local _accum_0 = { } -local _len_0 = 1 -for i = 1, 100 do - if i % 2 == 0 then - _accum_0[_len_0] = i - _len_0 = _len_0 + 1 - end -end -evens = _accum_0 -local thing = { - color = "red", - name = "fast", - width = 123 -} -local thing_copy -local _tbl_0 = { } -for k, v in pairs(thing) do - _tbl_0[k] = v -end -thing_copy = _tbl_0 -local no_color -local _tbl_0 = { } -for k, v in pairs(thing) do - if k ~= "color" then - _tbl_0[k] = v - end -end -no_color = _tbl_0 -local numbers = { - 1, - 2, - 3, - 4 -} -local sqrts -local _tbl_0 = { } -for _index_0 = 1, #numbers do - local i = numbers[_index_0] - _tbl_0[i] = math.sqrt(i) -end -sqrts = _tbl_0 -local tuples = { - { - "hello", - "world" - }, - { - "foo", - "bar" - } -} -local tbl -local _tbl_0 = { } -for _index_0 = 1, #tuples do - local tuple = tuples[_index_0] - local _key_0, _val_0 = unpack(tuple) - _tbl_0[_key_0] = _val_0 -end -tbl = _tbl_0 -local slice -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -for _index_0 = 1, 5 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 -end -slice = _accum_0 -local slice -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -local _max_0 = #_list_0 -for _index_0 = 2, _max_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 -end -slice = _accum_0 -local slice -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -local _max_0 = #_list_0 -for _index_0 = 1, _max_0, 2 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 -end -slice = _accum_0 -local slice -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -local _min_0 = #_list_0 + -4 + 1 -local _max_0 = #_list_0 + -1 + 1 -for _index_0 = _min_0, _max_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 -end -slice = _accum_0 -local reverse_slice -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -local _min_0 = #_list_0 + -1 + 1 -for _index_0 = _min_0, 1, -1 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 -end -reverse_slice = _accum_0 -local sub_list -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -for _index_0 = 2, 4 do - local _item_0 = _list_0[_index_0] - _accum_0[_len_0] = _item_0 - _len_0 = _len_0 + 1 -end -sub_list = _accum_0 -for i = 10, 20 do - print(i) -end -for k = 1, 15, 2 do - print(k) -end -for key, value in pairs(object) do - print(key, value) -end -local _list_0 = items -for _index_0 = 2, 4 do - local item = _list_0[_index_0] - print(item) -end -local _list_0 = items -for _index_0 = 1, #_list_0 do - local item = _list_0[_index_0] - print(item) -end -for j = 1, 10, 3 do - print(j) -end -local doubled_evens -local _accum_0 = { } -local _len_0 = 1 -for i = 1, 20 do - if i % 2 == 0 then - _accum_0[_len_0] = i * 2 - _len_0 = _len_0 + 1 - else - _accum_0[_len_0] = i - _len_0 = _len_0 + 1 - end -end -doubled_evens = _accum_0 -local first_large -local _accum_0 -local _list_0 = numbers -for _index_0 = 1, #_list_0 do - local n = _list_0[_index_0] - if n > 10 then - _accum_0 = n - break - end -end -first_large = _accum_0 -local func_a -func_a = function() - for i = 1, 10 do - print(i) - end -end -local func_b -func_b = function() - local _accum_0 = { } - local _len_0 = 1 - for i = 1, 10 do - _accum_0[_len_0] = i - _len_0 = _len_0 + 1 - end - return _accum_0 -end -print(func_a()) -print(func_b()) -local i = 10 -repeat - print(i) - i = i - 1 -until i == 0 -local i = 10 -while i > 0 do - print(i) - i = i - 1 -end -while running == true do - my_function() -end -local i = 10 -while not (i == 0) do - print(i) - i = i - 1 -end -while not (running == false) do - my_function() -end -local i = 0 -while i < 10 do - i = i + 1 - if i % 2 == 0 then - goto _continue_0 - end - print(i) - ::_continue_0:: -end -local my_numbers = { - 1, - 2, - 3, - 4, - 5, - 6 -} -local odds -local _accum_0 = { } -local _len_0 = 1 -for _index_0 = 1, #my_numbers do - local x = my_numbers[_index_0] - if x % 2 == 1 then - goto _continue_0 - end - _accum_0[_len_0] = x - _len_0 = _len_0 + 1 - ::_continue_0:: -end -odds = _accum_0 -local have_coins = false -if have_coins then - print("Got coins") -else - print("No coins") -end -local have_coins = false -if have_coins then - print("Got coins") -else - print("No coins") -end -local have_coins = false -print((function() - if have_coins then - return "Got coins" - else - return "No coins" - end -end)()) -local is_tall -is_tall = function(name) - if name == "Rob" then - return true - else - return false - end -end -local message -if is_tall("Rob") then - message = "I am very tall" -else - message = "I am not so tall" -end -print(message) -if not (os.date("%A") == "Monday") then - print("it is not Monday!") -end -if not (math.random() > 0.1) then - print("You're lucky!") -end -local a = 5 -if (1 == a or 3 == a or 5 == a or 7 == a) then - print("checking equality with discrete values") -end -if (function() - local _check_0 = list - for _index_0 = 1, #_check_0 do - if _check_0[_index_0] == a then - return true - end - end - return false -end)() then - print("checking if `a` is in a list") -end -if not (math.random() > 0.1) then - print("You're lucky!") -end -if name == "Rob" then - print("hello world") -end -local _list_0 = items -for _index_0 = 1, #_list_0 do - local item = _list_0[_index_0] - print("item: ", item) -end -while game:isRunning() do - game:update() -end -while not reader:eof() do - reader:parse_line() -end -local name = "Dan" -if "Robert" == name then - print("You are Robert") -elseif "Dan" == name or "Daniel" == name then - print("Your name, it's Dan") -else - print("I don't know about you with name " .. tostring(name)) -end -local b = 1 -local next_number -if 1 == b then - next_number = 2 -elseif 2 == b then - next_number = 3 -else - next_number = error("can't count that high!") -end -local msg -local _exp_0 = math.random(1, 5) -if 1 == _exp_0 then - msg = "you are lucky" -elseif 2 == _exp_0 then - msg = "you are almost lucky" -else - msg = "not so lucky" -end -do - local _exp_0 = math.random(1, 5) - if 1 == _exp_0 then - print("you are lucky") - else - print("not so lucky") - end -end -local _exp_0 = math.random(1, 5) -if 1 == _exp_0 then - print("you are lucky") -else - print("not so lucky") -end -local items = { - { - x = 100, - y = 200 - }, - { - width = 300, - height = 400 - } -} -for _index_0 = 1, #items do - local item = items[_index_0] - local _type_0 = type(item) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false - if _tab_0 then - local x = item.x - local y = item.y - if x ~= nil and y ~= nil then - _match_0 = true - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) - end - end - if not _match_0 then - if _tab_0 then - local width = item.width - local height = item.height - if width ~= nil and height ~= nil then - print("size " .. tostring(width) .. ", " .. tostring(height)) - end - end - end -end -local item = { } -local x, y = item.pos.x, item.pos.y -if x == nil then - x = 50 -end -if y == nil then - y = 200 -end -local _type_0 = type(item) -local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -if _tab_0 then - do - local _obj_0 = item.pos - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - x = _obj_0.x - end - end - do - local _obj_0 = item.pos - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - y = _obj_0.y - end - end - if x == nil then - x = 50 - end - if y == nil then - y = 200 - end - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) -end -local _exp_0 = tb -local _type_0 = type(_exp_0) -local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -local _match_0 = false -if _tab_0 then - if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then - _match_0 = true - print("1, 2, 3") - end -end -if not _match_0 then - local _match_1 = false - if _tab_0 then - local b = _exp_0[2] - if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then - _match_1 = true - print("1, " .. tostring(b) .. ", 3") - end - end - if not _match_1 then - if _tab_0 then - local b = _exp_0[3] - if b == nil then - b = 3 - end - if 1 == _exp_0[1] and 2 == _exp_0[2] then - print("1, 2, " .. tostring(b)) - end - end - end -end -local _exp_0 = tb -local _type_0 = type(_exp_0) -local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -local _match_0 = false -if _tab_0 then - local result = _exp_0.result - if true == _exp_0.success and result ~= nil then - _match_0 = true - print("success", result) - end -end -if not _match_0 then - local _match_1 = false - if _tab_0 then - if false == _exp_0.success then - _match_1 = true - print("failed", result) - end - end - if not _match_1 then - print("invalid") - end -end -local _exp_0 = tb -local _type_0 = type(_exp_0) -local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -local _match_0 = false -if _tab_0 then - local content - do - local _obj_0 = _exp_0.data - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - content = _obj_0.content - end - end - local _val_0 - do - local _obj_0 = _exp_0.data - if _obj_0 ~= nil then - _val_0 = _obj_0.type - end - end - if "success" == _val_0 and content ~= nil then - _match_0 = true - print("success", content) - end -end -if not _match_0 then - local _match_1 = false - if _tab_0 then - local content - do - local _obj_0 = _exp_0.data - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - content = _obj_0.content - end - end - local _val_0 - do - local _obj_0 = _exp_0.data - if _obj_0 ~= nil then - _val_0 = _obj_0.type - end - end - if "error" == _val_0 and content ~= nil then - _match_1 = true - print("failed", content) - end - end - if not _match_1 then - print("invalid") - end -end -local _exp_0 = tb -local _type_0 = type(_exp_0) -local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -if _tab_0 then - local fourth = _exp_0[4] - local _val_0 - do - local _obj_0 = _exp_0[1] - if _obj_0 ~= nil then - _val_0 = _obj_0.a - end - end - local _val_1 - do - local _obj_0 = _exp_0[1] - if _obj_0 ~= nil then - _val_1 = _obj_0.b - end - end - local _val_2 - do - local _obj_0 = _exp_0[2] - if _obj_0 ~= nil then - _val_2 = _obj_0.a + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end + }) + _base_0.__class = _class_0 + if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) end - local _val_3 - do - local _obj_0 = _exp_0[2] - if _obj_0 ~= nil then - _val_3 = _obj_0.b - end + BigBucket = _class_0 +end +assert(Bucket.__name == "BigBucket") +local x +local _class_0 +local _base_0 = { } +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "x" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - local _val_4 - do - local _obj_0 = _exp_0[3] - if _obj_0 ~= nil then - _val_4 = _obj_0.a +}) +_base_0.__class = _class_0 +x = _class_0 +local MyIndex = { + __index = { + var = 1 + } +} +local X +do + local _class_0 + local _base_0 = { + func = function(self) + return print(123) end - end - local _val_5 - do - local _obj_0 = _exp_0[3] - if _obj_0 ~= nil then - _val_5 = _obj_0.b + } + local _list_0 = { + MyIndex + } + for _index_0 = 1, #_list_0 do + local _item_0 = _list_0[_index_0] + local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0 + for _key_0, _val_0 in pairs(_mixin_0) do + if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then + _base_0[_key_0] = _val_0 + end end end - if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then - print("matched", fourth) + if _base_0.__index == nil then + _base_0.__index = _base_0 end + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "X" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_0.__class = _class_0 + X = _class_0 end -local segments = { - "admin", - "users", - "logs", - "view" -} -local _type_0 = type(segments) -local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -if _tab_0 then - local groups - do - local _accum_0 = { } - local _len_0 = 1 - local _max_0 = #segments + -3 + 1 - for _index_0 = 1, _max_0 do - local _item_0 = segments[_index_0] - _accum_0[_len_0] = _item_0 - _len_0 = _len_0 + 1 +local x = X() +print(x.var) +local Y +do + local _class_0 + local _base_0 = { } + local _list_0 = { + X + } + for _index_0 = 1, #_list_0 do + local _item_0 = _list_0[_index_0] + local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0 + for _key_0, _val_0 in pairs(_mixin_0) do + if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then + _base_0[_key_0] = _val_0 + end end - groups = _accum_0 end - local resource = segments[#segments - 1] - local action = segments[#segments] - if resource ~= nil and action ~= nil then - print("Group:", groups) - print("Resource:", resource) - print("Action:", action) + if _base_0.__index == nil then + _base_0.__index = _base_0 end + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Y" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_0.__class = _class_0 + Y = _class_0 end +local y = Y() +y:func() +assert(y.__class.__parent ~= X) local Inventory local _class_0 local _base_0 = { @@ -5050,6 +4970,67 @@ local _with_0 = obj if _with_0 ~= nil then print(obj.name) end +local _with_0 = Person() +_with_0.name = "Oswald" +_with_0:add_relative(my_dad) +_with_0:save() +print(_with_0.name) +local file +local _with_0 = File("favorite_foods.txt") +_with_0:set_encoding("utf8") +file = _with_0 +local create_person +create_person = function(name, relatives) + local _with_0 = Person() + _with_0.name = name + for _index_0 = 1, #relatives do + local relative = relatives[_index_0] + _with_0:add_relative(relative) + end + return _with_0 +end +local me = create_person("Leaf", { + dad, + mother, + sister +}) +local str = "Hello" +print("original:", str) +print("upper:", str:upper()) +local _with_0 = tb +_with_0[1] = 1 +print(_with_0[2]) +do + local _with_1 = _with_0[abc] + _with_1[3] = _with_1[2]:func() + _with_1["key-name"] = value +end +_with_0[#_with_0 + 1] = "abc" +local _with_0 = obj +if _with_0 ~= nil then + print(obj.name) +end +do + local var = "hello" + print(var) +end +print(var) +local counter +do + local i = 0 + counter = function() + i = i + 1 + return i + end +end +print(counter()) +print(counter()) +local tbl = { + key = (function() + print("assigning key!") + return 1234 + end)() +} do local var = "hello" print(var) @@ -5090,6 +5071,53 @@ run_callback((function() return _fn_0(_base_0, ...) end end)()) +local my_object = { + value = 1000, + write = function(self) + return print("the value:", self.value) + end +} +local run_callback +run_callback = function(func) + print("running callback...") + return func() +end +run_callback(my_object.write) +run_callback((function() + local _base_0 = my_object + local _fn_0 = _base_0.write + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end +end)()) +local i = 100 +local my_func +my_func = function() + i = 10 + while i > 0 do + print(i) + i = i - 1 + end +end +my_func() +print(i) +local i = 100 +local my_func +my_func = function() + local i = "hello" +end +my_func() +print(i) +local tmp = 1213 +local i, k = 100, 50 +local my_func +my_func = function(add) + local tmp = tmp + add + i = i + tmp + k = k + tmp +end +my_func(22) +print(i, k) local i = 100 local my_func my_func = function() diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index 2aa354e..f4ef2c7 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua @@ -76,6 +76,123 @@ end local _u1f31b = "月之脚本" _module_0["🌛"] = _u1f31b return _module_0 +local _module_0 = { } +local p, to_lua +do + local _obj_0 = require("yue") + p, to_lua = _obj_0.p, _obj_0.to_lua +end +local inventory = { + equipment = { + "sword", + "shield" + }, + items = { + { + name = "potion", + count = 10 + }, + { + name = "bread", + count = 3 + } + } +} +local map +map = function(arr, action) + local _accum_0 = { } + local _len_0 = 1 + for _index_0 = 1, #arr do + local item = arr[_index_0] + _accum_0[_len_0] = action(item) + _len_0 = _len_0 + 1 + end + return _accum_0 +end +local filter +filter = function(arr, cond) + local _accum_0 = { } + local _len_0 = 1 + for _index_0 = 1, #arr do + local item = arr[_index_0] + if cond(item) then + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 + end + end + return _accum_0 +end +local reduce +reduce = function(arr, init, action) + for _index_0 = 1, #arr do + local item = arr[_index_0] + init = action(init, item) + end + return init +end +print(reduce(filter(map({ + 1, + 2, + 3 +}, function(x) + return x * 2 +end), function(x) + return x > 4 +end), 0, function(a, b) + return a + b +end)) +local apple = setmetatable({ + size = 15, +}, { + __index = { + color = 0x00ffff + } +}) +if (getmetatable(apple) ~= nil) then + p(apple.size, apple.color, getmetatable(apple).__index) +end +local _u1f31b = "月之脚本" +_module_0["🌛"] = _u1f31b +return _module_0 +local area = 6.2831853071796 * 5 +print('你好 世界') +do + assert(item ~= nil) +end +local value = item +if (f1() and f2() and f3()) then + print("OK") +end +do + local funcA + funcA = function() end +end +local funcA +funcA = function() + return "无法访问宏生成月之脚本里定义的变量" +end +do +local function funcB() end +end +local funcB +funcB = function() + return "无法访问宏生成 Lua 代码里定义的变量" +end +do +-- 插入原始Lua代码 +if cond then + print("输出") +end +end +print("yuescript") +print(2) +print("有效的枚举类型:", "Static") +do + print(123, "hello") +end +do + print(123, "hello") +end local area = 6.2831853071796 * 5 print('你好 世界') do @@ -408,46 +525,339 @@ local tb = { } } } -do - local insert, concat = table.insert, table.concat - local C, Ct, Cmt - do - local _obj_0 = require("lpeg") - C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt +if tb ~= nil then + tb:func() +end +if tb ~= nil then + tb:func() +end +print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5) +local a = 5 +print(1 <= a and a <= 10) +local v +v = function(x) + print(x) + return x +end +print((function() + local _cond_0 = v(2) + if not (v(1) < _cond_0) then + return false + else + return _cond_0 <= v(3) end - local x, y, z - do - local _obj_0 = require('mymodule') - x, y, z = _obj_0.x, _obj_0.y, _obj_0.z +end)()) +print((function() + local _cond_0 = v(2) + if not (v(1) > _cond_0) then + return false + else + return _cond_0 <= v(3) end - local a, b, c - local _obj_0 = require('module') - a, b, c = _obj_0.a, _obj_0.b, _obj_0.c +end)()) +local tab = { } +tab[#tab + 1] = "Value" +local tbA = { + 1, + 2, + 3 +} +local tbB = { + 4, + 5, + 6 +} +local _len_0 = #tbA + 1 +for _index_0 = 1, #tbB do + local _elm_0 = tbB[_index_0] + tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 end +local parts = { + "shoulders", + "knees" +} +local lyrics do - local module = require('module') - local module_x = require('module_x') - local d_a_s_h_e_s = require("d-a-s-h-e-s") - local part = require("module.part") + local _tab_0 = { + "head" + } + local _idx_0 = 1 + for _key_0, _value_0 in pairs(parts) do + if _idx_0 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_0 = _idx_0 + 1 + else + _tab_0[_key_0] = _value_0 + end + end + _tab_0[#_tab_0 + 1] = "and" + _tab_0[#_tab_0 + 1] = "toes" + lyrics = _tab_0 end +local copy do - local PlayerModule = require("player") - local C, Ct, Cmt - do - local _obj_0 = require("lpeg") - C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt + local _tab_0 = { } + local _idx_0 = 1 + for _key_0, _value_0 in pairs(other) do + if _idx_0 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_0 = _idx_0 + 1 + else + _tab_0[_key_0] = _value_0 + end end - local one, two, ch - local _obj_0 = require("export") - one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] + copy = _tab_0 end -do - local tostring = tostring - local concat = table.concat - print(concat({ - "a", - tostring(1) - })) +local a = { + 1, + 2, + 3, + x = 1 +} +local b = { + 4, + 5, + y = 1 +} +local merge +local _tab_0 = { } +local _idx_0 = 1 +for _key_0, _value_0 in pairs(a) do + if _idx_0 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_0 = _idx_0 + 1 + else + _tab_0[_key_0] = _value_0 + end +end +local _idx_1 = 1 +for _key_0, _value_0 in pairs(b) do + if _idx_1 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_1 = _idx_1 + 1 + else + _tab_0[_key_0] = _value_0 + end +end +merge = _tab_0 +local last +do + local _item_0 = data.items + last = _item_0[#_item_0] +end +local second_last +do + local _item_0 = data.items + second_last = _item_0[#_item_0 - 1] +end +local _obj_0 = data.items +_obj_0[#_obj_0] = 1 +local mt = { } +local add +add = function(self, right) + return setmetatable({ + value = self.value + right.value + }, mt) +end +mt.__add = add +local a = setmetatable({ + value = 1 +}, mt) +local b = setmetatable({ + value = 2 +}, { + __add = add +}) +local c = setmetatable({ + value = 3 +}, { + __add = mt.__add +}) +local d = a + b + c +print(d.value) +local _ = setmetatable({ }, { + __close = function() + return print("超出范围") + end +}) +local tb = setmetatable({ }, { + ["value"] = 123 +}) +getmetatable(tb).__index = getmetatable(tb) +print(tb.value) +setmetatable(tb, { + __index = { + item = "hello" + } +}) +print(tb.item) +local item, new, close, getter +do + local _obj_0 = tb + item, new = _obj_0[1], _obj_0.new + do + local _obj_1 = getmetatable(_obj_0) + close, getter = _obj_1.__close, _obj_1.__index + end +end +print(item, new, close, getter) +do + local _obj_0 = func + if _obj_0 ~= nil then + _obj_0() + end +end +print((function() + local _obj_0 = abc + if _obj_0 ~= nil then + local _obj_1 = _obj_0["你好 世界"] + if _obj_1 ~= nil then + return _obj_1.xyz + end + return nil + end + return nil +end)()) +local x +do + local _obj_0 = tab + if _obj_0 ~= nil then + x = _obj_0.value + end +end +local len = (function() + local _obj_0 = utf8 + if _obj_0 ~= nil then + return _obj_0.len + end + return nil +end)() or (function() + local _obj_0 = string + if _obj_0 ~= nil then + return _obj_0.len + end + return nil +end)() or function(o) + return #o +end +if print and (x ~= nil) then + print(x) +end +local _with_0 = io.open("test.txt", "w") +if _with_0 ~= nil then + _with_0:write("你好") + _with_0:close() +end +print("你好") +print(1, 2) +print(1, 2, 3) +print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) +local a, b, c, d +if b ~= nil then + a = b +else + if c ~= nil then + a = c + else + a = d + end +end +func((function() + if a ~= nil then + return a + else + return { } + end +end)()) +if a == nil then + a = false +end +local list = { + 1, + 2, + 3 +} +func({ + 1, + 2, + 3 +}) +local f +f = function() + return { + 1, + 2, + 3 + } +end +local tb = { + name = "abc", + values = { + "a", + "b", + "c" + }, + objects = { + { + name = "a", + value = 1, + func = function(self) + return self.value + 1 + end, + tb = { + fieldA = 1 + } + }, + { + name = "b", + value = 2, + func = function(self) + return self.value + 2 + end, + tb = { } + } + } +} +do + local insert, concat = table.insert, table.concat + local C, Ct, Cmt + do + local _obj_0 = require("lpeg") + C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt + end + local x, y, z + do + local _obj_0 = require('mymodule') + x, y, z = _obj_0.x, _obj_0.y, _obj_0.z + end + local a, b, c + local _obj_0 = require('module') + a, b, c = _obj_0.a, _obj_0.b, _obj_0.c +end +do + local module = require('module') + local module_x = require('module_x') + local d_a_s_h_e_s = require("d-a-s-h-e-s") + local part = require("module.part") +end +do + local PlayerModule = require("player") + local C, Ct, Cmt + do + local _obj_0 = require("lpeg") + C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt + end + local one, two, ch + local _obj_0 = require("export") + one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] +end +do + local tostring = tostring + local concat = table.concat + print(concat({ + "a", + tostring(1) + })) end do local print = print @@ -539,37 +949,219 @@ _module_0 = function() return 123 end return _module_0 -local hello = "world" -local a, b, c = 1, 2, 3 -hello = 123 -local x = 1 -x = x + 1 -x = x - 1 -x = x * 10 -x = x / 10 -x = x % 10 -local s = s .. "world" -local arg = arg or "默认值" -local a = 0 -local b = 0 -local c = 0 -local d = 0 -local e = 0 -local x = f() -local y = x -local z = x do - local a = 1 + local insert, concat = table.insert, table.concat + local C, Ct, Cmt + do + local _obj_0 = require("lpeg") + C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt + end local x, y, z - print("预先声明后续所有变量为局部变量") - x = function() - return 1 + y + z + do + local _obj_0 = require('mymodule') + x, y, z = _obj_0.x, _obj_0.y, _obj_0.z end - y, z = 2, 3 - instance = Item:new() + local a, b, c + local _obj_0 = require('module') + a, b, c = _obj_0.a, _obj_0.b, _obj_0.c end do - local X = 1 + local module = require('module') + local module_x = require('module_x') + local d_a_s_h_e_s = require("d-a-s-h-e-s") + local part = require("module.part") +end +do + local PlayerModule = require("player") + local C, Ct, Cmt + do + local _obj_0 = require("lpeg") + C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt + end + local one, two, ch + local _obj_0 = require("export") + one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] +end +do + local tostring = tostring + local concat = table.concat + print(concat({ + "a", + tostring(1) + })) +end +do + local print = print + local math = math + print("hello") + math.random(3) +end +do + local print = print + print(FLAG) + FLAG = 123 +end +local _module_0 = { } +local a, b, c = 1, 2, 3 +_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c +local cool = "cat" +_module_0["cool"] = cool +local What +if this then + What = "abc" +else + What = "def" +end +_module_0["What"] = What +local y +y = function() + local hallo = 3434 +end +_module_0["y"] = y +local Something +local _class_0 +local _base_0 = { + umm = "cool" +} +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Something" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end +}) +_base_0.__class = _class_0 +Something = _class_0 +_module_0["Something"] = Something +return _module_0 +local _module_0 = { } +local loadstring, tolua +do + local _obj_0 = yue + loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua +end +_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua +local fieldA = tb.itemA.fieldA +if fieldA == nil then + fieldA = '默认值' +end +_module_0["fieldA"] = fieldA +return _module_0 +local _module_0 = setmetatable({ }, { }) +_module_0.itemA = tb +getmetatable(_module_0).__index = items +_module_0["a-b-c"] = 123 +return _module_0 +local _module_0 = { } +local d, e, f = 3, 2, 1 +_module_0[#_module_0 + 1] = d +_module_0[#_module_0 + 1] = e +_module_0[#_module_0 + 1] = f +if this then + _module_0[#_module_0 + 1] = 123 +else + _module_0[#_module_0 + 1] = 456 +end +local _with_0 = tmp +local j = 2000 +_module_0[#_module_0 + 1] = _with_0 +return _module_0 +local _module_0 = nil +_module_0 = function() + print("你好") + return 123 +end +return _module_0 +local hello = "world" +local a, b, c = 1, 2, 3 +hello = 123 +local x = 1 +x = x + 1 +x = x - 1 +x = x * 10 +x = x / 10 +x = x % 10 +local s = s .. "world" +local arg = arg or "默认值" +local a = 0 +local b = 0 +local c = 0 +local d = 0 +local e = 0 +local x = f() +local y = x +local z = x +do + local a = 1 + local x, y, z + print("预先声明后续所有变量为局部变量") + x = function() + return 1 + y + z + end + y, z = 2, 3 + instance = Item:new() +end +do + local X = 1 + local B + print("只预先声明后续大写的变量为局部变量") + local a = 1 + B = 2 +end +do + a = 1 + print("预先声明所有变量为全局变量") + x = function() + return 1 + y + z + end + y, z = 2, 3 +end +do + x = 1 + print("只预先声明大写的变量为全局变量") + local a = 1 + B = 2 + local Temp = "一个局部值" +end +local hello = "world" +local a, b, c = 1, 2, 3 +hello = 123 +local x = 1 +x = x + 1 +x = x - 1 +x = x * 10 +x = x / 10 +x = x % 10 +local s = s .. "world" +local arg = arg or "默认值" +local a = 0 +local b = 0 +local c = 0 +local d = 0 +local e = 0 +local x = f() +local y = x +local z = x +do + local a = 1 + local x, y, z + print("预先声明后续所有变量为局部变量") + x = function() + return 1 + y + z + end + y, z = 2, 3 + instance = Item:new() +end +do + local X = 1 local B print("只预先声明后续大写的变量为局部变量") local a = 1 @@ -707,66 +1299,242 @@ for _index_0 = 1, #tuples do local left, right = _des_0[1], _des_0[2] print(left, right) end -local user = database.find_user("moon") -if user then - print(user.name) -end -local hello = os.getenv("hello") -if hello then - print("你有 hello", hello) -else - local world = os.getenv("world") - if world then - print("你有 world", world) - else - print("什么都没有 :(") - end -end -do - local success, result = pcall(function() - return "无报错地获取结果" - end) - if success then - print(result) - end -end -print("好的") -repeat - local byte = stream:read_one() - if byte then - print(byte) - else - break - end -until false -local list = { +local thing = { 1, - 2, - 3, - 4, - 5 + 2 } -local fn -fn = function(ok) - return ok, table.unpack(list) -end -(function(_arg_0, ...) - local ok = _arg_0 - local count = select('#', ...) - local first = select(1, ...) - return print(ok, count, first) -end)(fn(true)) -local a = 1 -local b = 2 -print(a + b) -Rx.Observable.fromRange(1, 8):filter(function(x) - return x % 2 == 0 -end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) - return value .. '!' -end):subscribe(print) -local str = strA .. strB .. strC -func(3000, "192.168.1.1") -xpcall(function() +local a, b = thing[1], thing[2] +print(a, b) +local obj = { + hello = "world", + day = "tuesday", + length = 20 +} +local hello, the_day = obj.hello, obj.day +print(hello, the_day) +local day = obj.day +local obj2 = { + numbers = { + 1, + 2, + 3, + 4 + }, + properties = { + color = "green", + height = 13.5 + } +} +local first, second = obj2.numbers[1], obj2.numbers[2] +print(first, second, color) +local first, second, color +local _obj_0 = obj2 +first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color +local concat, insert +local _obj_0 = table +concat, insert = _obj_0.concat, _obj_0.insert +local mix, max, rand +local _obj_0 = math +mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random +local name, job +local _obj_0 = person +name, job = _obj_0.name, _obj_0.job +if name == nil then + name = "nameless" +end +if job == nil then + job = "jobless" +end +local two, four +local _obj_0 = items +two, four = _obj_0[2], _obj_0[4] +local orders = { + "first", + "second", + "third", + "fourth", + "last" +} +local first, bulk, last = orders[1], (function() + local _accum_0 = { } + local _len_0 = 1 + local _max_0 = #orders + -2 + 1 + for _index_0 = 2, _max_0 do + local _item_0 = orders[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 + end + return _accum_0 +end)(), orders[#orders] +print(first) +print(bulk) +print(last) +local first, rest +do + local _obj_0 = orders + first, rest = _obj_0[1], (function() + local _accum_0 = { } + local _len_0 = 1 + local _max_0 = #_obj_0 + for _index_0 = 2, _max_0 do + local _item_0 = _obj_0[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 + end + return _accum_0 + end)() +end +local start, last +do + local _obj_0 = orders + start, last = (function() + local _accum_0 = { } + local _len_0 = 1 + local _max_0 = #_obj_0 + -2 + 1 + for _index_0 = 1, _max_0 do + local _item_0 = _obj_0[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 + end + return _accum_0 + end)(), _obj_0[#_obj_0] +end +local _obj_0 = orders +first, last = _obj_0[1], _obj_0[#_obj_0] +local tuples = { + { + "hello", + "world" + }, + { + "egg", + "head" + } +} +for _index_0 = 1, #tuples do + local _des_0 = tuples[_index_0] + local left, right = _des_0[1], _des_0[2] + print(left, right) +end +local user = database.find_user("moon") +if user then + print(user.name) +end +local hello = os.getenv("hello") +if hello then + print("你有 hello", hello) +else + local world = os.getenv("world") + if world then + print("你有 world", world) + else + print("什么都没有 :(") + end +end +do + local success, result = pcall(function() + return "无报错地获取结果" + end) + if success then + print(result) + end +end +print("好的") +repeat + local byte = stream:read_one() + if byte then + print(byte) + else + break + end +until false +local user = database.find_user("moon") +if user then + print(user.name) +end +local hello = os.getenv("hello") +if hello then + print("你有 hello", hello) +else + local world = os.getenv("world") + if world then + print("你有 world", world) + else + print("什么都没有 :(") + end +end +do + local success, result = pcall(function() + return "无报错地获取结果" + end) + if success then + print(result) + end +end +print("好的") +repeat + local byte = stream:read_one() + if byte then + print(byte) + else + break + end +until false +local list = { + 1, + 2, + 3, + 4, + 5 +} +local fn +fn = function(ok) + return ok, table.unpack(list) +end +(function(_arg_0, ...) + local ok = _arg_0 + local count = select('#', ...) + local first = select(1, ...) + return print(ok, count, first) +end)(fn(true)) +local list = { + 1, + 2, + 3, + 4, + 5 +} +local fn +fn = function(ok) + return ok, table.unpack(list) +end +(function(_arg_0, ...) + local ok = _arg_0 + local count = select('#', ...) + local first = select(1, ...) + return print(ok, count, first) +end)(fn(true)) +local a = 1 +local b = 2 +print(a + b) +Rx.Observable.fromRange(1, 8):filter(function(x) + return x % 2 == 0 +end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) + return value .. '!' +end):subscribe(print) +local a = 1 +local b = 2 +print(a + b) +Rx.Observable.fromRange(1, 8):filter(function(x) + return x % 2 == 0 +end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) + return value .. '!' +end):subscribe(print) +local str = strA .. strB .. strC +func(3000, "192.168.1.1") +local str = strA .. strB .. strC +func(3000, "192.168.1.1") +xpcall(function() return func(1, 2, 3) end, function(err) return print(yue.traceback(err)) @@ -846,30 +1614,132 @@ f((function() return e end)) end)()) -local a = 123 -local _ = setmetatable({ }, { - __close = function() - return print("超出范围。") - end -}) -local a, b, c, d -local _obj_0 = tb -a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] -Constant = 123 -local some_string = "这是一个字符串\n 并包括一个换行。" -print("我有" .. tostring(math.random() * 100) .. "%的把握。") -local integer = 1000000 -local hex = 0xEFBBBF -local binary = 19 -local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) -local fn -fn = function() - local str = "foo:\n bar: baz" - return str -end -local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" -local my_function -my_function = function() end +xpcall(function() + return func(1, 2, 3) +end, function(err) + return print(yue.traceback(err)) +end) +local success, result = xpcall(function() + return func(1, 2, 3) +end, function(err) + return yue.traceback(err) +end) +xpcall(function() + return func(1, 2, 3) +end, function(err) + return print(yue.traceback(err)) +end) +success, result = pcall(function() + return func(1, 2, 3) +end) +pcall(function() + print("尝试中") + return func(1, 2, 3) +end) +success, result = xpcall(function() + return func(1, 2, 3) +end, function(err) + return print(yue.traceback(err)) +end) +if success then + print(result) +end +local a, b, c +do + local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() + return func() + end) + if _ok_0 then + a, b, c = _ret_0, _ret_1, _ret_2 + end +end +do + local _exp_0 = ((function() + return (function(_arg_0, ...) + local _ok_0 = _arg_0 + if _ok_0 then + return ... + end + end)(pcall(function() + return func() + end)) + end)()) + if _exp_0 ~= nil then + a = _exp_0 + else + a = "default" + end +end +f((function() + return (function(_arg_0, ...) + local _ok_0 = _arg_0 + if _ok_0 then + return ... + end + end)(pcall(function() + return func() + end)) +end)()) +f((function() + return (function(_arg_0, ...) + local _ok_0 = _arg_0 + if _ok_0 then + return ... + end + end)(xpcall(function() + print(123) + return func() + end, function(e) + print(e) + return e + end)) +end)()) +local a = 123 +local _ = setmetatable({ }, { + __close = function() + return print("超出范围。") + end +}) +local a, b, c, d +local _obj_0 = tb +a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] +Constant = 123 +local a = 123 +local _ = setmetatable({ }, { + __close = function() + return print("超出范围。") + end +}) +local a, b, c, d +local _obj_0 = tb +a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] +Constant = 123 +local some_string = "这是一个字符串\n 并包括一个换行。" +print("我有" .. tostring(math.random() * 100) .. "%的把握。") +local integer = 1000000 +local hex = 0xEFBBBF +local binary = 19 +local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) +local fn +fn = function() + local str = "foo:\n bar: baz" + return str +end +local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" +local some_string = "这是一个字符串\n 并包括一个换行。" +print("我有" .. tostring(math.random() * 100) .. "%的把握。") +local integer = 1000000 +local hex = 0xEFBBBF +local binary = 19 +local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) +local fn +fn = function() + local str = "foo:\n bar: baz" + return str +end +local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" +local my_function +my_function = function() end my_function() local func_a func_a = function() @@ -929,6 +1799,12 @@ some_args = function(x, y) end return print(x + y) end +local a = x - 10 +local b = x - 10 +local c = x(-y) +local d = x - z +local x = func("hello") + 100 +local y = func("hello" + 100) my_func(5, 4, 3, 8, 9, 10) cool_func(1, 2, 3, 4, 5, 6, 7, 8) my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4) @@ -1046,76 +1922,351 @@ process = function(...) return sum end process(1, nil, 3, nil, 5) -f(function() - return print("hello") -end) -f(function(self) - return print(self.value) -end) -map(function(x) - return x * 2 -end, { - 1, - 2, - 3 -}) -local result, msg -do - result, msg = readAsync("文件名.txt", function(data) - print(data) - return processAsync(data, function(info) - return check(info) - end) - end) +local my_function +my_function = function() end +my_function() +local func_a +func_a = function() + return print("你好,世界") end -print(result, msg) -local some_values = { - 1, - 2, - 3, - 4 -} -local some_values = { - name = "Bill", - age = 200, - ["favorite food"] = "rice" -} -local profile = { - height = "4英尺", - shoe_size = 13, - favorite_foods = { - "冰淇淋", - "甜甜圈" - } -} -local values = { +local func_b +func_b = function() + local value = 100 + return print("这个值是:", value) +end +func_a() +func_b() +local sum +sum = function(x, y) + return print("数字的和", x + y) +end +sum(10, 20) +print(sum(10, 20)) +a(b(c("a", "b", "c"))) +print("x:", sum(10, 20), "y:", sum(30, 40)) +local sum +sum = function(x, y) + return x + y +end +print("数字的和是", sum(10, 20)) +local sum +sum = function(x, y) + return x + y +end +local mystery +mystery = function(x, y) + return x + y, x - y +end +local a, b = mystery(10, 20) +local func +func = function(self, num) + return self.value + num +end +local my_function +my_function = function(name, height) + if name == nil then + name = "某物" + end + if height == nil then + height = 100 + end + print("你好,我是", name) + return print("我的高度是", height) +end +local some_args +some_args = function(x, y) + if x == nil then + x = 100 + end + if y == nil then + y = x + 1000 + end + return print(x + y) +end +local a = x - 10 +local b = x - 10 +local c = x(-y) +local d = x - z +local x = func("hello") + 100 +local y = func("hello" + 100) +my_func(5, 4, 3, 8, 9, 10) +cool_func(1, 2, 3, 4, 5, 6, 7, 8) +my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4) +local x = { 1, 2, 3, 4, - 5, - 6, - 7, + a_func(4, 5, 5, 6), 8, - name = "超人", - occupation = "打击犯罪" + 9, + 10 } -my_function({ - dance = "探戈", - partner = "无" -}) local y = { - type = "狗", - legs = 4, - tails = 1 -} -local tbl = { - ["do"] = "某事", - ["end"] = "饥饿" + my_func(1, 2, 3, 4, 5), + 5, + 6, + 7 } -local hair = "金色" -local height = 200 -local person = { +if func(1, 2, 3, "你好", "世界") then + print("你好") + print("我在if内部") +end +if func(1, 2, 3, "你好", "世界") then + print("你好") + print("我在if内部") +end +local f1 +f1 = function(_arg_0) + local a, b, c + a, b, c = _arg_0.a, _arg_0.b, _arg_0.c + return print(a, b, c) +end +f1({ + a = 1, + b = "2", + c = { } +}) +local f2 +f2 = function(_arg_0, c) + local a1, b + a1, b = _arg_0.a, _arg_0.b + if a1 == nil then + a1 = 123 + end + if b == nil then + b = 'abc' + end + if c == nil then + c = { } + end + return print(a1, b, c) +end +local arg1 = { + a = 0 +} +f2(arg1, arg2) +local findFirstEven +findFirstEven = function(list) + for _index_0 = 1, #list do + local item = list[_index_0] + if type(item) == "table" then + for _index_1 = 1, #item do + local sub = item[_index_1] + if sub % 2 == 0 then + return sub + end + end + end + end + return nil +end +local findFirstEven +findFirstEven = function(list) + for _index_0 = 1, #list do + local item = list[_index_0] + if type(item) == "table" then + for _index_1 = 1, #item do + local sub = item[_index_1] + if sub % 2 == 0 then + return sub + end + end + end + end + return nil +end +local f +f = function(...) + local t = { + n = select("#", ...), + ... + } + print("参数个数:", t.n) + print("表长度:", #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(x) + return print("hello" .. x) +end) +f(function(self) + return print(self.value) +end) +map(function(x) + return x * 2 +end, { + 1, + 2, + 3 +}) +local result, msg +do + result, msg = readAsync("文件名.txt", function(data) + print(data) + return processAsync(data, function(info) + return check(info) + end) + end) +end +print(result, msg) +f(function(x) + return print("hello" .. x) +end) +f(function(self) + return print(self.value) +end) +map(function(x) + return x * 2 +end, { + 1, + 2, + 3 +}) +local result, msg +do + result, msg = readAsync("文件名.txt", function(data) + print(data) + return processAsync(data, function(info) + return check(info) + end) + end) +end +print(result, msg) +local some_values = { + 1, + 2, + 3, + 4 +} +local some_values = { + name = "Bill", + age = 200, + ["favorite food"] = "rice" +} +local profile = { + height = "4英尺", + shoe_size = 13, + favorite_foods = { + "冰淇淋", + "甜甜圈" + } +} +local values = { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + name = "超人", + occupation = "打击犯罪" +} +my_function({ + dance = "探戈", + partner = "无" +}) +local y = { + type = "狗", + legs = 4, + tails = 1 +} +local tbl = { + ["do"] = "某事", + ["end"] = "饥饿" +} +local hair = "金色" +local height = 200 +local person = { + hair = hair, + height = height, + shoe_size = 40 +} +print_table({ + hair = hair, + height = height +}) +local t = { + [1 + 2] = "你好", + ["你好 世界"] = true +} +local some_values = { + 1, + 2, + 3, + 4 +} +local list_with_one_element = { + 1 +} +local some_values = { + 1, + 2, + 3, + 4 +} +local some_values = { + name = "Bill", + age = 200, + ["favorite food"] = "rice" +} +local profile = { + height = "4英尺", + shoe_size = 13, + favorite_foods = { + "冰淇淋", + "甜甜圈" + } +} +local values = { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + name = "超人", + occupation = "打击犯罪" +} +my_function({ + dance = "探戈", + partner = "无" +}) +local y = { + type = "狗", + legs = 4, + tails = 1 +} +local tbl = { + ["do"] = "某事", + ["end"] = "饥饿" +} +local hair = "金色" +local height = 200 +local person = { hair = hair, height = height, shoe_size = 40 @@ -1335,15 +2486,250 @@ for _index_0 = _min_0, 1, -1 do end reverse_slice = _accum_0 local sub_list -local _accum_0 = { } +do + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = items + for _index_0 = 2, 4 do + local _item_0 = _list_0[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 + end + sub_list = _accum_0 +end +local last_four_items +local _accum_0 = { } local _len_0 = 1 local _list_0 = items -for _index_0 = 2, 4 do +local _min_0 = #_list_0 + -4 + 1 +local _max_0 = #_list_0 + -1 + 1 +for _index_0 = _min_0, _max_0 do + local _item_0 = _list_0[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 +end +last_four_items = _accum_0 +local items = { + 1, + 2, + 3, + 4 +} +local doubled +local _accum_0 = { } +local _len_0 = 1 +for i, item in ipairs(items) do + _accum_0[_len_0] = item * 2 + _len_0 = _len_0 + 1 +end +doubled = _accum_0 +local slice +local _accum_0 = { } +local _len_0 = 1 +for i, item in ipairs(items) do + if i > 1 and i < 3 then + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 + end +end +slice = _accum_0 +local doubled +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item * 2 + _len_0 = _len_0 + 1 +end +doubled = _accum_0 +local data = { + a = { + 1, + 2, + 3 + }, + b = { + 4, + 5, + 6 + } +} +local flat +local _accum_0 = { } +for k, v in pairs(data) do + local _len_0 = #_accum_0 + 1 + for _index_0 = 1, #v do + local _elm_0 = v[_index_0] + _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1 + end +end +flat = _accum_0 +local x_coords = { + 4, + 5, + 6, + 7 +} +local y_coords = { + 9, + 2, + 3 +} +local points +local _accum_0 = { } +local _len_0 = 1 +for _index_0 = 1, #x_coords do + local x = x_coords[_index_0] + for _index_1 = 1, #y_coords do + local y = y_coords[_index_1] + _accum_0[_len_0] = { + x, + y + } + _len_0 = _len_0 + 1 + end +end +points = _accum_0 +local evens +local _accum_0 = { } +local _len_0 = 1 +for i = 1, 100 do + if i % 2 == 0 then + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end +end +evens = _accum_0 +local thing = { + color = "red", + name = "fast", + width = 123 +} +local thing_copy +local _tbl_0 = { } +for k, v in pairs(thing) do + _tbl_0[k] = v +end +thing_copy = _tbl_0 +local no_color +local _tbl_0 = { } +for k, v in pairs(thing) do + if k ~= "color" then + _tbl_0[k] = v + end +end +no_color = _tbl_0 +local numbers = { + 1, + 2, + 3, + 4 +} +local sqrts +local _tbl_0 = { } +for _index_0 = 1, #numbers do + local i = numbers[_index_0] + _tbl_0[i] = math.sqrt(i) +end +sqrts = _tbl_0 +local tuples = { + { + "hello", + "world" + }, + { + "foo", + "bar" + } +} +local tbl +local _tbl_0 = { } +for _index_0 = 1, #tuples do + local tuple = tuples[_index_0] + local _key_0, _val_0 = unpack(tuple) + _tbl_0[_key_0] = _val_0 +end +tbl = _tbl_0 +local slice +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +for _index_0 = 1, 5 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 +end +slice = _accum_0 +local slice +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _max_0 = #_list_0 +for _index_0 = 2, _max_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 +end +slice = _accum_0 +local slice +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _max_0 = #_list_0 +for _index_0 = 1, _max_0, 2 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 +end +slice = _accum_0 +local slice +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _min_0 = #_list_0 + -4 + 1 +local _max_0 = #_list_0 + -1 + 1 +for _index_0 = _min_0, _max_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 +end +slice = _accum_0 +local reverse_slice +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _min_0 = #_list_0 + -1 + 1 +for _index_0 = _min_0, 1, -1 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 +end +reverse_slice = _accum_0 +local sub_list +do + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = items + for _index_0 = 2, 4 do + local _item_0 = _list_0[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 + end + sub_list = _accum_0 +end +local last_four_items +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _min_0 = #_list_0 + -4 + 1 +local _max_0 = #_list_0 + -1 + 1 +for _index_0 = _min_0, _max_0 do local _item_0 = _list_0[_index_0] _accum_0[_len_0] = _item_0 _len_0 = _len_0 + 1 end -sub_list = _accum_0 +last_four_items = _accum_0 for i = 10, 20 do print(i) end @@ -1408,29 +2794,144 @@ func_b = function() end print(func_a()) print(func_b()) -local i = 10 -repeat - print(i) - i = i - 1 -until i == 0 -local i = 10 -while i > 0 do +for i = 10, 20 do print(i) - i = i - 1 end -while running == true do - my_function() +for k = 1, 15, 2 do + print(k) end -local i = 10 -while not (i == 0) do - print(i) - i = i - 1 +for key, value in pairs(object) do + print(key, value) end -while not (running == false) do - my_function() +local _list_0 = items +for _index_0 = 2, 4 do + local item = _list_0[_index_0] + print(item) end -local i = 0 -while i < 10 do +local _list_0 = items +for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + print(item) +end +for j = 1, 10, 3 do + print(j) +end +local doubled_evens +local _accum_0 = { } +local _len_0 = 1 +for i = 1, 20 do + if i % 2 == 0 then + _accum_0[_len_0] = i * 2 + _len_0 = _len_0 + 1 + else + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end +end +doubled_evens = _accum_0 +local first_large +local _accum_0 +local _list_0 = numbers +for _index_0 = 1, #_list_0 do + local n = _list_0[_index_0] + if n > 10 then + _accum_0 = n + break + end +end +first_large = _accum_0 +local func_a +func_a = function() + for i = 1, 10 do + print(i) + end +end +local func_b +func_b = function() + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end + return _accum_0 +end +print(func_a()) +print(func_b()) +local i = 10 +while i > 0 do + print(i) + i = i - 1 +end +while running == true do + my_function() +end +local i = 10 +while not (i == 0) do + print(i) + i = i - 1 +end +while not (running == false) do + my_function() +end +local i = 10 +repeat + print(i) + i = i - 1 +until i == 0 +local i = 10 +while i > 0 do + print(i) + i = i - 1 +end +while running == true do + my_function() +end +local i = 10 +while not (i == 0) do + print(i) + i = i - 1 +end +while not (running == false) do + my_function() +end +local i = 10 +repeat + print(i) + i = i - 1 +until i == 0 +local i = 0 +while i < 10 do + i = i + 1 + if i % 2 == 0 then + goto _continue_0 + end + print(i) + ::_continue_0:: +end +local my_numbers = { + 1, + 2, + 3, + 4, + 5, + 6 +} +local odds +local _accum_0 = { } +local _len_0 = 1 +for _index_0 = 1, #my_numbers do + local x = my_numbers[_index_0] + if x % 2 == 1 then + goto _continue_0 + end + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + ::_continue_0:: +end +odds = _accum_0 +local i = 0 +while i < 10 do i = i + 1 if i % 2 == 0 then goto _continue_0 @@ -1518,6 +3019,79 @@ end if not (math.random() > 0.1) then print("你很幸运!") end +local have_coins = false +if have_coins then + print("有硬币") +else + print("没有硬币") +end +local have_coins = false +if have_coins then + print("有硬币") +else + print("没有硬币") +end +local have_coins = false +print((function() + if have_coins then + return "有硬币" + else + return "没有硬币" + end +end)()) +local is_tall +is_tall = function(name) + if name == "Rob" then + return true + else + return false + end +end +local message +if is_tall("Rob") then + message = "我很高" +else + message = "我不是很高" +end +print(message) +if not (os.date("%A") == "Monday") then + print("今天不是星期一!") +end +if not (math.random() > 0.1) then + print("你真幸运!") +end +local a = 5 +if (1 == a or 3 == a or 5 == a or 7 == a) then + print("检查离散值的相等性") +end +if (function() + local _check_0 = list + for _index_0 = 1, #_check_0 do + if _check_0[_index_0] == a then + return true + end + end + return false +end)() then + print("检查`a`是否在列表中") +end +if not (math.random() > 0.1) then + print("你很幸运!") +end +if name == "Rob" then + print("你好,世界") +end +local _list_0 = items +for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + print("项目: ", item) +end +while game:isRunning() do + game:update() +end +while not reader:eof() do + reader:parse_line() +end if name == "Rob" then print("你好,世界") end @@ -1824,207 +3398,382 @@ if _tab_0 then print("Action:", action) end end -local Inventory -local _class_0 -local _base_0 = { - add_item = function(self, name) - if self.items[name] then - local _obj_0 = self.items - _obj_0[name] = _obj_0[name] + 1 - else - self.items[name] = 1 - end - end -} -if _base_0.__index == nil then - _base_0.__index = _base_0 +local name = "Dan" +if "Robert" == name then + print("你是Robert") +elseif "Dan" == name or "Daniel" == name then + print("你的名字是Dan") +else + print("我不认识你,你的名字是" .. tostring(name)) +end +local b = 1 +local next_number +if 1 == b then + next_number = 2 +elseif 2 == b then + next_number = 3 +else + next_number = error("数字数得太大了!") +end +local msg +local _exp_0 = math.random(1, 5) +if 1 == _exp_0 then + msg = "你很幸运" +elseif 2 == _exp_0 then + msg = "你差点很幸运" +else + msg = "不太幸运" end -_class_0 = setmetatable({ - __init = function(self) - self.items = { } - end, - __base = _base_0, - __name = "Inventory" -}, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end -}) -_base_0.__class = _class_0 -Inventory = _class_0 -local inv = Inventory() -inv:add_item("t-shirt") -inv:add_item("pants") -local Person do - local _class_0 - local _base_0 = { - clothes = { }, - give_item = function(self, name) - return table.insert(self.clothes, name) - end + local _exp_0 = math.random(1, 5) + if 1 == _exp_0 then + print("你很幸运") + else + print("不太幸运") + end +end +local _exp_0 = math.random(1, 5) +if 1 == _exp_0 then + print("你很幸运") +else + print("不太幸运") +end +local items = { + { + x = 100, + y = 200 + }, + { + width = 300, + height = 400 } - if _base_0.__index == nil then - _base_0.__index = _base_0 +} +for _index_0 = 1, #items do + local item = items[_index_0] + local _type_0 = type(item) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local x = item.x + local y = item.y + if x ~= nil and y ~= nil then + _match_0 = true + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) + end end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Person" - }, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 + if not _match_0 then + if _tab_0 then + local width = item.width + local height = item.height + if width ~= nil and height ~= nil then + print("尺寸 " .. tostring(width) .. ", " .. tostring(height)) + end end - }) - _base_0.__class = _class_0 - Person = _class_0 + end end -local a = Person() -local b = Person() -a:give_item("pants") -b:give_item("shirt") -local _list_0 = a.clothes -for _index_0 = 1, #_list_0 do - local item = _list_0[_index_0] - print(item) +local item = { } +local x, y = item.pos.x, item.pos.y +if x == nil then + x = 50 end -local Person -local _class_0 -local _base_0 = { } -if _base_0.__index == nil then - _base_0.__index = _base_0 +if y == nil then + y = 200 end -_class_0 = setmetatable({ - __init = function(self) - self.clothes = { } - end, - __base = _base_0, - __name = "Person" -}, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 +local _type_0 = type(item) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +if _tab_0 then + do + local _obj_0 = item.pos + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + x = _obj_0.x + end end -}) -_base_0.__class = _class_0 -Person = _class_0 -local BackPack -local _class_0 -local _parent_0 = Inventory -local _base_0 = { - size = 10, - add_item = function(self, name) - if #self.items > size then - error("背包已满") + do + local _obj_0 = item.pos + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + y = _obj_0.y end - return _class_0.__parent.__base.add_item(self, name) end -} -for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 + if x == nil then + x = 50 + end + if y == nil then + y = 200 end + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end -if _base_0.__index == nil then - _base_0.__index = _base_0 +local _exp_0 = tb +local _type_0 = type(_exp_0) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +local _match_0 = false +if _tab_0 then + if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then + _match_0 = true + print("1, 2, 3") + end end -setmetatable(_base_0, _parent_0.__base) -_class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, - __base = _base_0, - __name = "BackPack", - __parent = _parent_0 -}, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] +if not _match_0 then + local _match_1 = false + if _tab_0 then + local b = _exp_0[2] + if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then + _match_1 = true + print("1, " .. tostring(b) .. ", 3") + end + end + if not _match_1 then + if _tab_0 then + local b = _exp_0[3] + if b == nil then + b = 3 + end + if 1 == _exp_0[1] and 2 == _exp_0[2] then + print("1, 2, " .. tostring(b)) end - else - return val end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 end -}) -_base_0.__class = _class_0 -if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) end -BackPack = _class_0 -local Shelf -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _exp_0 = tb +local _type_0 = type(_exp_0) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +local _match_0 = false +if _tab_0 then + local result = _exp_0.result + if true == _exp_0.success and result ~= nil then + _match_0 = true + print("成功", result) end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Shelf" - }, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 +end +if not _match_0 then + local _match_1 = false + if _tab_0 then + if false == _exp_0.success then + _match_1 = true + print("失败", result) end - }) - _base_0.__class = _class_0 - local self = _class_0; - self.__inherited = function(self, child) - return print(self.__name, "被", child.__name, "继承") end - Shelf = _class_0 + if not _match_1 then + print("无效值") + end end -local Cupboard -local _class_0 -local _parent_0 = Shelf -local _base_0 = { } -for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 +local _exp_0 = tb +local _type_0 = type(_exp_0) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +local _match_0 = false +if _tab_0 then + local content + do + local _obj_0 = _exp_0.data + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + content = _obj_0.content + end + end + local _val_0 + do + local _obj_0 = _exp_0.data + if _obj_0 ~= nil then + _val_0 = _obj_0.type + end + end + if "success" == _val_0 and content ~= nil then + _match_0 = true + print("成功", content) end end +if not _match_0 then + local _match_1 = false + if _tab_0 then + local content + do + local _obj_0 = _exp_0.data + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + content = _obj_0.content + end + end + local _val_0 + do + local _obj_0 = _exp_0.data + if _obj_0 ~= nil then + _val_0 = _obj_0.type + end + end + if "error" == _val_0 and content ~= nil then + _match_1 = true + print("失败", content) + end + end + if not _match_1 then + print("无效值") + end +end +local _exp_0 = tb +local _type_0 = type(_exp_0) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +if _tab_0 then + local fourth = _exp_0[4] + local _val_0 + do + local _obj_0 = _exp_0[1] + if _obj_0 ~= nil then + _val_0 = _obj_0.a + end + end + local _val_1 + do + local _obj_0 = _exp_0[1] + if _obj_0 ~= nil then + _val_1 = _obj_0.b + end + end + local _val_2 + do + local _obj_0 = _exp_0[2] + if _obj_0 ~= nil then + _val_2 = _obj_0.a + end + end + local _val_3 + do + local _obj_0 = _exp_0[2] + if _obj_0 ~= nil then + _val_3 = _obj_0.b + end + end + local _val_4 + do + local _obj_0 = _exp_0[3] + if _obj_0 ~= nil then + _val_4 = _obj_0.a + end + end + local _val_5 + do + local _obj_0 = _exp_0[3] + if _obj_0 ~= nil then + _val_5 = _obj_0.b + end + end + if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then + print("匹配成功", fourth) + end +end +local segments = { + "admin", + "users", + "logs", + "view" +} +local _type_0 = type(segments) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +if _tab_0 then + local groups + do + local _accum_0 = { } + local _len_0 = 1 + local _max_0 = #segments + -3 + 1 + for _index_0 = 1, _max_0 do + local _item_0 = segments[_index_0] + _accum_0[_len_0] = _item_0 + _len_0 = _len_0 + 1 + end + groups = _accum_0 + end + local resource = segments[#segments - 1] + local action = segments[#segments] + if resource ~= nil and action ~= nil then + print("Group:", groups) + print("Resource:", resource) + print("Action:", action) + end +end +local Inventory +local _class_0 +local _base_0 = { + add_item = function(self, name) + if self.items[name] then + local _obj_0 = self.items + _obj_0[name] = _obj_0[name] + 1 + else + self.items[name] = 1 + end + end +} if _base_0.__index == nil then _base_0.__index = _base_0 end -setmetatable(_base_0, _parent_0.__base) _class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) + __init = function(self) + self.items = { } end, __base = _base_0, - __name = "Cupboard", - __parent = _parent_0 + __name = "Inventory" }, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end - else - return val + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end +}) +_base_0.__class = _class_0 +Inventory = _class_0 +local inv = Inventory() +inv:add_item("t-shirt") +inv:add_item("pants") +local Person +do + local _class_0 + local _base_0 = { + clothes = { }, + give_item = function(self, name) + return table.insert(self.clothes, name) + end + } + if _base_0.__index == nil then + _base_0.__index = _base_0 + end + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Person" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end + }) + _base_0.__class = _class_0 + Person = _class_0 +end +local a = Person() +local b = Person() +a:give_item("pants") +b:give_item("shirt") +local _list_0 = a.clothes +for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + print(item) +end +local Person +local _class_0 +local _base_0 = { } +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function(self) + self.clothes = { } end, + __base = _base_0, + __name = "Person" +}, { + __index = _base_0, __call = function(cls, ...) local _self_0 = setmetatable({ }, _base_0) cls.__init(_self_0, ...) @@ -2032,19 +3781,17 @@ _class_0 = setmetatable({ end }) _base_0.__class = _class_0 -if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) -end -Cupboard = _class_0 -local MyClass +Person = _class_0 +local BackPack local _class_0 -local _parent_0 = ParentClass +local _parent_0 = Inventory local _base_0 = { - a_method = function(self) - _class_0.__parent.__base.a_method(self, "你好", "世界") - _class_0.__parent.a_method(self, "你好", "世界") - _class_0.__parent.a_method(self, "你好", "世界") - return assert(_class_0.__parent == ParentClass) + size = 10, + add_item = function(self, name) + if #self.items > size then + error("背包已满") + end + return _class_0.__parent.__base.add_item(self, name) end } for _key_0, _val_0 in pairs(_parent_0.__base) do @@ -2061,7 +3808,7 @@ _class_0 = setmetatable({ return _class_0.__parent.__init(self, ...) end, __base = _base_0, - __name = "MyClass", + __name = "BackPack", __parent = _parent_0 }, { __index = function(cls, name) @@ -2085,12 +3832,8 @@ _base_0.__class = _class_0 if _parent_0.__inherited then _parent_0.__inherited(_parent_0, _class_0) end -MyClass = _class_0 -local b = BackPack() -assert(b.__class == BackPack) -print(BackPack.size) -print(BackPack.__name) -local Things +BackPack = _class_0 +local Shelf do local _class_0 local _base_0 = { } @@ -2100,7 +3843,7 @@ do _class_0 = setmetatable({ __init = function() end, __base = _base_0, - __name = "Things" + __name = "Shelf" }, { __index = _base_0, __call = function(cls, ...) @@ -2111,27 +3854,150 @@ do }) _base_0.__class = _class_0 local self = _class_0; - self.some_func = function(self) - return print("Hello from", self.__name) + self.__inherited = function(self, child) + return print(self.__name, "被", child.__name, "继承") end - Things = _class_0 + Shelf = _class_0 end -Things:some_func() -assert(Things().some_func == nil) -local Counter -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local Cupboard +local _class_0 +local _parent_0 = Shelf +local _base_0 = { } +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 end - _class_0 = setmetatable({ - __init = function(self) - self.__class.count = self.__class.count + 1 - end, - __base = _base_0, - __name = "Counter" - }, { +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "Cupboard", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] + end + else + return val + end + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) +end +Cupboard = _class_0 +local MyClass +local _class_0 +local _parent_0 = ParentClass +local _base_0 = { + a_method = function(self) + _class_0.__parent.__base.a_method(self, "你好", "世界") + _class_0.__parent.a_method(self, "你好", "世界") + _class_0.__parent.a_method(self, "你好", "世界") + return assert(_class_0.__parent == ParentClass) + end +} +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "MyClass", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] + end + else + return val + end + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) +end +MyClass = _class_0 +local b = BackPack() +assert(b.__class == BackPack) +print(BackPack.size) +print(BackPack.__name) +local Things +do + local _class_0 + local _base_0 = { } + if _base_0.__index == nil then + _base_0.__index = _base_0 + end + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Things" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_0.__class = _class_0 + local self = _class_0; + self.some_func = function(self) + return print("Hello from", self.__name) + end + Things = _class_0 +end +Things:some_func() +assert(Things().some_func == nil) +local Counter +do + local _class_0 + local _base_0 = { } + if _base_0.__index == nil then + _base_0.__index = _base_0 + end + _class_0 = setmetatable({ + __init = function(self) + self.__class.count = self.__class.count + 1 + end, + __base = _base_0, + __name = "Counter" + }, { __index = _base_0, __call = function(cls, ...) local _self_0 = setmetatable({ }, _base_0) @@ -2328,2056 +4194,122 @@ do else return val end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end - }) - _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) - end - BigBucket = _class_0 -end -assert(Bucket.__name == "BigBucket") -local x -local _class_0 -local _base_0 = { } -if _base_0.__index == nil then - _base_0.__index = _base_0 -end -_class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "x" -}, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end -}) -_base_0.__class = _class_0 -x = _class_0 -local MyIndex = { - __index = { - var = 1 - } -} -local X -do - local _class_0 - local _base_0 = { - func = function(self) - return print(123) - end - } - local _list_0 = { - MyIndex - } - for _index_0 = 1, #_list_0 do - local _item_0 = _list_0[_index_0] - local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0 - for _key_0, _val_0 in pairs(_mixin_0) do - if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then - _base_0[_key_0] = _val_0 - end - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "X" - }, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end - }) - _base_0.__class = _class_0 - X = _class_0 -end -local x = X() -print(x.var) -local Y -do - local _class_0 - local _base_0 = { } - local _list_0 = { - X - } - for _index_0 = 1, #_list_0 do - local _item_0 = _list_0[_index_0] - local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0 - for _key_0, _val_0 in pairs(_mixin_0) do - if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then - _base_0[_key_0] = _val_0 - end - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Y" - }, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end - }) - _base_0.__class = _class_0 - Y = _class_0 -end -local y = Y() -y:func() -assert(y.__class.__parent ~= X) -local _with_0 = Person() -_with_0.name = "Oswald" -_with_0:add_relative(my_dad) -_with_0:save() -print(_with_0.name) -local file -local _with_0 = File("favorite_foods.txt") -_with_0:set_encoding("utf8") -file = _with_0 -local create_person -create_person = function(name, relatives) - local _with_0 = Person() - _with_0.name = name - for _index_0 = 1, #relatives do - local relative = relatives[_index_0] - _with_0:add_relative(relative) - end - return _with_0 -end -local me = create_person("Leaf", { - dad, - mother, - sister -}) -local str = "你好" -print("原始:", str) -print("大写:", str:upper()) -local _with_0 = tb -_with_0[1] = 1 -print(_with_0[2]) -do - local _with_1 = _with_0[abc] - _with_1[3] = _with_1[2]:func() - _with_1["key-name"] = value -end -_with_0[#_with_0 + 1] = "abc" -local _with_0 = obj -if _with_0 ~= nil then - print(obj.name) -end -do - local var = "hello" - print(var) -end -print(var) -local counter -do - local i = 0 - counter = function() - i = i + 1 - return i - end -end -print(counter()) -print(counter()) -local tbl = { - key = (function() - print("分配键值!") - return 1234 - end)() -} -local my_object = { - value = 1000, - write = function(self) - return print("值为:", self.value) - end -} -local run_callback -run_callback = function(func) - print("运行回调...") - return func() -end -run_callback(my_object.write) -run_callback((function() - local _base_0 = my_object - local _fn_0 = _base_0.write - return _fn_0 and function(...) - return _fn_0(_base_0, ...) - end -end)()) -local i = 100 -local my_func -my_func = function() - i = 10 - while i > 0 do - print(i) - i = i - 1 - end -end -my_func() -print(i) -local i = 100 -local my_func -my_func = function() - local i = "hello" -end -my_func() -print(i) -local tmp = 1213 -local i, k = 100, 50 -local my_func -my_func = function(add) - local tmp = tmp + add - i = i + tmp - k = k + tmp -end -my_func(22) -print(i, k) -local _module_0 = { } -local p, to_lua -do - local _obj_0 = require("yue") - p, to_lua = _obj_0.p, _obj_0.to_lua -end -local inventory = { - equipment = { - "sword", - "shield" - }, - items = { - { - name = "potion", - count = 10 - }, - { - name = "bread", - count = 3 - } - } -} -local map -map = function(arr, action) - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #arr do - local item = arr[_index_0] - _accum_0[_len_0] = action(item) - _len_0 = _len_0 + 1 - end - return _accum_0 -end -local filter -filter = function(arr, cond) - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #arr do - local item = arr[_index_0] - if cond(item) then - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - end - return _accum_0 -end -local reduce -reduce = function(arr, init, action) - for _index_0 = 1, #arr do - local item = arr[_index_0] - init = action(init, item) - end - return init -end -print(reduce(filter(map({ - 1, - 2, - 3 -}, function(x) - return x * 2 -end), function(x) - return x > 4 -end), 0, function(a, b) - return a + b -end)) -local apple = setmetatable({ - size = 15, -}, { - __index = { - color = 0x00ffff - } -}) -if (getmetatable(apple) ~= nil) then - p(apple.size, apple.color, getmetatable(apple).__index) -end -local _u1f31b = "月之脚本" -_module_0["🌛"] = _u1f31b -return _module_0 -local area = 6.2831853071796 * 5 -print('你好 世界') -do - assert(item ~= nil) -end -local value = item -if (f1() and f2() and f3()) then - print("OK") -end -do - local funcA - funcA = function() end -end -local funcA -funcA = function() - return "无法访问宏生成月之脚本里定义的变量" -end -do -local function funcB() end -end -local funcB -funcB = function() - return "无法访问宏生成 Lua 代码里定义的变量" -end -do --- 插入原始Lua代码 -if cond then - print("输出") -end -end -print("yuescript") -print(2) -print("有效的枚举类型:", "Static") -do - print(123, "hello") -end -do - print(123, "hello") -end -if tb ~= nil then - tb:func() -end -if tb ~= nil then - tb:func() -end -print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5) -local a = 5 -print(1 <= a and a <= 10) -local v -v = function(x) - print(x) - return x -end -print((function() - local _cond_0 = v(2) - if not (v(1) < _cond_0) then - return false - else - return _cond_0 <= v(3) - end -end)()) -print((function() - local _cond_0 = v(2) - if not (v(1) > _cond_0) then - return false - else - return _cond_0 <= v(3) - end -end)()) -local tab = { } -tab[#tab + 1] = "Value" -local tbA = { - 1, - 2, - 3 -} -local tbB = { - 4, - 5, - 6 -} -local _len_0 = #tbA + 1 -for _index_0 = 1, #tbB do - local _elm_0 = tbB[_index_0] - tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 -end -local parts = { - "shoulders", - "knees" -} -local lyrics -do - local _tab_0 = { - "head" - } - local _idx_0 = 1 - for _key_0, _value_0 in pairs(parts) do - if _idx_0 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_0 = _idx_0 + 1 - else - _tab_0[_key_0] = _value_0 - end - end - _tab_0[#_tab_0 + 1] = "and" - _tab_0[#_tab_0 + 1] = "toes" - lyrics = _tab_0 -end -local copy -do - local _tab_0 = { } - local _idx_0 = 1 - for _key_0, _value_0 in pairs(other) do - if _idx_0 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_0 = _idx_0 + 1 - else - _tab_0[_key_0] = _value_0 - end - end - copy = _tab_0 -end -local a = { - 1, - 2, - 3, - x = 1 -} -local b = { - 4, - 5, - y = 1 -} -local merge -local _tab_0 = { } -local _idx_0 = 1 -for _key_0, _value_0 in pairs(a) do - if _idx_0 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_0 = _idx_0 + 1 - else - _tab_0[_key_0] = _value_0 - end -end -local _idx_1 = 1 -for _key_0, _value_0 in pairs(b) do - if _idx_1 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_1 = _idx_1 + 1 - else - _tab_0[_key_0] = _value_0 - end -end -merge = _tab_0 -local last -do - local _item_0 = data.items - last = _item_0[#_item_0] -end -local second_last -do - local _item_0 = data.items - second_last = _item_0[#_item_0 - 1] -end -local _obj_0 = data.items -_obj_0[#_obj_0] = 1 -local mt = { } -local add -add = function(self, right) - return setmetatable({ - value = self.value + right.value - }, mt) -end -mt.__add = add -local a = setmetatable({ - value = 1 -}, mt) -local b = setmetatable({ - value = 2 -}, { - __add = add -}) -local c = setmetatable({ - value = 3 -}, { - __add = mt.__add -}) -local d = a + b + c -print(d.value) -local _ = setmetatable({ }, { - __close = function() - return print("超出范围") - end -}) -local tb = setmetatable({ }, { - ["value"] = 123 -}) -getmetatable(tb).__index = getmetatable(tb) -print(tb.value) -setmetatable(tb, { - __index = { - item = "hello" - } -}) -print(tb.item) -local item, new, close, getter -do - local _obj_0 = tb - item, new = _obj_0[1], _obj_0.new - do - local _obj_1 = getmetatable(_obj_0) - close, getter = _obj_1.__close, _obj_1.__index - end -end -print(item, new, close, getter) -do - local _obj_0 = func - if _obj_0 ~= nil then - _obj_0() - end -end -print((function() - local _obj_0 = abc - if _obj_0 ~= nil then - local _obj_1 = _obj_0["你好 世界"] - if _obj_1 ~= nil then - return _obj_1.xyz - end - return nil - end - return nil -end)()) -local x -do - local _obj_0 = tab - if _obj_0 ~= nil then - x = _obj_0.value - end -end -local len = (function() - local _obj_0 = utf8 - if _obj_0 ~= nil then - return _obj_0.len - end - return nil -end)() or (function() - local _obj_0 = string - if _obj_0 ~= nil then - return _obj_0.len - end - return nil -end)() or function(o) - return #o -end -if print and (x ~= nil) then - print(x) -end -local _with_0 = io.open("test.txt", "w") -if _with_0 ~= nil then - _with_0:write("你好") - _with_0:close() -end -print("你好") -print(1, 2) -print(1, 2, 3) -print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) -local a, b, c, d -if b ~= nil then - a = b -else - if c ~= nil then - a = c - else - a = d - end -end -func((function() - if a ~= nil then - return a - else - return { } - end -end)()) -if a == nil then - a = false -end -local list = { - 1, - 2, - 3 -} -func({ - 1, - 2, - 3 -}) -local f -f = function() - return { - 1, - 2, - 3 - } -end -local tb = { - name = "abc", - values = { - "a", - "b", - "c" - }, - objects = { - { - name = "a", - value = 1, - func = function(self) - return self.value + 1 - end, - tb = { - fieldA = 1 - } - }, - { - name = "b", - value = 2, - func = function(self) - return self.value + 2 - end, - tb = { } - } - } -} -do - local insert, concat = table.insert, table.concat - local C, Ct, Cmt - do - local _obj_0 = require("lpeg") - C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt - end - local x, y, z - do - local _obj_0 = require('mymodule') - x, y, z = _obj_0.x, _obj_0.y, _obj_0.z - end - local a, b, c - local _obj_0 = require('module') - a, b, c = _obj_0.a, _obj_0.b, _obj_0.c -end -do - local module = require('module') - local module_x = require('module_x') - local d_a_s_h_e_s = require("d-a-s-h-e-s") - local part = require("module.part") -end -do - local PlayerModule = require("player") - local C, Ct, Cmt - do - local _obj_0 = require("lpeg") - C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt - end - local one, two, ch - local _obj_0 = require("export") - one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] -end -do - local tostring = tostring - local concat = table.concat - print(concat({ - "a", - tostring(1) - })) -end -do - local print = print - local math = math - print("hello") - math.random(3) -end -do - local print = print - print(FLAG) - FLAG = 123 -end -local _module_0 = { } -local a, b, c = 1, 2, 3 -_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c -local cool = "cat" -_module_0["cool"] = cool -local What -if this then - What = "abc" -else - What = "def" -end -_module_0["What"] = What -local y -y = function() - local hallo = 3434 -end -_module_0["y"] = y -local Something -local _class_0 -local _base_0 = { - umm = "cool" -} -if _base_0.__index == nil then - _base_0.__index = _base_0 -end -_class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Something" -}, { - __index = _base_0, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end -}) -_base_0.__class = _class_0 -Something = _class_0 -_module_0["Something"] = Something -return _module_0 -local _module_0 = { } -local loadstring, tolua -do - local _obj_0 = yue - loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua -end -_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua -local fieldA = tb.itemA.fieldA -if fieldA == nil then - fieldA = '默认值' -end -_module_0["fieldA"] = fieldA -return _module_0 -local _module_0 = setmetatable({ }, { }) -_module_0.itemA = tb -getmetatable(_module_0).__index = items -_module_0["a-b-c"] = 123 -return _module_0 -local _module_0 = { } -local d, e, f = 3, 2, 1 -_module_0[#_module_0 + 1] = d -_module_0[#_module_0 + 1] = e -_module_0[#_module_0 + 1] = f -if this then - _module_0[#_module_0 + 1] = 123 -else - _module_0[#_module_0 + 1] = 456 -end -local _with_0 = tmp -local j = 2000 -_module_0[#_module_0 + 1] = _with_0 -return _module_0 -local _module_0 = nil -_module_0 = function() - print("你好") - return 123 -end -return _module_0 -local hello = "world" -local a, b, c = 1, 2, 3 -hello = 123 -local x = 1 -x = x + 1 -x = x - 1 -x = x * 10 -x = x / 10 -x = x % 10 -local s = s .. "world" -local arg = arg or "默认值" -local a = 0 -local b = 0 -local c = 0 -local d = 0 -local e = 0 -local x = f() -local y = x -local z = x -do - local a = 1 - local x, y, z - print("预先声明后续所有变量为局部变量") - x = function() - return 1 + y + z - end - y, z = 2, 3 - instance = Item:new() -end -do - local X = 1 - local B - print("只预先声明后续大写的变量为局部变量") - local a = 1 - B = 2 -end -do - a = 1 - print("预先声明所有变量为全局变量") - x = function() - return 1 + y + z - end - y, z = 2, 3 -end -do - x = 1 - print("只预先声明大写的变量为全局变量") - local a = 1 - B = 2 - local Temp = "一个局部值" -end -local thing = { - 1, - 2 -} -local a, b = thing[1], thing[2] -print(a, b) -local obj = { - hello = "world", - day = "tuesday", - length = 20 -} -local hello, the_day = obj.hello, obj.day -print(hello, the_day) -local day = obj.day -local obj2 = { - numbers = { - 1, - 2, - 3, - 4 - }, - properties = { - color = "green", - height = 13.5 - } -} -local first, second = obj2.numbers[1], obj2.numbers[2] -print(first, second, color) -local first, second, color -local _obj_0 = obj2 -first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color -local concat, insert -local _obj_0 = table -concat, insert = _obj_0.concat, _obj_0.insert -local mix, max, rand -local _obj_0 = math -mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random -local name, job -local _obj_0 = person -name, job = _obj_0.name, _obj_0.job -if name == nil then - name = "nameless" -end -if job == nil then - job = "jobless" -end -local two, four -local _obj_0 = items -two, four = _obj_0[2], _obj_0[4] -local orders = { - "first", - "second", - "third", - "fourth", - "last" -} -local first, bulk, last = orders[1], (function() - local _accum_0 = { } - local _len_0 = 1 - local _max_0 = #orders + -2 + 1 - for _index_0 = 2, _max_0 do - local _item_0 = orders[_index_0] - _accum_0[_len_0] = _item_0 - _len_0 = _len_0 + 1 - end - return _accum_0 -end)(), orders[#orders] -print(first) -print(bulk) -print(last) -local first, rest -do - local _obj_0 = orders - first, rest = _obj_0[1], (function() - local _accum_0 = { } - local _len_0 = 1 - local _max_0 = #_obj_0 - for _index_0 = 2, _max_0 do - local _item_0 = _obj_0[_index_0] - _accum_0[_len_0] = _item_0 - _len_0 = _len_0 + 1 - end - return _accum_0 - end)() -end -local start, last -do - local _obj_0 = orders - start, last = (function() - local _accum_0 = { } - local _len_0 = 1 - local _max_0 = #_obj_0 + -2 + 1 - for _index_0 = 1, _max_0 do - local _item_0 = _obj_0[_index_0] - _accum_0[_len_0] = _item_0 - _len_0 = _len_0 + 1 - end - return _accum_0 - end)(), _obj_0[#_obj_0] -end -local _obj_0 = orders -first, last = _obj_0[1], _obj_0[#_obj_0] -local tuples = { - { - "hello", - "world" - }, - { - "egg", - "head" - } -} -for _index_0 = 1, #tuples do - local _des_0 = tuples[_index_0] - local left, right = _des_0[1], _des_0[2] - print(left, right) -end -local user = database.find_user("moon") -if user then - print(user.name) -end -local hello = os.getenv("hello") -if hello then - print("你有 hello", hello) -else - local world = os.getenv("world") - if world then - print("你有 world", world) - else - print("什么都没有 :(") - end -end -do - local success, result = pcall(function() - return "无报错地获取结果" - end) - if success then - print(result) - end -end -print("好的") -repeat - local byte = stream:read_one() - if byte then - print(byte) - else - break - end -until false -local list = { - 1, - 2, - 3, - 4, - 5 -} -local fn -fn = function(ok) - return ok, table.unpack(list) -end -(function(_arg_0, ...) - local ok = _arg_0 - local count = select('#', ...) - local first = select(1, ...) - return print(ok, count, first) -end)(fn(true)) -local a = 1 -local b = 2 -print(a + b) -Rx.Observable.fromRange(1, 8):filter(function(x) - return x % 2 == 0 -end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) - return value .. '!' -end):subscribe(print) -local str = strA .. strB .. strC -func(3000, "192.168.1.1") -xpcall(function() - return func(1, 2, 3) -end, function(err) - return print(yue.traceback(err)) -end) -local success, result = xpcall(function() - return func(1, 2, 3) -end, function(err) - return yue.traceback(err) -end) -xpcall(function() - return func(1, 2, 3) -end, function(err) - return print(yue.traceback(err)) -end) -success, result = pcall(function() - return func(1, 2, 3) -end) -pcall(function() - print("尝试中") - return func(1, 2, 3) -end) -success, result = xpcall(function() - return func(1, 2, 3) -end, function(err) - return print(yue.traceback(err)) -end) -if success then - print(result) -end -local a, b, c -do - local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() - return func() - end) - if _ok_0 then - a, b, c = _ret_0, _ret_1, _ret_2 - end -end -do - local _exp_0 = ((function() - return (function(_arg_0, ...) - local _ok_0 = _arg_0 - if _ok_0 then - return ... - end - end)(pcall(function() - return func() - end)) - end)()) - if _exp_0 ~= nil then - a = _exp_0 - else - a = "default" - end -end -f((function() - return (function(_arg_0, ...) - local _ok_0 = _arg_0 - if _ok_0 then - return ... - end - end)(pcall(function() - return func() - end)) -end)()) -f((function() - return (function(_arg_0, ...) - local _ok_0 = _arg_0 - if _ok_0 then - return ... - end - end)(xpcall(function() - print(123) - return func() - end, function(e) - print(e) - return e - end)) -end)()) -local a = 123 -local _ = setmetatable({ }, { - __close = function() - return print("超出范围。") - end -}) -local a, b, c, d -local _obj_0 = tb -a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] -Constant = 123 -local some_string = "这是一个字符串\n 并包括一个换行。" -print("我有" .. tostring(math.random() * 100) .. "%的把握。") -local integer = 1000000 -local hex = 0xEFBBBF -local binary = 19 -local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) -local fn -fn = function() - local str = "foo:\n bar: baz" - return str -end -local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" -local my_function -my_function = function() end -my_function() -local func_a -func_a = function() - return print("你好,世界") -end -local func_b -func_b = function() - local value = 100 - return print("这个值是:", value) -end -func_a() -func_b() -local sum -sum = function(x, y) - return print("数字的和", x + y) -end -sum(10, 20) -print(sum(10, 20)) -a(b(c("a", "b", "c"))) -print("x:", sum(10, 20), "y:", sum(30, 40)) -local sum -sum = function(x, y) - return x + y -end -print("数字的和是", sum(10, 20)) -local sum -sum = function(x, y) - return x + y -end -local mystery -mystery = function(x, y) - return x + y, x - y -end -local a, b = mystery(10, 20) -local func -func = function(self, num) - return self.value + num -end -local my_function -my_function = function(name, height) - if name == nil then - name = "某物" - end - if height == nil then - height = 100 - end - print("你好,我是", name) - return print("我的高度是", height) -end -local some_args -some_args = function(x, y) - if x == nil then - x = 100 - end - if y == nil then - y = x + 1000 - end - return print(x + y) -end -my_func(5, 4, 3, 8, 9, 10) -cool_func(1, 2, 3, 4, 5, 6, 7, 8) -my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4) -local x = { - 1, - 2, - 3, - 4, - a_func(4, 5, 5, 6), - 8, - 9, - 10 -} -local y = { - my_func(1, 2, 3, 4, 5), - 5, - 6, - 7 -} -if func(1, 2, 3, "你好", "世界") then - print("你好") - print("我在if内部") -end -if func(1, 2, 3, "你好", "世界") then - print("你好") - print("我在if内部") -end -local f1 -f1 = function(_arg_0) - local a, b, c - a, b, c = _arg_0.a, _arg_0.b, _arg_0.c - return print(a, b, c) -end -f1({ - a = 1, - b = "2", - c = { } -}) -local f2 -f2 = function(_arg_0, c) - local a1, b - a1, b = _arg_0.a, _arg_0.b - if a1 == nil then - a1 = 123 - end - if b == nil then - b = 'abc' - end - if c == nil then - c = { } - end - return print(a1, b, c) -end -local arg1 = { - a = 0 -} -f2(arg1, arg2) -local findFirstEven -findFirstEven = function(list) - for _index_0 = 1, #list do - local item = list[_index_0] - if type(item) == "table" then - for _index_1 = 1, #item do - local sub = item[_index_1] - if sub % 2 == 0 then - return sub - end - end - end - end - return nil -end -local findFirstEven -findFirstEven = function(list) - for _index_0 = 1, #list do - local item = list[_index_0] - if type(item) == "table" then - for _index_1 = 1, #item do - local sub = item[_index_1] - if sub % 2 == 0 then - return sub - end - end - end - end - return nil -end -local f -f = function(...) - local t = { - n = select("#", ...), - ... - } - print("参数个数:", t.n) - print("表长度:", #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) -f(function(self) - return print(self.value) -end) -map(function(x) - return x * 2 -end, { - 1, - 2, - 3 -}) -local result, msg -do - result, msg = readAsync("文件名.txt", function(data) - print(data) - return processAsync(data, function(info) - return check(info) - end) - end) -end -print(result, msg) -local some_values = { - 1, - 2, - 3, - 4 -} -local some_values = { - name = "Bill", - age = 200, - ["favorite food"] = "rice" -} -local profile = { - height = "4英尺", - shoe_size = 13, - favorite_foods = { - "冰淇淋", - "甜甜圈" - } -} -local values = { - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - name = "超人", - occupation = "打击犯罪" -} -my_function({ - dance = "探戈", - partner = "无" -}) -local y = { - type = "狗", - legs = 4, - tails = 1 -} -local tbl = { - ["do"] = "某事", - ["end"] = "饥饿" -} -local hair = "金色" -local height = 200 -local person = { - hair = hair, - height = height, - shoe_size = 40 -} -print_table({ - hair = hair, - height = height -}) -local t = { - [1 + 2] = "你好", - ["你好 世界"] = true -} -local some_values = { - 1, - 2, - 3, - 4 -} -local list_with_one_element = { - 1 -} -local items = { - 1, - 2, - 3, - 4 -} -local doubled -local _accum_0 = { } -local _len_0 = 1 -for i, item in ipairs(items) do - _accum_0[_len_0] = item * 2 - _len_0 = _len_0 + 1 -end -doubled = _accum_0 -local slice -local _accum_0 = { } -local _len_0 = 1 -for i, item in ipairs(items) do - if i > 1 and i < 3 then - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end -end -slice = _accum_0 -local doubled -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -for _index_0 = 1, #_list_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item * 2 - _len_0 = _len_0 + 1 -end -doubled = _accum_0 -local data = { - a = { - 1, - 2, - 3 - }, - b = { - 4, - 5, - 6 - } -} -local flat -local _accum_0 = { } -for k, v in pairs(data) do - local _len_0 = #_accum_0 + 1 - for _index_0 = 1, #v do - local _elm_0 = v[_index_0] - _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1 - end -end -flat = _accum_0 -local x_coords = { - 4, - 5, - 6, - 7 -} -local y_coords = { - 9, - 2, - 3 -} -local points -local _accum_0 = { } -local _len_0 = 1 -for _index_0 = 1, #x_coords do - local x = x_coords[_index_0] - for _index_1 = 1, #y_coords do - local y = y_coords[_index_1] - _accum_0[_len_0] = { - x, - y - } - _len_0 = _len_0 + 1 - end -end -points = _accum_0 -local evens -local _accum_0 = { } -local _len_0 = 1 -for i = 1, 100 do - if i % 2 == 0 then - _accum_0[_len_0] = i - _len_0 = _len_0 + 1 - end -end -evens = _accum_0 -local thing = { - color = "red", - name = "fast", - width = 123 -} -local thing_copy -local _tbl_0 = { } -for k, v in pairs(thing) do - _tbl_0[k] = v -end -thing_copy = _tbl_0 -local no_color -local _tbl_0 = { } -for k, v in pairs(thing) do - if k ~= "color" then - _tbl_0[k] = v - end -end -no_color = _tbl_0 -local numbers = { - 1, - 2, - 3, - 4 -} -local sqrts -local _tbl_0 = { } -for _index_0 = 1, #numbers do - local i = numbers[_index_0] - _tbl_0[i] = math.sqrt(i) -end -sqrts = _tbl_0 -local tuples = { - { - "hello", - "world" - }, - { - "foo", - "bar" - } -} -local tbl -local _tbl_0 = { } -for _index_0 = 1, #tuples do - local tuple = tuples[_index_0] - local _key_0, _val_0 = unpack(tuple) - _tbl_0[_key_0] = _val_0 -end -tbl = _tbl_0 -local slice -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -for _index_0 = 1, 5 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 -end -slice = _accum_0 -local slice -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -local _max_0 = #_list_0 -for _index_0 = 2, _max_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 -end -slice = _accum_0 -local slice -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -local _max_0 = #_list_0 -for _index_0 = 1, _max_0, 2 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 -end -slice = _accum_0 -local slice -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -local _min_0 = #_list_0 + -4 + 1 -local _max_0 = #_list_0 + -1 + 1 -for _index_0 = _min_0, _max_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 -end -slice = _accum_0 -local reverse_slice -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -local _min_0 = #_list_0 + -1 + 1 -for _index_0 = _min_0, 1, -1 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 -end -reverse_slice = _accum_0 -local sub_list -local _accum_0 = { } -local _len_0 = 1 -local _list_0 = items -for _index_0 = 2, 4 do - local _item_0 = _list_0[_index_0] - _accum_0[_len_0] = _item_0 - _len_0 = _len_0 + 1 -end -sub_list = _accum_0 -for i = 10, 20 do - print(i) -end -for k = 1, 15, 2 do - print(k) -end -for key, value in pairs(object) do - print(key, value) -end -local _list_0 = items -for _index_0 = 2, 4 do - local item = _list_0[_index_0] - print(item) -end -local _list_0 = items -for _index_0 = 1, #_list_0 do - local item = _list_0[_index_0] - print(item) -end -for j = 1, 10, 3 do - print(j) -end -local doubled_evens -local _accum_0 = { } -local _len_0 = 1 -for i = 1, 20 do - if i % 2 == 0 then - _accum_0[_len_0] = i * 2 - _len_0 = _len_0 + 1 - else - _accum_0[_len_0] = i - _len_0 = _len_0 + 1 - end -end -doubled_evens = _accum_0 -local first_large -local _accum_0 -local _list_0 = numbers -for _index_0 = 1, #_list_0 do - local n = _list_0[_index_0] - if n > 10 then - _accum_0 = n - break - end -end -first_large = _accum_0 -local func_a -func_a = function() - for i = 1, 10 do - print(i) - end -end -local func_b -func_b = function() - local _accum_0 = { } - local _len_0 = 1 - for i = 1, 10 do - _accum_0[_len_0] = i - _len_0 = _len_0 + 1 - end - return _accum_0 -end -print(func_a()) -print(func_b()) -local i = 10 -repeat - print(i) - i = i - 1 -until i == 0 -local i = 10 -while i > 0 do - print(i) - i = i - 1 -end -while running == true do - my_function() -end -local i = 10 -while not (i == 0) do - print(i) - i = i - 1 -end -while not (running == false) do - my_function() -end -local i = 0 -while i < 10 do - i = i + 1 - if i % 2 == 0 then - goto _continue_0 - end - print(i) - ::_continue_0:: -end -local my_numbers = { - 1, - 2, - 3, - 4, - 5, - 6 -} -local odds -local _accum_0 = { } -local _len_0 = 1 -for _index_0 = 1, #my_numbers do - local x = my_numbers[_index_0] - if x % 2 == 1 then - goto _continue_0 - end - _accum_0[_len_0] = x - _len_0 = _len_0 + 1 - ::_continue_0:: -end -odds = _accum_0 -local have_coins = false -if have_coins then - print("有硬币") -else - print("没有硬币") -end -local have_coins = false -if have_coins then - print("有硬币") -else - print("没有硬币") -end -local have_coins = false -print((function() - if have_coins then - return "有硬币" - else - return "没有硬币" - end -end)()) -local is_tall -is_tall = function(name) - if name == "Rob" then - return true - else - return false - end -end -local message -if is_tall("Rob") then - message = "我很高" -else - message = "我不是很高" -end -print(message) -if not (os.date("%A") == "Monday") then - print("今天不是星期一!") -end -if not (math.random() > 0.1) then - print("你真幸运!") -end -local a = 5 -if (1 == a or 3 == a or 5 == a or 7 == a) then - print("检查离散值的相等性") -end -if (function() - local _check_0 = list - for _index_0 = 1, #_check_0 do - if _check_0[_index_0] == a then - return true - end - end - return false -end)() then - print("检查`a`是否在列表中") -end -if not (math.random() > 0.1) then - print("你很幸运!") -end -if name == "Rob" then - print("你好,世界") -end -local _list_0 = items -for _index_0 = 1, #_list_0 do - local item = _list_0[_index_0] - print("项目: ", item) -end -while game:isRunning() do - game:update() -end -while not reader:eof() do - reader:parse_line() -end -local name = "Dan" -if "Robert" == name then - print("你是Robert") -elseif "Dan" == name or "Daniel" == name then - print("你的名字是Dan") -else - print("我不认识你,你的名字是" .. tostring(name)) -end -local b = 1 -local next_number -if 1 == b then - next_number = 2 -elseif 2 == b then - next_number = 3 -else - next_number = error("数字数得太大了!") -end -local msg -local _exp_0 = math.random(1, 5) -if 1 == _exp_0 then - msg = "你很幸运" -elseif 2 == _exp_0 then - msg = "你差点很幸运" -else - msg = "不太幸运" -end -do - local _exp_0 = math.random(1, 5) - if 1 == _exp_0 then - print("你很幸运") - else - print("不太幸运") - end -end -local _exp_0 = math.random(1, 5) -if 1 == _exp_0 then - print("你很幸运") -else - print("不太幸运") -end -local items = { - { - x = 100, - y = 200 - }, - { - width = 300, - height = 400 - } -} -for _index_0 = 1, #items do - local item = items[_index_0] - local _type_0 = type(item) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false - if _tab_0 then - local x = item.x - local y = item.y - if x ~= nil and y ~= nil then - _match_0 = true - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) - end - end - if not _match_0 then - if _tab_0 then - local width = item.width - local height = item.height - if width ~= nil and height ~= nil then - print("尺寸 " .. tostring(width) .. ", " .. tostring(height)) - end - end - end -end -local item = { } -local x, y = item.pos.x, item.pos.y -if x == nil then - x = 50 -end -if y == nil then - y = 200 -end -local _type_0 = type(item) -local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -if _tab_0 then - do - local _obj_0 = item.pos - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - x = _obj_0.x - end - end - do - local _obj_0 = item.pos - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - y = _obj_0.y - end - end - if x == nil then - x = 50 - end - if y == nil then - y = 200 - end - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) -end -local _exp_0 = tb -local _type_0 = type(_exp_0) -local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -local _match_0 = false -if _tab_0 then - if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then - _match_0 = true - print("1, 2, 3") - end -end -if not _match_0 then - local _match_1 = false - if _tab_0 then - local b = _exp_0[2] - if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then - _match_1 = true - print("1, " .. tostring(b) .. ", 3") - end - end - if not _match_1 then - if _tab_0 then - local b = _exp_0[3] - if b == nil then - b = 3 - end - if 1 == _exp_0[1] and 2 == _exp_0[2] then - print("1, 2, " .. tostring(b)) - end - end - end -end -local _exp_0 = tb -local _type_0 = type(_exp_0) -local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -local _match_0 = false -if _tab_0 then - local result = _exp_0.result - if true == _exp_0.success and result ~= nil then - _match_0 = true - print("成功", result) - end -end -if not _match_0 then - local _match_1 = false - if _tab_0 then - if false == _exp_0.success then - _match_1 = true - print("失败", result) - end - end - if not _match_1 then - print("无效值") - end -end -local _exp_0 = tb -local _type_0 = type(_exp_0) -local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -local _match_0 = false -if _tab_0 then - local content - do - local _obj_0 = _exp_0.data - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - content = _obj_0.content - end - end - local _val_0 - do - local _obj_0 = _exp_0.data - if _obj_0 ~= nil then - _val_0 = _obj_0.type - end - end - if "success" == _val_0 and content ~= nil then - _match_0 = true - print("成功", content) - end -end -if not _match_0 then - local _match_1 = false - if _tab_0 then - local content - do - local _obj_0 = _exp_0.data - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - content = _obj_0.content - end - end - local _val_0 - do - local _obj_0 = _exp_0.data - if _obj_0 ~= nil then - _val_0 = _obj_0.type - end - end - if "error" == _val_0 and content ~= nil then - _match_1 = true - print("失败", content) - end - end - if not _match_1 then - print("无效值") - end -end -local _exp_0 = tb -local _type_0 = type(_exp_0) -local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -if _tab_0 then - local fourth = _exp_0[4] - local _val_0 - do - local _obj_0 = _exp_0[1] - if _obj_0 ~= nil then - _val_0 = _obj_0.a - end - end - local _val_1 - do - local _obj_0 = _exp_0[1] - if _obj_0 ~= nil then - _val_1 = _obj_0.b - end - end - local _val_2 - do - local _obj_0 = _exp_0[2] - if _obj_0 ~= nil then - _val_2 = _obj_0.a + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end + }) + _base_0.__class = _class_0 + if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) end - local _val_3 - do - local _obj_0 = _exp_0[2] - if _obj_0 ~= nil then - _val_3 = _obj_0.b - end + BigBucket = _class_0 +end +assert(Bucket.__name == "BigBucket") +local x +local _class_0 +local _base_0 = { } +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "x" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - local _val_4 - do - local _obj_0 = _exp_0[3] - if _obj_0 ~= nil then - _val_4 = _obj_0.a +}) +_base_0.__class = _class_0 +x = _class_0 +local MyIndex = { + __index = { + var = 1 + } +} +local X +do + local _class_0 + local _base_0 = { + func = function(self) + return print(123) end - end - local _val_5 - do - local _obj_0 = _exp_0[3] - if _obj_0 ~= nil then - _val_5 = _obj_0.b + } + local _list_0 = { + MyIndex + } + for _index_0 = 1, #_list_0 do + local _item_0 = _list_0[_index_0] + local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0 + for _key_0, _val_0 in pairs(_mixin_0) do + if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then + _base_0[_key_0] = _val_0 + end end end - if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then - print("匹配成功", fourth) + if _base_0.__index == nil then + _base_0.__index = _base_0 end + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "X" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_0.__class = _class_0 + X = _class_0 end -local segments = { - "admin", - "users", - "logs", - "view" -} -local _type_0 = type(segments) -local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -if _tab_0 then - local groups - do - local _accum_0 = { } - local _len_0 = 1 - local _max_0 = #segments + -3 + 1 - for _index_0 = 1, _max_0 do - local _item_0 = segments[_index_0] - _accum_0[_len_0] = _item_0 - _len_0 = _len_0 + 1 +local x = X() +print(x.var) +local Y +do + local _class_0 + local _base_0 = { } + local _list_0 = { + X + } + for _index_0 = 1, #_list_0 do + local _item_0 = _list_0[_index_0] + local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0 + for _key_0, _val_0 in pairs(_mixin_0) do + if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then + _base_0[_key_0] = _val_0 + end end - groups = _accum_0 end - local resource = segments[#segments - 1] - local action = segments[#segments] - if resource ~= nil and action ~= nil then - print("Group:", groups) - print("Resource:", resource) - print("Action:", action) + if _base_0.__index == nil then + _base_0.__index = _base_0 end + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Y" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_0.__class = _class_0 + Y = _class_0 end +local y = Y() +y:func() +assert(y.__class.__parent ~= X) local Inventory local _class_0 local _base_0 = { @@ -5038,6 +4970,67 @@ local _with_0 = obj if _with_0 ~= nil then print(obj.name) end +local _with_0 = Person() +_with_0.name = "Oswald" +_with_0:add_relative(my_dad) +_with_0:save() +print(_with_0.name) +local file +local _with_0 = File("favorite_foods.txt") +_with_0:set_encoding("utf8") +file = _with_0 +local create_person +create_person = function(name, relatives) + local _with_0 = Person() + _with_0.name = name + for _index_0 = 1, #relatives do + local relative = relatives[_index_0] + _with_0:add_relative(relative) + end + return _with_0 +end +local me = create_person("Leaf", { + dad, + mother, + sister +}) +local str = "你好" +print("原始:", str) +print("大写:", str:upper()) +local _with_0 = tb +_with_0[1] = 1 +print(_with_0[2]) +do + local _with_1 = _with_0[abc] + _with_1[3] = _with_1[2]:func() + _with_1["key-name"] = value +end +_with_0[#_with_0 + 1] = "abc" +local _with_0 = obj +if _with_0 ~= nil then + print(obj.name) +end +do + local var = "hello" + print(var) +end +print(var) +local counter +do + local i = 0 + counter = function() + i = i + 1 + return i + end +end +print(counter()) +print(counter()) +local tbl = { + key = (function() + print("分配键值!") + return 1234 + end)() +} do local var = "hello" print(var) @@ -5078,6 +5071,53 @@ run_callback((function() return _fn_0(_base_0, ...) end end)()) +local my_object = { + value = 1000, + write = function(self) + return print("值为:", self.value) + end +} +local run_callback +run_callback = function(func) + print("运行回调...") + return func() +end +run_callback(my_object.write) +run_callback((function() + local _base_0 = my_object + local _fn_0 = _base_0.write + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end +end)()) +local i = 100 +local my_func +my_func = function() + i = 10 + while i > 0 do + print(i) + i = i - 1 + end +end +my_func() +print(i) +local i = 100 +local my_func +my_func = function() + local i = "hello" +end +my_func() +print(i) +local tmp = 1213 +local i, k = 100, 50 +local my_func +my_func = function(add) + local tmp = tmp + add + i = i + tmp + k = k + tmp +end +my_func(22) +print(i, k) local i = 100 local my_func my_func = function() diff --git a/spec/outputs/compile_doc.lua b/spec/outputs/compile_doc.lua index e7d307d..cb359a1 100644 --- a/spec/outputs/compile_doc.lua +++ b/spec/outputs/compile_doc.lua @@ -2,52 +2,113 @@ local outputFolder = ... local _list_0 = { { "codes_from_doc.lua", - "doc/docs/doc/index.md" + { + "doc/docs/doc/introduction.md", + "doc/docs/doc/macro.md", + "doc/docs/doc/operator.md", + "doc/docs/doc/module.md", + "doc/docs/doc/assignment.md", + "doc/docs/doc/destructuring-assignment.md", + "doc/docs/doc/if-assignment.md", + "doc/docs/doc/varargs-assignment.md", + "doc/docs/doc/whitespace.md", + "doc/docs/doc/comment.md", + "doc/docs/doc/try.md", + "doc/docs/doc/attributes.md", + "doc/docs/doc/literals.md", + "doc/docs/doc/function-literals.md", + "doc/docs/doc/backcalls.md", + "doc/docs/doc/table-literals.md", + "doc/docs/doc/comprehensions.md", + "doc/docs/doc/for-loop.md", + "doc/docs/doc/while-loop.md", + "doc/docs/doc/continue.md", + "doc/docs/doc/conditionals.md", + "doc/docs/doc/line-decorators.md", + "doc/docs/doc/switch.md", + "doc/docs/doc/object-oriented-programming.md", + "doc/docs/doc/with-statement.md", + "doc/docs/doc/do.md", + "doc/docs/doc/function-stubs.md", + "doc/docs/doc/the-using-clause-controlling-destructive-assignment.md" + } }, { "codes_from_doc_zh.lua", - "doc/docs/zh/doc/index.md" + { + "doc/docs/zh/doc/introduction.md", + "doc/docs/zh/doc/macro.md", + "doc/docs/zh/doc/operator.md", + "doc/docs/zh/doc/module.md", + "doc/docs/zh/doc/assignment.md", + "doc/docs/zh/doc/destructuring-assignment.md", + "doc/docs/zh/doc/if-assignment.md", + "doc/docs/zh/doc/varargs-assignment.md", + "doc/docs/zh/doc/whitespace.md", + "doc/docs/zh/doc/comment.md", + "doc/docs/zh/doc/try.md", + "doc/docs/zh/doc/attributes.md", + "doc/docs/zh/doc/literals.md", + "doc/docs/zh/doc/function-literals.md", + "doc/docs/zh/doc/backcalls.md", + "doc/docs/zh/doc/table-literals.md", + "doc/docs/zh/doc/comprehensions.md", + "doc/docs/zh/doc/for-loop.md", + "doc/docs/zh/doc/while-loop.md", + "doc/docs/zh/doc/continue.md", + "doc/docs/zh/doc/conditionals.md", + "doc/docs/zh/doc/line-decorators.md", + "doc/docs/zh/doc/switch.md", + "doc/docs/zh/doc/object-oriented-programming.md", + "doc/docs/zh/doc/with-statement.md", + "doc/docs/zh/doc/do.md", + "doc/docs/zh/doc/function-stubs.md", + "doc/docs/zh/doc/the-using-clause-controlling-destructive-assignment.md" + } } } for _index_0 = 1, #_list_0 do local _des_0 = _list_0[_index_0] - local compiledFile, docFile = _des_0[1], _des_0[2] - local input - local _with_0 = io.open(docFile) - if _with_0 ~= nil then - local to_lua = require("yue").to_lua - local text = _with_0:read("*a") - local codes = { } - for code in text:gmatch("```yuescript[\r\n]+(.-)```[^%w]") do - local result, err = to_lua(code, { - implicit_return_root = false, - reserve_line_number = false - }) - if result then - codes[#codes + 1] = result - elseif not err:match("macro exporting module only accepts macro definition") then - print(err) - os.exit(1) + local compiledFile, docFiles = _des_0[1], _des_0[2] + local codes = { } + for _index_1 = 1, #docFiles do + local docFile = docFiles[_index_1] + local input + local _with_0 = io.open(docFile) + if _with_0 ~= nil then + local to_lua = require("yue").to_lua + local text = _with_0:read("*a") + for code in text:gmatch("```yuescript[\r\n]+(.-)```[^%w]") do + local result, err = to_lua(code, { + implicit_return_root = false, + reserve_line_number = false + }) + if result then + codes[#codes + 1] = result + elseif not err:match("macro exporting module only accepts macro definition") then + print(err) + os.exit(1) + end end - end - for code in text:gmatch("```yue[\r\n]+(.-)```[^%w]") do - local result, err = to_lua(code, { - implicit_return_root = false, - reserve_line_number = false - }) - if result then - codes[#codes + 1] = result - else - print(err) - os.exit(1) + for code in text:gmatch("```yue[\r\n]+(.-)```[^%w]") do + local result, err = to_lua(code, { + implicit_return_root = false, + reserve_line_number = false + }) + if result then + codes[#codes + 1] = result + else + print(err) + os.exit(1) + end end end - local output - local _with_1 = io.open(tostring(outputFolder) .. "/" .. tostring(compiledFile), "w+") - _with_1:write(table.concat(codes)) - output = _with_1 - local _close_0 = output + input = _with_0 + local _close_0 = input end - input = _with_0 - local _close_0 = input + local output + local _with_0 = io.open(tostring(outputFolder) .. "/" .. tostring(compiledFile), "w+") + _with_0:write(table.concat(codes)) + output = _with_0 + local _close_0 = output end -- cgit v1.2.3-55-g6feb