aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/codes_from_doc_zh.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/outputs/codes_from_doc_zh.lua')
-rw-r--r--spec/outputs/codes_from_doc_zh.lua3916
1 files changed, 1978 insertions, 1938 deletions
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,84 @@ end
76local _u1f31b = "月之脚本" 76local _u1f31b = "月之脚本"
77_module_0["🌛"] = _u1f31b 77_module_0["🌛"] = _u1f31b
78return _module_0 78return _module_0
79local _module_0 = { }
80local p, to_lua
81do
82 local _obj_0 = require("yue")
83 p, to_lua = _obj_0.p, _obj_0.to_lua
84end
85local inventory = {
86 equipment = {
87 "sword",
88 "shield"
89 },
90 items = {
91 {
92 name = "potion",
93 count = 10
94 },
95 {
96 name = "bread",
97 count = 3
98 }
99 }
100}
101local map
102map = function(arr, action)
103 local _accum_0 = { }
104 local _len_0 = 1
105 for _index_0 = 1, #arr do
106 local item = arr[_index_0]
107 _accum_0[_len_0] = action(item)
108 _len_0 = _len_0 + 1
109 end
110 return _accum_0
111end
112local filter
113filter = function(arr, cond)
114 local _accum_0 = { }
115 local _len_0 = 1
116 for _index_0 = 1, #arr do
117 local item = arr[_index_0]
118 if cond(item) then
119 _accum_0[_len_0] = item
120 _len_0 = _len_0 + 1
121 end
122 end
123 return _accum_0
124end
125local reduce
126reduce = function(arr, init, action)
127 for _index_0 = 1, #arr do
128 local item = arr[_index_0]
129 init = action(init, item)
130 end
131 return init
132end
133print(reduce(filter(map({
134 1,
135 2,
136 3
137}, function(x)
138 return x * 2
139end), function(x)
140 return x > 4
141end), 0, function(a, b)
142 return a + b
143end))
144local apple = setmetatable({
145 size = 15,
146}, {
147 __index = {
148 color = 0x00ffff
149 }
150})
151if (getmetatable(apple) ~= nil) then
152 p(apple.size, apple.color, getmetatable(apple).__index)
153end
154local _u1f31b = "月之脚本"
155_module_0["🌛"] = _u1f31b
156return _module_0
79local area = 6.2831853071796 * 5 157local area = 6.2831853071796 * 5
80print('你好 世界') 158print('你好 世界')
81do 159do
@@ -115,6 +193,338 @@ end
115do 193do
116 print(123, "hello") 194 print(123, "hello")
117end 195end
196local area = 6.2831853071796 * 5
197print('你好 世界')
198do
199 assert(item ~= nil)
200end
201local value = item
202if (f1() and f2() and f3()) then
203 print("OK")
204end
205do
206 local funcA
207 funcA = function() end
208end
209local funcA
210funcA = function()
211 return "无法访问宏生成月之脚本里定义的变量"
212end
213do
214local function funcB() end
215end
216local funcB
217funcB = function()
218 return "无法访问宏生成 Lua 代码里定义的变量"
219end
220do
221-- 插入原始Lua代码
222if cond then
223 print("输出")
224end
225end
226print("yuescript")
227print(2)
228print("有效的枚举类型:", "Static")
229do
230 print(123, "hello")
231end
232do
233 print(123, "hello")
234end
235if tb ~= nil then
236 tb:func()
237end
238if tb ~= nil then
239 tb:func()
240end
241print(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)
242local a = 5
243print(1 <= a and a <= 10)
244local v
245v = function(x)
246 print(x)
247 return x
248end
249print((function()
250 local _cond_0 = v(2)
251 if not (v(1) < _cond_0) then
252 return false
253 else
254 return _cond_0 <= v(3)
255 end
256end)())
257print((function()
258 local _cond_0 = v(2)
259 if not (v(1) > _cond_0) then
260 return false
261 else
262 return _cond_0 <= v(3)
263 end
264end)())
265local tab = { }
266tab[#tab + 1] = "Value"
267local tbA = {
268 1,
269 2,
270 3
271}
272local tbB = {
273 4,
274 5,
275 6
276}
277local _len_0 = #tbA + 1
278for _index_0 = 1, #tbB do
279 local _elm_0 = tbB[_index_0]
280 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
281end
282local parts = {
283 "shoulders",
284 "knees"
285}
286local lyrics
287do
288 local _tab_0 = {
289 "head"
290 }
291 local _idx_0 = 1
292 for _key_0, _value_0 in pairs(parts) do
293 if _idx_0 == _key_0 then
294 _tab_0[#_tab_0 + 1] = _value_0
295 _idx_0 = _idx_0 + 1
296 else
297 _tab_0[_key_0] = _value_0
298 end
299 end
300 _tab_0[#_tab_0 + 1] = "and"
301 _tab_0[#_tab_0 + 1] = "toes"
302 lyrics = _tab_0
303end
304local copy
305do
306 local _tab_0 = { }
307 local _idx_0 = 1
308 for _key_0, _value_0 in pairs(other) do
309 if _idx_0 == _key_0 then
310 _tab_0[#_tab_0 + 1] = _value_0
311 _idx_0 = _idx_0 + 1
312 else
313 _tab_0[_key_0] = _value_0
314 end
315 end
316 copy = _tab_0
317end
318local a = {
319 1,
320 2,
321 3,
322 x = 1
323}
324local b = {
325 4,
326 5,
327 y = 1
328}
329local merge
330local _tab_0 = { }
331local _idx_0 = 1
332for _key_0, _value_0 in pairs(a) do
333 if _idx_0 == _key_0 then
334 _tab_0[#_tab_0 + 1] = _value_0
335 _idx_0 = _idx_0 + 1
336 else
337 _tab_0[_key_0] = _value_0
338 end
339end
340local _idx_1 = 1
341for _key_0, _value_0 in pairs(b) do
342 if _idx_1 == _key_0 then
343 _tab_0[#_tab_0 + 1] = _value_0
344 _idx_1 = _idx_1 + 1
345 else
346 _tab_0[_key_0] = _value_0
347 end
348end
349merge = _tab_0
350local last
351do
352 local _item_0 = data.items
353 last = _item_0[#_item_0]
354end
355local second_last
356do
357 local _item_0 = data.items
358 second_last = _item_0[#_item_0 - 1]
359end
360local _obj_0 = data.items
361_obj_0[#_obj_0] = 1
362local mt = { }
363local add
364add = function(self, right)
365 return setmetatable({
366 value = self.value + right.value
367 }, mt)
368end
369mt.__add = add
370local a = setmetatable({
371 value = 1
372}, mt)
373local b = setmetatable({
374 value = 2
375}, {
376 __add = add
377})
378local c = setmetatable({
379 value = 3
380}, {
381 __add = mt.__add
382})
383local d = a + b + c
384print(d.value)
385local _ <close> = setmetatable({ }, {
386 __close = function()
387 return print("超出范围")
388 end
389})
390local tb = setmetatable({ }, {
391 ["value"] = 123
392})
393getmetatable(tb).__index = getmetatable(tb)
394print(tb.value)
395setmetatable(tb, {
396 __index = {
397 item = "hello"
398 }
399})
400print(tb.item)
401local item, new, close, getter
402do
403 local _obj_0 = tb
404 item, new = _obj_0[1], _obj_0.new
405 do
406 local _obj_1 = getmetatable(_obj_0)
407 close, getter = _obj_1.__close, _obj_1.__index
408 end
409end
410print(item, new, close, getter)
411do
412 local _obj_0 = func
413 if _obj_0 ~= nil then
414 _obj_0()
415 end
416end
417print((function()
418 local _obj_0 = abc
419 if _obj_0 ~= nil then
420 local _obj_1 = _obj_0["你好 世界"]
421 if _obj_1 ~= nil then
422 return _obj_1.xyz
423 end
424 return nil
425 end
426 return nil
427end)())
428local x
429do
430 local _obj_0 = tab
431 if _obj_0 ~= nil then
432 x = _obj_0.value
433 end
434end
435local len = (function()
436 local _obj_0 = utf8
437 if _obj_0 ~= nil then
438 return _obj_0.len
439 end
440 return nil
441end)() or (function()
442 local _obj_0 = string
443 if _obj_0 ~= nil then
444 return _obj_0.len
445 end
446 return nil
447end)() or function(o)
448 return #o
449end
450if print and (x ~= nil) then
451 print(x)
452end
453local _with_0 = io.open("test.txt", "w")
454if _with_0 ~= nil then
455 _with_0:write("你好")
456 _with_0:close()
457end
458print("你好")
459print(1, 2)
460print(1, 2, 3)
461print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
462local a, b, c, d
463if b ~= nil then
464 a = b
465else
466 if c ~= nil then
467 a = c
468 else
469 a = d
470 end
471end
472func((function()
473 if a ~= nil then
474 return a
475 else
476 return { }
477 end
478end)())
479if a == nil then
480 a = false
481end
482local list = {
483 1,
484 2,
485 3
486}
487func({
488 1,
489 2,
490 3
491})
492local f
493f = function()
494 return {
495 1,
496 2,
497 3
498 }
499end
500local tb = {
501 name = "abc",
502 values = {
503 "a",
504 "b",
505 "c"
506 },
507 objects = {
508 {
509 name = "a",
510 value = 1,
511 func = function(self)
512 return self.value + 1
513 end,
514 tb = {
515 fieldA = 1
516 }
517 },
518 {
519 name = "b",
520 value = 2,
521 func = function(self)
522 return self.value + 2
523 end,
524 tb = { }
525 }
526 }
527}
118if tb ~= nil then 528if tb ~= nil then
119 tb:func() 529 tb:func()
120end 530end
@@ -539,6 +949,188 @@ _module_0 = function()
539 return 123 949 return 123
540end 950end
541return _module_0 951return _module_0
952do
953 local insert, concat = table.insert, table.concat
954 local C, Ct, Cmt
955 do
956 local _obj_0 = require("lpeg")
957 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
958 end
959 local x, y, z
960 do
961 local _obj_0 = require('mymodule')
962 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z
963 end
964 local a, b, c
965 local _obj_0 = require('module')
966 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
967end
968do
969 local module = require('module')
970 local module_x = require('module_x')
971 local d_a_s_h_e_s = require("d-a-s-h-e-s")
972 local part = require("module.part")
973end
974do
975 local PlayerModule = require("player")
976 local C, Ct, Cmt
977 do
978 local _obj_0 = require("lpeg")
979 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
980 end
981 local one, two, ch
982 local _obj_0 = require("export")
983 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
984end
985do
986 local tostring <const> = tostring
987 local concat <const> = table.concat
988 print(concat({
989 "a",
990 tostring(1)
991 }))
992end
993do
994 local print <const> = print
995 local math <const> = math
996 print("hello")
997 math.random(3)
998end
999do
1000 local print <const> = print
1001 print(FLAG)
1002 FLAG = 123
1003end
1004local _module_0 = { }
1005local a, b, c = 1, 2, 3
1006_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
1007local cool = "cat"
1008_module_0["cool"] = cool
1009local What
1010if this then
1011 What = "abc"
1012else
1013 What = "def"
1014end
1015_module_0["What"] = What
1016local y
1017y = function()
1018 local hallo = 3434
1019end
1020_module_0["y"] = y
1021local Something
1022local _class_0
1023local _base_0 = {
1024 umm = "cool"
1025}
1026if _base_0.__index == nil then
1027 _base_0.__index = _base_0
1028end
1029_class_0 = setmetatable({
1030 __init = function() end,
1031 __base = _base_0,
1032 __name = "Something"
1033}, {
1034 __index = _base_0,
1035 __call = function(cls, ...)
1036 local _self_0 = setmetatable({ }, _base_0)
1037 cls.__init(_self_0, ...)
1038 return _self_0
1039 end
1040})
1041_base_0.__class = _class_0
1042Something = _class_0
1043_module_0["Something"] = Something
1044return _module_0
1045local _module_0 = { }
1046local loadstring, tolua
1047do
1048 local _obj_0 = yue
1049 loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua
1050end
1051_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua
1052local fieldA = tb.itemA.fieldA
1053if fieldA == nil then
1054 fieldA = '默认值'
1055end
1056_module_0["fieldA"] = fieldA
1057return _module_0
1058local _module_0 = setmetatable({ }, { })
1059_module_0.itemA = tb
1060getmetatable(_module_0).__index = items
1061_module_0["a-b-c"] = 123
1062return _module_0
1063local _module_0 = { }
1064local d, e, f = 3, 2, 1
1065_module_0[#_module_0 + 1] = d
1066_module_0[#_module_0 + 1] = e
1067_module_0[#_module_0 + 1] = f
1068if this then
1069 _module_0[#_module_0 + 1] = 123
1070else
1071 _module_0[#_module_0 + 1] = 456
1072end
1073local _with_0 = tmp
1074local j = 2000
1075_module_0[#_module_0 + 1] = _with_0
1076return _module_0
1077local _module_0 = nil
1078_module_0 = function()
1079 print("你好")
1080 return 123
1081end
1082return _module_0
1083local hello = "world"
1084local a, b, c = 1, 2, 3
1085hello = 123
1086local x = 1
1087x = x + 1
1088x = x - 1
1089x = x * 10
1090x = x / 10
1091x = x % 10
1092local s = s .. "world"
1093local arg = arg or "默认值"
1094local a = 0
1095local b = 0
1096local c = 0
1097local d = 0
1098local e = 0
1099local x = f()
1100local y = x
1101local z = x
1102do
1103 local a = 1
1104 local x, y, z
1105 print("预先声明后续所有变量为局部变量")
1106 x = function()
1107 return 1 + y + z
1108 end
1109 y, z = 2, 3
1110 instance = Item:new()
1111end
1112do
1113 local X = 1
1114 local B
1115 print("只预先声明后续大写的变量为局部变量")
1116 local a = 1
1117 B = 2
1118end
1119do
1120 a = 1
1121 print("预先声明所有变量为全局变量")
1122 x = function()
1123 return 1 + y + z
1124 end
1125 y, z = 2, 3
1126end
1127do
1128 x = 1
1129 print("只预先声明大写的变量为全局变量")
1130 local a = 1
1131 B = 2
1132 local Temp = "一个局部值"
1133end
542local hello = "world" 1134local hello = "world"
543local a, b, c = 1, 2, 3 1135local a, b, c = 1, 2, 3
544hello = 123 1136hello = 123
@@ -707,6 +1299,155 @@ for _index_0 = 1, #tuples do
707 local left, right = _des_0[1], _des_0[2] 1299 local left, right = _des_0[1], _des_0[2]
708 print(left, right) 1300 print(left, right)
709end 1301end
1302local thing = {
1303 1,
1304 2
1305}
1306local a, b = thing[1], thing[2]
1307print(a, b)
1308local obj = {
1309 hello = "world",
1310 day = "tuesday",
1311 length = 20
1312}
1313local hello, the_day = obj.hello, obj.day
1314print(hello, the_day)
1315local day = obj.day
1316local obj2 = {
1317 numbers = {
1318 1,
1319 2,
1320 3,
1321 4
1322 },
1323 properties = {
1324 color = "green",
1325 height = 13.5
1326 }
1327}
1328local first, second = obj2.numbers[1], obj2.numbers[2]
1329print(first, second, color)
1330local first, second, color
1331local _obj_0 = obj2
1332first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
1333local concat, insert
1334local _obj_0 = table
1335concat, insert = _obj_0.concat, _obj_0.insert
1336local mix, max, rand
1337local _obj_0 = math
1338mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
1339local name, job
1340local _obj_0 = person
1341name, job = _obj_0.name, _obj_0.job
1342if name == nil then
1343 name = "nameless"
1344end
1345if job == nil then
1346 job = "jobless"
1347end
1348local two, four
1349local _obj_0 = items
1350two, four = _obj_0[2], _obj_0[4]
1351local orders = {
1352 "first",
1353 "second",
1354 "third",
1355 "fourth",
1356 "last"
1357}
1358local first, bulk, last = orders[1], (function()
1359 local _accum_0 = { }
1360 local _len_0 = 1
1361 local _max_0 = #orders + -2 + 1
1362 for _index_0 = 2, _max_0 do
1363 local _item_0 = orders[_index_0]
1364 _accum_0[_len_0] = _item_0
1365 _len_0 = _len_0 + 1
1366 end
1367 return _accum_0
1368end)(), orders[#orders]
1369print(first)
1370print(bulk)
1371print(last)
1372local first, rest
1373do
1374 local _obj_0 = orders
1375 first, rest = _obj_0[1], (function()
1376 local _accum_0 = { }
1377 local _len_0 = 1
1378 local _max_0 = #_obj_0
1379 for _index_0 = 2, _max_0 do
1380 local _item_0 = _obj_0[_index_0]
1381 _accum_0[_len_0] = _item_0
1382 _len_0 = _len_0 + 1
1383 end
1384 return _accum_0
1385 end)()
1386end
1387local start, last
1388do
1389 local _obj_0 = orders
1390 start, last = (function()
1391 local _accum_0 = { }
1392 local _len_0 = 1
1393 local _max_0 = #_obj_0 + -2 + 1
1394 for _index_0 = 1, _max_0 do
1395 local _item_0 = _obj_0[_index_0]
1396 _accum_0[_len_0] = _item_0
1397 _len_0 = _len_0 + 1
1398 end
1399 return _accum_0
1400 end)(), _obj_0[#_obj_0]
1401end
1402local _obj_0 = orders
1403first, last = _obj_0[1], _obj_0[#_obj_0]
1404local tuples = {
1405 {
1406 "hello",
1407 "world"
1408 },
1409 {
1410 "egg",
1411 "head"
1412 }
1413}
1414for _index_0 = 1, #tuples do
1415 local _des_0 = tuples[_index_0]
1416 local left, right = _des_0[1], _des_0[2]
1417 print(left, right)
1418end
1419local user = database.find_user("moon")
1420if user then
1421 print(user.name)
1422end
1423local hello = os.getenv("hello")
1424if hello then
1425 print("你有 hello", hello)
1426else
1427 local world = os.getenv("world")
1428 if world then
1429 print("你有 world", world)
1430 else
1431 print("什么都没有 :(")
1432 end
1433end
1434do
1435 local success, result = pcall(function()
1436 return "无报错地获取结果"
1437 end)
1438 if success then
1439 print(result)
1440 end
1441end
1442print("好的")
1443repeat
1444 local byte = stream:read_one()
1445 if byte then
1446 print(byte)
1447 else
1448 break
1449 end
1450until false
710local user = database.find_user("moon") 1451local user = database.find_user("moon")
711if user then 1452if user then
712 print(user.name) 1453 print(user.name)
@@ -756,6 +1497,23 @@ end
756 local first = select(1, ...) 1497 local first = select(1, ...)
757 return print(ok, count, first) 1498 return print(ok, count, first)
758end)(fn(true)) 1499end)(fn(true))
1500local list = {
1501 1,
1502 2,
1503 3,
1504 4,
1505 5
1506}
1507local fn
1508fn = function(ok)
1509 return ok, table.unpack(list)
1510end
1511(function(_arg_0, ...)
1512 local ok = _arg_0
1513 local count = select('#', ...)
1514 local first = select(1, ...)
1515 return print(ok, count, first)
1516end)(fn(true))
759local a = 1 1517local a = 1
760local b = 2 1518local b = 2
761print(a + b) 1519print(a + b)
@@ -764,6 +1522,16 @@ Rx.Observable.fromRange(1, 8):filter(function(x)
764end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) 1522end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
765 return value .. '!' 1523 return value .. '!'
766end):subscribe(print) 1524end):subscribe(print)
1525local a = 1
1526local b = 2
1527print(a + b)
1528Rx.Observable.fromRange(1, 8):filter(function(x)
1529 return x % 2 == 0
1530end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
1531 return value .. '!'
1532end):subscribe(print)
1533local str = strA .. strB .. strC
1534func(3000, "192.168.1.1")
767local str = strA .. strB .. strC 1535local str = strA .. strB .. strC
768func(3000, "192.168.1.1") 1536func(3000, "192.168.1.1")
769xpcall(function() 1537xpcall(function()
@@ -846,6 +1614,96 @@ f((function()
846 return e 1614 return e
847 end)) 1615 end))
848end)()) 1616end)())
1617xpcall(function()
1618 return func(1, 2, 3)
1619end, function(err)
1620 return print(yue.traceback(err))
1621end)
1622local success, result = xpcall(function()
1623 return func(1, 2, 3)
1624end, function(err)
1625 return yue.traceback(err)
1626end)
1627xpcall(function()
1628 return func(1, 2, 3)
1629end, function(err)
1630 return print(yue.traceback(err))
1631end)
1632success, result = pcall(function()
1633 return func(1, 2, 3)
1634end)
1635pcall(function()
1636 print("尝试中")
1637 return func(1, 2, 3)
1638end)
1639success, result = xpcall(function()
1640 return func(1, 2, 3)
1641end, function(err)
1642 return print(yue.traceback(err))
1643end)
1644if success then
1645 print(result)
1646end
1647local a, b, c
1648do
1649 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
1650 return func()
1651 end)
1652 if _ok_0 then
1653 a, b, c = _ret_0, _ret_1, _ret_2
1654 end
1655end
1656do
1657 local _exp_0 = ((function()
1658 return (function(_arg_0, ...)
1659 local _ok_0 = _arg_0
1660 if _ok_0 then
1661 return ...
1662 end
1663 end)(pcall(function()
1664 return func()
1665 end))
1666 end)())
1667 if _exp_0 ~= nil then
1668 a = _exp_0
1669 else
1670 a = "default"
1671 end
1672end
1673f((function()
1674 return (function(_arg_0, ...)
1675 local _ok_0 = _arg_0
1676 if _ok_0 then
1677 return ...
1678 end
1679 end)(pcall(function()
1680 return func()
1681 end))
1682end)())
1683f((function()
1684 return (function(_arg_0, ...)
1685 local _ok_0 = _arg_0
1686 if _ok_0 then
1687 return ...
1688 end
1689 end)(xpcall(function()
1690 print(123)
1691 return func()
1692 end, function(e)
1693 print(e)
1694 return e
1695 end))
1696end)())
1697local a <const> = 123
1698local _ <close> = setmetatable({ }, {
1699 __close = function()
1700 return print("超出范围。")
1701 end
1702})
1703local a, b, c, d
1704local _obj_0 = tb
1705a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
1706Constant = 123
849local a <const> = 123 1707local a <const> = 123
850local _ <close> = setmetatable({ }, { 1708local _ <close> = setmetatable({ }, {
851 __close = function() 1709 __close = function()
@@ -868,6 +1726,18 @@ fn = function()
868 return str 1726 return str
869end 1727end
870local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" 1728local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
1729local some_string = "这是一个字符串\n 并包括一个换行。"
1730print("我有" .. tostring(math.random() * 100) .. "%的把握。")
1731local integer = 1000000
1732local hex = 0xEFBBBF
1733local binary = 19
1734local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
1735local fn
1736fn = function()
1737 local str = "foo:\n bar: baz"
1738 return str
1739end
1740local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
871local my_function 1741local my_function
872my_function = function() end 1742my_function = function() end
873my_function() 1743my_function()
@@ -929,6 +1799,12 @@ some_args = function(x, y)
929 end 1799 end
930 return print(x + y) 1800 return print(x + y)
931end 1801end
1802local a = x - 10
1803local b = x - 10
1804local c = x(-y)
1805local d = x - z
1806local x = func("hello") + 100
1807local y = func("hello" + 100)
932my_func(5, 4, 3, 8, 9, 10) 1808my_func(5, 4, 3, 8, 9, 10)
933cool_func(1, 2, 3, 4, 5, 6, 7, 8) 1809cool_func(1, 2, 3, 4, 5, 6, 7, 8)
934my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4) 1810my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
@@ -1046,8 +1922,215 @@ process = function(...)
1046 return sum 1922 return sum
1047end 1923end
1048process(1, nil, 3, nil, 5) 1924process(1, nil, 3, nil, 5)
1049f(function() 1925local my_function
1050 return print("hello") 1926my_function = function() end
1927my_function()
1928local func_a
1929func_a = function()
1930 return print("你好,世界")
1931end
1932local func_b
1933func_b = function()
1934 local value = 100
1935 return print("这个值是:", value)
1936end
1937func_a()
1938func_b()
1939local sum
1940sum = function(x, y)
1941 return print("数字的和", x + y)
1942end
1943sum(10, 20)
1944print(sum(10, 20))
1945a(b(c("a", "b", "c")))
1946print("x:", sum(10, 20), "y:", sum(30, 40))
1947local sum
1948sum = function(x, y)
1949 return x + y
1950end
1951print("数字的和是", sum(10, 20))
1952local sum
1953sum = function(x, y)
1954 return x + y
1955end
1956local mystery
1957mystery = function(x, y)
1958 return x + y, x - y
1959end
1960local a, b = mystery(10, 20)
1961local func
1962func = function(self, num)
1963 return self.value + num
1964end
1965local my_function
1966my_function = function(name, height)
1967 if name == nil then
1968 name = "某物"
1969 end
1970 if height == nil then
1971 height = 100
1972 end
1973 print("你好,我是", name)
1974 return print("我的高度是", height)
1975end
1976local some_args
1977some_args = function(x, y)
1978 if x == nil then
1979 x = 100
1980 end
1981 if y == nil then
1982 y = x + 1000
1983 end
1984 return print(x + y)
1985end
1986local a = x - 10
1987local b = x - 10
1988local c = x(-y)
1989local d = x - z
1990local x = func("hello") + 100
1991local y = func("hello" + 100)
1992my_func(5, 4, 3, 8, 9, 10)
1993cool_func(1, 2, 3, 4, 5, 6, 7, 8)
1994my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
1995local x = {
1996 1,
1997 2,
1998 3,
1999 4,
2000 a_func(4, 5, 5, 6),
2001 8,
2002 9,
2003 10
2004}
2005local y = {
2006 my_func(1, 2, 3, 4, 5),
2007 5,
2008 6,
2009 7
2010}
2011if func(1, 2, 3, "你好", "世界") then
2012 print("你好")
2013 print("我在if内部")
2014end
2015if func(1, 2, 3, "你好", "世界") then
2016 print("你好")
2017 print("我在if内部")
2018end
2019local f1
2020f1 = function(_arg_0)
2021 local a, b, c
2022 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
2023 return print(a, b, c)
2024end
2025f1({
2026 a = 1,
2027 b = "2",
2028 c = { }
2029})
2030local f2
2031f2 = function(_arg_0, c)
2032 local a1, b
2033 a1, b = _arg_0.a, _arg_0.b
2034 if a1 == nil then
2035 a1 = 123
2036 end
2037 if b == nil then
2038 b = 'abc'
2039 end
2040 if c == nil then
2041 c = { }
2042 end
2043 return print(a1, b, c)
2044end
2045local arg1 = {
2046 a = 0
2047}
2048f2(arg1, arg2)
2049local findFirstEven
2050findFirstEven = function(list)
2051 for _index_0 = 1, #list do
2052 local item = list[_index_0]
2053 if type(item) == "table" then
2054 for _index_1 = 1, #item do
2055 local sub = item[_index_1]
2056 if sub % 2 == 0 then
2057 return sub
2058 end
2059 end
2060 end
2061 end
2062 return nil
2063end
2064local findFirstEven
2065findFirstEven = function(list)
2066 for _index_0 = 1, #list do
2067 local item = list[_index_0]
2068 if type(item) == "table" then
2069 for _index_1 = 1, #item do
2070 local sub = item[_index_1]
2071 if sub % 2 == 0 then
2072 return sub
2073 end
2074 end
2075 end
2076 end
2077 return nil
2078end
2079local f
2080f = function(...)
2081 local t = {
2082 n = select("#", ...),
2083 ...
2084 }
2085 print("参数个数:", t.n)
2086 print("表长度:", #t)
2087 for i = 1, t.n do
2088 print(t[i])
2089 end
2090end
2091f(1, 2, 3)
2092f("a", "b", "c", "d")
2093f()
2094local process
2095process = function(...)
2096 local args = {
2097 n = select("#", ...),
2098 ...
2099 }
2100 local sum = 0
2101 for i = 1, args.n do
2102 if args[i] ~= nil and type(args[i]) == "number" then
2103 sum = sum + args[i]
2104 end
2105 end
2106 return sum
2107end
2108process(1, nil, 3, nil, 5)
2109f(function(x)
2110 return print("hello" .. x)
2111end)
2112f(function(self)
2113 return print(self.value)
2114end)
2115map(function(x)
2116 return x * 2
2117end, {
2118 1,
2119 2,
2120 3
2121})
2122local result, msg
2123do
2124 result, msg = readAsync("文件名.txt", function(data)
2125 print(data)
2126 return processAsync(data, function(info)
2127 return check(info)
2128 end)
2129 end)
2130end
2131print(result, msg)
2132f(function(x)
2133 return print("hello" .. x)
1051end) 2134end)
1052f(function(self) 2135f(function(self)
1053 return print(self.value) 2136 return print(self.value)
@@ -1137,6 +2220,74 @@ local some_values = {
1137local list_with_one_element = { 2220local list_with_one_element = {
1138 1 2221 1
1139} 2222}
2223local some_values = {
2224 1,
2225 2,
2226 3,
2227 4
2228}
2229local some_values = {
2230 name = "Bill",
2231 age = 200,
2232 ["favorite food"] = "rice"
2233}
2234local profile = {
2235 height = "4英尺",
2236 shoe_size = 13,
2237 favorite_foods = {
2238 "冰淇淋",
2239 "甜甜圈"
2240 }
2241}
2242local values = {
2243 1,
2244 2,
2245 3,
2246 4,
2247 5,
2248 6,
2249 7,
2250 8,
2251 name = "超人",
2252 occupation = "打击犯罪"
2253}
2254my_function({
2255 dance = "探戈",
2256 partner = "无"
2257})
2258local y = {
2259 type = "狗",
2260 legs = 4,
2261 tails = 1
2262}
2263local tbl = {
2264 ["do"] = "某事",
2265 ["end"] = "饥饿"
2266}
2267local hair = "金色"
2268local height = 200
2269local person = {
2270 hair = hair,
2271 height = height,
2272 shoe_size = 40
2273}
2274print_table({
2275 hair = hair,
2276 height = height
2277})
2278local t = {
2279 [1 + 2] = "你好",
2280 ["你好 世界"] = true
2281}
2282local some_values = {
2283 1,
2284 2,
2285 3,
2286 4
2287}
2288local list_with_one_element = {
2289 1
2290}
1140local items = { 2291local items = {
1141 1, 2292 1,
1142 2, 2293 2,
@@ -1335,15 +2486,250 @@ for _index_0 = _min_0, 1, -1 do
1335end 2486end
1336reverse_slice = _accum_0 2487reverse_slice = _accum_0
1337local sub_list 2488local sub_list
2489do
2490 local _accum_0 = { }
2491 local _len_0 = 1
2492 local _list_0 = items
2493 for _index_0 = 2, 4 do
2494 local _item_0 = _list_0[_index_0]
2495 _accum_0[_len_0] = _item_0
2496 _len_0 = _len_0 + 1
2497 end
2498 sub_list = _accum_0
2499end
2500local last_four_items
1338local _accum_0 = { } 2501local _accum_0 = { }
1339local _len_0 = 1 2502local _len_0 = 1
1340local _list_0 = items 2503local _list_0 = items
1341for _index_0 = 2, 4 do 2504local _min_0 = #_list_0 + -4 + 1
2505local _max_0 = #_list_0 + -1 + 1
2506for _index_0 = _min_0, _max_0 do
2507 local _item_0 = _list_0[_index_0]
2508 _accum_0[_len_0] = _item_0
2509 _len_0 = _len_0 + 1
2510end
2511last_four_items = _accum_0
2512local items = {
2513 1,
2514 2,
2515 3,
2516 4
2517}
2518local doubled
2519local _accum_0 = { }
2520local _len_0 = 1
2521for i, item in ipairs(items) do
2522 _accum_0[_len_0] = item * 2
2523 _len_0 = _len_0 + 1
2524end
2525doubled = _accum_0
2526local slice
2527local _accum_0 = { }
2528local _len_0 = 1
2529for i, item in ipairs(items) do
2530 if i > 1 and i < 3 then
2531 _accum_0[_len_0] = item
2532 _len_0 = _len_0 + 1
2533 end
2534end
2535slice = _accum_0
2536local doubled
2537local _accum_0 = { }
2538local _len_0 = 1
2539local _list_0 = items
2540for _index_0 = 1, #_list_0 do
2541 local item = _list_0[_index_0]
2542 _accum_0[_len_0] = item * 2
2543 _len_0 = _len_0 + 1
2544end
2545doubled = _accum_0
2546local data = {
2547 a = {
2548 1,
2549 2,
2550 3
2551 },
2552 b = {
2553 4,
2554 5,
2555 6
2556 }
2557}
2558local flat
2559local _accum_0 = { }
2560for k, v in pairs(data) do
2561 local _len_0 = #_accum_0 + 1
2562 for _index_0 = 1, #v do
2563 local _elm_0 = v[_index_0]
2564 _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1
2565 end
2566end
2567flat = _accum_0
2568local x_coords = {
2569 4,
2570 5,
2571 6,
2572 7
2573}
2574local y_coords = {
2575 9,
2576 2,
2577 3
2578}
2579local points
2580local _accum_0 = { }
2581local _len_0 = 1
2582for _index_0 = 1, #x_coords do
2583 local x = x_coords[_index_0]
2584 for _index_1 = 1, #y_coords do
2585 local y = y_coords[_index_1]
2586 _accum_0[_len_0] = {
2587 x,
2588 y
2589 }
2590 _len_0 = _len_0 + 1
2591 end
2592end
2593points = _accum_0
2594local evens
2595local _accum_0 = { }
2596local _len_0 = 1
2597for i = 1, 100 do
2598 if i % 2 == 0 then
2599 _accum_0[_len_0] = i
2600 _len_0 = _len_0 + 1
2601 end
2602end
2603evens = _accum_0
2604local thing = {
2605 color = "red",
2606 name = "fast",
2607 width = 123
2608}
2609local thing_copy
2610local _tbl_0 = { }
2611for k, v in pairs(thing) do
2612 _tbl_0[k] = v
2613end
2614thing_copy = _tbl_0
2615local no_color
2616local _tbl_0 = { }
2617for k, v in pairs(thing) do
2618 if k ~= "color" then
2619 _tbl_0[k] = v
2620 end
2621end
2622no_color = _tbl_0
2623local numbers = {
2624 1,
2625 2,
2626 3,
2627 4
2628}
2629local sqrts
2630local _tbl_0 = { }
2631for _index_0 = 1, #numbers do
2632 local i = numbers[_index_0]
2633 _tbl_0[i] = math.sqrt(i)
2634end
2635sqrts = _tbl_0
2636local tuples = {
2637 {
2638 "hello",
2639 "world"
2640 },
2641 {
2642 "foo",
2643 "bar"
2644 }
2645}
2646local tbl
2647local _tbl_0 = { }
2648for _index_0 = 1, #tuples do
2649 local tuple = tuples[_index_0]
2650 local _key_0, _val_0 = unpack(tuple)
2651 _tbl_0[_key_0] = _val_0
2652end
2653tbl = _tbl_0
2654local slice
2655local _accum_0 = { }
2656local _len_0 = 1
2657local _list_0 = items
2658for _index_0 = 1, 5 do
2659 local item = _list_0[_index_0]
2660 _accum_0[_len_0] = item
2661 _len_0 = _len_0 + 1
2662end
2663slice = _accum_0
2664local slice
2665local _accum_0 = { }
2666local _len_0 = 1
2667local _list_0 = items
2668local _max_0 = #_list_0
2669for _index_0 = 2, _max_0 do
2670 local item = _list_0[_index_0]
2671 _accum_0[_len_0] = item
2672 _len_0 = _len_0 + 1
2673end
2674slice = _accum_0
2675local slice
2676local _accum_0 = { }
2677local _len_0 = 1
2678local _list_0 = items
2679local _max_0 = #_list_0
2680for _index_0 = 1, _max_0, 2 do
2681 local item = _list_0[_index_0]
2682 _accum_0[_len_0] = item
2683 _len_0 = _len_0 + 1
2684end
2685slice = _accum_0
2686local slice
2687local _accum_0 = { }
2688local _len_0 = 1
2689local _list_0 = items
2690local _min_0 = #_list_0 + -4 + 1
2691local _max_0 = #_list_0 + -1 + 1
2692for _index_0 = _min_0, _max_0 do
2693 local item = _list_0[_index_0]
2694 _accum_0[_len_0] = item
2695 _len_0 = _len_0 + 1
2696end
2697slice = _accum_0
2698local reverse_slice
2699local _accum_0 = { }
2700local _len_0 = 1
2701local _list_0 = items
2702local _min_0 = #_list_0 + -1 + 1
2703for _index_0 = _min_0, 1, -1 do
2704 local item = _list_0[_index_0]
2705 _accum_0[_len_0] = item
2706 _len_0 = _len_0 + 1
2707end
2708reverse_slice = _accum_0
2709local sub_list
2710do
2711 local _accum_0 = { }
2712 local _len_0 = 1
2713 local _list_0 = items
2714 for _index_0 = 2, 4 do
2715 local _item_0 = _list_0[_index_0]
2716 _accum_0[_len_0] = _item_0
2717 _len_0 = _len_0 + 1
2718 end
2719 sub_list = _accum_0
2720end
2721local last_four_items
2722local _accum_0 = { }
2723local _len_0 = 1
2724local _list_0 = items
2725local _min_0 = #_list_0 + -4 + 1
2726local _max_0 = #_list_0 + -1 + 1
2727for _index_0 = _min_0, _max_0 do
1342 local _item_0 = _list_0[_index_0] 2728 local _item_0 = _list_0[_index_0]
1343 _accum_0[_len_0] = _item_0 2729 _accum_0[_len_0] = _item_0
1344 _len_0 = _len_0 + 1 2730 _len_0 = _len_0 + 1
1345end 2731end
1346sub_list = _accum_0 2732last_four_items = _accum_0
1347for i = 10, 20 do 2733for i = 10, 20 do
1348 print(i) 2734 print(i)
1349end 2735end
@@ -1408,6 +2794,86 @@ func_b = function()
1408end 2794end
1409print(func_a()) 2795print(func_a())
1410print(func_b()) 2796print(func_b())
2797for i = 10, 20 do
2798 print(i)
2799end
2800for k = 1, 15, 2 do
2801 print(k)
2802end
2803for key, value in pairs(object) do
2804 print(key, value)
2805end
2806local _list_0 = items
2807for _index_0 = 2, 4 do
2808 local item = _list_0[_index_0]
2809 print(item)
2810end
2811local _list_0 = items
2812for _index_0 = 1, #_list_0 do
2813 local item = _list_0[_index_0]
2814 print(item)
2815end
2816for j = 1, 10, 3 do
2817 print(j)
2818end
2819local doubled_evens
2820local _accum_0 = { }
2821local _len_0 = 1
2822for i = 1, 20 do
2823 if i % 2 == 0 then
2824 _accum_0[_len_0] = i * 2
2825 _len_0 = _len_0 + 1
2826 else
2827 _accum_0[_len_0] = i
2828 _len_0 = _len_0 + 1
2829 end
2830end
2831doubled_evens = _accum_0
2832local first_large
2833local _accum_0
2834local _list_0 = numbers
2835for _index_0 = 1, #_list_0 do
2836 local n = _list_0[_index_0]
2837 if n > 10 then
2838 _accum_0 = n
2839 break
2840 end
2841end
2842first_large = _accum_0
2843local func_a
2844func_a = function()
2845 for i = 1, 10 do
2846 print(i)
2847 end
2848end
2849local func_b
2850func_b = function()
2851 local _accum_0 = { }
2852 local _len_0 = 1
2853 for i = 1, 10 do
2854 _accum_0[_len_0] = i
2855 _len_0 = _len_0 + 1
2856 end
2857 return _accum_0
2858end
2859print(func_a())
2860print(func_b())
2861local i = 10
2862while i > 0 do
2863 print(i)
2864 i = i - 1
2865end
2866while running == true do
2867 my_function()
2868end
2869local i = 10
2870while not (i == 0) do
2871 print(i)
2872 i = i - 1
2873end
2874while not (running == false) do
2875 my_function()
2876end
1411local i = 10 2877local i = 10
1412repeat 2878repeat
1413 print(i) 2879 print(i)
@@ -1429,6 +2895,11 @@ end
1429while not (running == false) do 2895while not (running == false) do
1430 my_function() 2896 my_function()
1431end 2897end
2898local i = 10
2899repeat
2900 print(i)
2901 i = i - 1
2902until i == 0
1432local i = 0 2903local i = 0
1433while i < 10 do 2904while i < 10 do
1434 i = i + 1 2905 i = i + 1
@@ -1459,6 +2930,95 @@ for _index_0 = 1, #my_numbers do
1459 ::_continue_0:: 2930 ::_continue_0::
1460end 2931end
1461odds = _accum_0 2932odds = _accum_0
2933local i = 0
2934while i < 10 do
2935 i = i + 1
2936 if i % 2 == 0 then
2937 goto _continue_0
2938 end
2939 print(i)
2940 ::_continue_0::
2941end
2942local my_numbers = {
2943 1,
2944 2,
2945 3,
2946 4,
2947 5,
2948 6
2949}
2950local odds
2951local _accum_0 = { }
2952local _len_0 = 1
2953for _index_0 = 1, #my_numbers do
2954 local x = my_numbers[_index_0]
2955 if x % 2 == 1 then
2956 goto _continue_0
2957 end
2958 _accum_0[_len_0] = x
2959 _len_0 = _len_0 + 1
2960 ::_continue_0::
2961end
2962odds = _accum_0
2963local have_coins = false
2964if have_coins then
2965 print("有硬币")
2966else
2967 print("没有硬币")
2968end
2969local have_coins = false
2970if have_coins then
2971 print("有硬币")
2972else
2973 print("没有硬币")
2974end
2975local have_coins = false
2976print((function()
2977 if have_coins then
2978 return "有硬币"
2979 else
2980 return "没有硬币"
2981 end
2982end)())
2983local is_tall
2984is_tall = function(name)
2985 if name == "Rob" then
2986 return true
2987 else
2988 return false
2989 end
2990end
2991local message
2992if is_tall("Rob") then
2993 message = "我很高"
2994else
2995 message = "我不是很高"
2996end
2997print(message)
2998if not (os.date("%A") == "Monday") then
2999 print("今天不是星期一!")
3000end
3001if not (math.random() > 0.1) then
3002 print("你真幸运!")
3003end
3004local a = 5
3005if (1 == a or 3 == a or 5 == a or 7 == a) then
3006 print("检查离散值的相等性")
3007end
3008if (function()
3009 local _check_0 = list
3010 for _index_0 = 1, #_check_0 do
3011 if _check_0[_index_0] == a then
3012 return true
3013 end
3014 end
3015 return false
3016end)() then
3017 print("检查`a`是否在列表中")
3018end
3019if not (math.random() > 0.1) then
3020 print("你很幸运!")
3021end
1462local have_coins = false 3022local have_coins = false
1463if have_coins then 3023if have_coins then
1464 print("有硬币") 3024 print("有硬币")
@@ -1532,6 +3092,312 @@ end
1532while not reader:eof() do 3092while not reader:eof() do
1533 reader:parse_line() 3093 reader:parse_line()
1534end 3094end
3095if name == "Rob" then
3096 print("你好,世界")
3097end
3098local _list_0 = items
3099for _index_0 = 1, #_list_0 do
3100 local item = _list_0[_index_0]
3101 print("项目: ", item)
3102end
3103while game:isRunning() do
3104 game:update()
3105end
3106while not reader:eof() do
3107 reader:parse_line()
3108end
3109local name = "Dan"
3110if "Robert" == name then
3111 print("你是Robert")
3112elseif "Dan" == name or "Daniel" == name then
3113 print("你的名字是Dan")
3114else
3115 print("我不认识你,你的名字是" .. tostring(name))
3116end
3117local b = 1
3118local next_number
3119if 1 == b then
3120 next_number = 2
3121elseif 2 == b then
3122 next_number = 3
3123else
3124 next_number = error("数字数得太大了!")
3125end
3126local msg
3127local _exp_0 = math.random(1, 5)
3128if 1 == _exp_0 then
3129 msg = "你很幸运"
3130elseif 2 == _exp_0 then
3131 msg = "你差点很幸运"
3132else
3133 msg = "不太幸运"
3134end
3135do
3136 local _exp_0 = math.random(1, 5)
3137 if 1 == _exp_0 then
3138 print("你很幸运")
3139 else
3140 print("不太幸运")
3141 end
3142end
3143local _exp_0 = math.random(1, 5)
3144if 1 == _exp_0 then
3145 print("你很幸运")
3146else
3147 print("不太幸运")
3148end
3149local items = {
3150 {
3151 x = 100,
3152 y = 200
3153 },
3154 {
3155 width = 300,
3156 height = 400
3157 }
3158}
3159for _index_0 = 1, #items do
3160 local item = items[_index_0]
3161 local _type_0 = type(item)
3162 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3163 local _match_0 = false
3164 if _tab_0 then
3165 local x = item.x
3166 local y = item.y
3167 if x ~= nil and y ~= nil then
3168 _match_0 = true
3169 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3170 end
3171 end
3172 if not _match_0 then
3173 if _tab_0 then
3174 local width = item.width
3175 local height = item.height
3176 if width ~= nil and height ~= nil then
3177 print("尺寸 " .. tostring(width) .. ", " .. tostring(height))
3178 end
3179 end
3180 end
3181end
3182local item = { }
3183local x, y = item.pos.x, item.pos.y
3184if x == nil then
3185 x = 50
3186end
3187if y == nil then
3188 y = 200
3189end
3190local _type_0 = type(item)
3191local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3192if _tab_0 then
3193 do
3194 local _obj_0 = item.pos
3195 local _type_1 = type(_obj_0)
3196 if "table" == _type_1 or "userdata" == _type_1 then
3197 x = _obj_0.x
3198 end
3199 end
3200 do
3201 local _obj_0 = item.pos
3202 local _type_1 = type(_obj_0)
3203 if "table" == _type_1 or "userdata" == _type_1 then
3204 y = _obj_0.y
3205 end
3206 end
3207 if x == nil then
3208 x = 50
3209 end
3210 if y == nil then
3211 y = 200
3212 end
3213 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3214end
3215local _exp_0 = tb
3216local _type_0 = type(_exp_0)
3217local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3218local _match_0 = false
3219if _tab_0 then
3220 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3221 _match_0 = true
3222 print("1, 2, 3")
3223 end
3224end
3225if not _match_0 then
3226 local _match_1 = false
3227 if _tab_0 then
3228 local b = _exp_0[2]
3229 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3230 _match_1 = true
3231 print("1, " .. tostring(b) .. ", 3")
3232 end
3233 end
3234 if not _match_1 then
3235 if _tab_0 then
3236 local b = _exp_0[3]
3237 if b == nil then
3238 b = 3
3239 end
3240 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3241 print("1, 2, " .. tostring(b))
3242 end
3243 end
3244 end
3245end
3246local _exp_0 = tb
3247local _type_0 = type(_exp_0)
3248local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3249local _match_0 = false
3250if _tab_0 then
3251 local result = _exp_0.result
3252 if true == _exp_0.success and result ~= nil then
3253 _match_0 = true
3254 print("成功", result)
3255 end
3256end
3257if not _match_0 then
3258 local _match_1 = false
3259 if _tab_0 then
3260 if false == _exp_0.success then
3261 _match_1 = true
3262 print("失败", result)
3263 end
3264 end
3265 if not _match_1 then
3266 print("无效值")
3267 end
3268end
3269local _exp_0 = tb
3270local _type_0 = type(_exp_0)
3271local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3272local _match_0 = false
3273if _tab_0 then
3274 local content
3275 do
3276 local _obj_0 = _exp_0.data
3277 local _type_1 = type(_obj_0)
3278 if "table" == _type_1 or "userdata" == _type_1 then
3279 content = _obj_0.content
3280 end
3281 end
3282 local _val_0
3283 do
3284 local _obj_0 = _exp_0.data
3285 if _obj_0 ~= nil then
3286 _val_0 = _obj_0.type
3287 end
3288 end
3289 if "success" == _val_0 and content ~= nil then
3290 _match_0 = true
3291 print("成功", content)
3292 end
3293end
3294if not _match_0 then
3295 local _match_1 = false
3296 if _tab_0 then
3297 local content
3298 do
3299 local _obj_0 = _exp_0.data
3300 local _type_1 = type(_obj_0)
3301 if "table" == _type_1 or "userdata" == _type_1 then
3302 content = _obj_0.content
3303 end
3304 end
3305 local _val_0
3306 do
3307 local _obj_0 = _exp_0.data
3308 if _obj_0 ~= nil then
3309 _val_0 = _obj_0.type
3310 end
3311 end
3312 if "error" == _val_0 and content ~= nil then
3313 _match_1 = true
3314 print("失败", content)
3315 end
3316 end
3317 if not _match_1 then
3318 print("无效值")
3319 end
3320end
3321local _exp_0 = tb
3322local _type_0 = type(_exp_0)
3323local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3324if _tab_0 then
3325 local fourth = _exp_0[4]
3326 local _val_0
3327 do
3328 local _obj_0 = _exp_0[1]
3329 if _obj_0 ~= nil then
3330 _val_0 = _obj_0.a
3331 end
3332 end
3333 local _val_1
3334 do
3335 local _obj_0 = _exp_0[1]
3336 if _obj_0 ~= nil then
3337 _val_1 = _obj_0.b
3338 end
3339 end
3340 local _val_2
3341 do
3342 local _obj_0 = _exp_0[2]
3343 if _obj_0 ~= nil then
3344 _val_2 = _obj_0.a
3345 end
3346 end
3347 local _val_3
3348 do
3349 local _obj_0 = _exp_0[2]
3350 if _obj_0 ~= nil then
3351 _val_3 = _obj_0.b
3352 end
3353 end
3354 local _val_4
3355 do
3356 local _obj_0 = _exp_0[3]
3357 if _obj_0 ~= nil then
3358 _val_4 = _obj_0.a
3359 end
3360 end
3361 local _val_5
3362 do
3363 local _obj_0 = _exp_0[3]
3364 if _obj_0 ~= nil then
3365 _val_5 = _obj_0.b
3366 end
3367 end
3368 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
3369 print("匹配成功", fourth)
3370 end
3371end
3372local segments = {
3373 "admin",
3374 "users",
3375 "logs",
3376 "view"
3377}
3378local _type_0 = type(segments)
3379local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3380if _tab_0 then
3381 local groups
3382 do
3383 local _accum_0 = { }
3384 local _len_0 = 1
3385 local _max_0 = #segments + -3 + 1
3386 for _index_0 = 1, _max_0 do
3387 local _item_0 = segments[_index_0]
3388 _accum_0[_len_0] = _item_0
3389 _len_0 = _len_0 + 1
3390 end
3391 groups = _accum_0
3392 end
3393 local resource = segments[#segments - 1]
3394 local action = segments[#segments]
3395 if resource ~= nil and action ~= nil then
3396 print("Group:", groups)
3397 print("Resource:", resource)
3398 print("Action:", action)
3399 end
3400end
1535local name = "Dan" 3401local name = "Dan"
1536if "Robert" == name then 3402if "Robert" == name then
1537 print("你是Robert") 3403 print("你是Robert")
@@ -2444,1940 +4310,6 @@ end
2444local y = Y() 4310local y = Y()
2445y:func() 4311y:func()
2446assert(y.__class.__parent ~= X) 4312assert(y.__class.__parent ~= X)
2447local _with_0 = Person()
2448_with_0.name = "Oswald"
2449_with_0:add_relative(my_dad)
2450_with_0:save()
2451print(_with_0.name)
2452local file
2453local _with_0 = File("favorite_foods.txt")
2454_with_0:set_encoding("utf8")
2455file = _with_0
2456local create_person
2457create_person = function(name, relatives)
2458 local _with_0 = Person()
2459 _with_0.name = name
2460 for _index_0 = 1, #relatives do
2461 local relative = relatives[_index_0]
2462 _with_0:add_relative(relative)
2463 end
2464 return _with_0
2465end
2466local me = create_person("Leaf", {
2467 dad,
2468 mother,
2469 sister
2470})
2471local str = "你好"
2472print("原始:", str)
2473print("大写:", str:upper())
2474local _with_0 = tb
2475_with_0[1] = 1
2476print(_with_0[2])
2477do
2478 local _with_1 = _with_0[abc]
2479 _with_1[3] = _with_1[2]:func()
2480 _with_1["key-name"] = value
2481end
2482_with_0[#_with_0 + 1] = "abc"
2483local _with_0 = obj
2484if _with_0 ~= nil then
2485 print(obj.name)
2486end
2487do
2488 local var = "hello"
2489 print(var)
2490end
2491print(var)
2492local counter
2493do
2494 local i = 0
2495 counter = function()
2496 i = i + 1
2497 return i
2498 end
2499end
2500print(counter())
2501print(counter())
2502local tbl = {
2503 key = (function()
2504 print("分配键值!")
2505 return 1234
2506 end)()
2507}
2508local my_object = {
2509 value = 1000,
2510 write = function(self)
2511 return print("值为:", self.value)
2512 end
2513}
2514local run_callback
2515run_callback = function(func)
2516 print("运行回调...")
2517 return func()
2518end
2519run_callback(my_object.write)
2520run_callback((function()
2521 local _base_0 = my_object
2522 local _fn_0 = _base_0.write
2523 return _fn_0 and function(...)
2524 return _fn_0(_base_0, ...)
2525 end
2526end)())
2527local i = 100
2528local my_func
2529my_func = function()
2530 i = 10
2531 while i > 0 do
2532 print(i)
2533 i = i - 1
2534 end
2535end
2536my_func()
2537print(i)
2538local i = 100
2539local my_func
2540my_func = function()
2541 local i = "hello"
2542end
2543my_func()
2544print(i)
2545local tmp = 1213
2546local i, k = 100, 50
2547local my_func
2548my_func = function(add)
2549 local tmp = tmp + add
2550 i = i + tmp
2551 k = k + tmp
2552end
2553my_func(22)
2554print(i, k)
2555local _module_0 = { }
2556local p, to_lua
2557do
2558 local _obj_0 = require("yue")
2559 p, to_lua = _obj_0.p, _obj_0.to_lua
2560end
2561local inventory = {
2562 equipment = {
2563 "sword",
2564 "shield"
2565 },
2566 items = {
2567 {
2568 name = "potion",
2569 count = 10
2570 },
2571 {
2572 name = "bread",
2573 count = 3
2574 }
2575 }
2576}
2577local map
2578map = function(arr, action)
2579 local _accum_0 = { }
2580 local _len_0 = 1
2581 for _index_0 = 1, #arr do
2582 local item = arr[_index_0]
2583 _accum_0[_len_0] = action(item)
2584 _len_0 = _len_0 + 1
2585 end
2586 return _accum_0
2587end
2588local filter
2589filter = function(arr, cond)
2590 local _accum_0 = { }
2591 local _len_0 = 1
2592 for _index_0 = 1, #arr do
2593 local item = arr[_index_0]
2594 if cond(item) then
2595 _accum_0[_len_0] = item
2596 _len_0 = _len_0 + 1
2597 end
2598 end
2599 return _accum_0
2600end
2601local reduce
2602reduce = function(arr, init, action)
2603 for _index_0 = 1, #arr do
2604 local item = arr[_index_0]
2605 init = action(init, item)
2606 end
2607 return init
2608end
2609print(reduce(filter(map({
2610 1,
2611 2,
2612 3
2613}, function(x)
2614 return x * 2
2615end), function(x)
2616 return x > 4
2617end), 0, function(a, b)
2618 return a + b
2619end))
2620local apple = setmetatable({
2621 size = 15,
2622}, {
2623 __index = {
2624 color = 0x00ffff
2625 }
2626})
2627if (getmetatable(apple) ~= nil) then
2628 p(apple.size, apple.color, getmetatable(apple).__index)
2629end
2630local _u1f31b = "月之脚本"
2631_module_0["🌛"] = _u1f31b
2632return _module_0
2633local area = 6.2831853071796 * 5
2634print('你好 世界')
2635do
2636 assert(item ~= nil)
2637end
2638local value = item
2639if (f1() and f2() and f3()) then
2640 print("OK")
2641end
2642do
2643 local funcA
2644 funcA = function() end
2645end
2646local funcA
2647funcA = function()
2648 return "无法访问宏生成月之脚本里定义的变量"
2649end
2650do
2651local function funcB() end
2652end
2653local funcB
2654funcB = function()
2655 return "无法访问宏生成 Lua 代码里定义的变量"
2656end
2657do
2658-- 插入原始Lua代码
2659if cond then
2660 print("输出")
2661end
2662end
2663print("yuescript")
2664print(2)
2665print("有效的枚举类型:", "Static")
2666do
2667 print(123, "hello")
2668end
2669do
2670 print(123, "hello")
2671end
2672if tb ~= nil then
2673 tb:func()
2674end
2675if tb ~= nil then
2676 tb:func()
2677end
2678print(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)
2679local a = 5
2680print(1 <= a and a <= 10)
2681local v
2682v = function(x)
2683 print(x)
2684 return x
2685end
2686print((function()
2687 local _cond_0 = v(2)
2688 if not (v(1) < _cond_0) then
2689 return false
2690 else
2691 return _cond_0 <= v(3)
2692 end
2693end)())
2694print((function()
2695 local _cond_0 = v(2)
2696 if not (v(1) > _cond_0) then
2697 return false
2698 else
2699 return _cond_0 <= v(3)
2700 end
2701end)())
2702local tab = { }
2703tab[#tab + 1] = "Value"
2704local tbA = {
2705 1,
2706 2,
2707 3
2708}
2709local tbB = {
2710 4,
2711 5,
2712 6
2713}
2714local _len_0 = #tbA + 1
2715for _index_0 = 1, #tbB do
2716 local _elm_0 = tbB[_index_0]
2717 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
2718end
2719local parts = {
2720 "shoulders",
2721 "knees"
2722}
2723local lyrics
2724do
2725 local _tab_0 = {
2726 "head"
2727 }
2728 local _idx_0 = 1
2729 for _key_0, _value_0 in pairs(parts) do
2730 if _idx_0 == _key_0 then
2731 _tab_0[#_tab_0 + 1] = _value_0
2732 _idx_0 = _idx_0 + 1
2733 else
2734 _tab_0[_key_0] = _value_0
2735 end
2736 end
2737 _tab_0[#_tab_0 + 1] = "and"
2738 _tab_0[#_tab_0 + 1] = "toes"
2739 lyrics = _tab_0
2740end
2741local copy
2742do
2743 local _tab_0 = { }
2744 local _idx_0 = 1
2745 for _key_0, _value_0 in pairs(other) do
2746 if _idx_0 == _key_0 then
2747 _tab_0[#_tab_0 + 1] = _value_0
2748 _idx_0 = _idx_0 + 1
2749 else
2750 _tab_0[_key_0] = _value_0
2751 end
2752 end
2753 copy = _tab_0
2754end
2755local a = {
2756 1,
2757 2,
2758 3,
2759 x = 1
2760}
2761local b = {
2762 4,
2763 5,
2764 y = 1
2765}
2766local merge
2767local _tab_0 = { }
2768local _idx_0 = 1
2769for _key_0, _value_0 in pairs(a) do
2770 if _idx_0 == _key_0 then
2771 _tab_0[#_tab_0 + 1] = _value_0
2772 _idx_0 = _idx_0 + 1
2773 else
2774 _tab_0[_key_0] = _value_0
2775 end
2776end
2777local _idx_1 = 1
2778for _key_0, _value_0 in pairs(b) do
2779 if _idx_1 == _key_0 then
2780 _tab_0[#_tab_0 + 1] = _value_0
2781 _idx_1 = _idx_1 + 1
2782 else
2783 _tab_0[_key_0] = _value_0
2784 end
2785end
2786merge = _tab_0
2787local last
2788do
2789 local _item_0 = data.items
2790 last = _item_0[#_item_0]
2791end
2792local second_last
2793do
2794 local _item_0 = data.items
2795 second_last = _item_0[#_item_0 - 1]
2796end
2797local _obj_0 = data.items
2798_obj_0[#_obj_0] = 1
2799local mt = { }
2800local add
2801add = function(self, right)
2802 return setmetatable({
2803 value = self.value + right.value
2804 }, mt)
2805end
2806mt.__add = add
2807local a = setmetatable({
2808 value = 1
2809}, mt)
2810local b = setmetatable({
2811 value = 2
2812}, {
2813 __add = add
2814})
2815local c = setmetatable({
2816 value = 3
2817}, {
2818 __add = mt.__add
2819})
2820local d = a + b + c
2821print(d.value)
2822local _ <close> = setmetatable({ }, {
2823 __close = function()
2824 return print("超出范围")
2825 end
2826})
2827local tb = setmetatable({ }, {
2828 ["value"] = 123
2829})
2830getmetatable(tb).__index = getmetatable(tb)
2831print(tb.value)
2832setmetatable(tb, {
2833 __index = {
2834 item = "hello"
2835 }
2836})
2837print(tb.item)
2838local item, new, close, getter
2839do
2840 local _obj_0 = tb
2841 item, new = _obj_0[1], _obj_0.new
2842 do
2843 local _obj_1 = getmetatable(_obj_0)
2844 close, getter = _obj_1.__close, _obj_1.__index
2845 end
2846end
2847print(item, new, close, getter)
2848do
2849 local _obj_0 = func
2850 if _obj_0 ~= nil then
2851 _obj_0()
2852 end
2853end
2854print((function()
2855 local _obj_0 = abc
2856 if _obj_0 ~= nil then
2857 local _obj_1 = _obj_0["你好 世界"]
2858 if _obj_1 ~= nil then
2859 return _obj_1.xyz
2860 end
2861 return nil
2862 end
2863 return nil
2864end)())
2865local x
2866do
2867 local _obj_0 = tab
2868 if _obj_0 ~= nil then
2869 x = _obj_0.value
2870 end
2871end
2872local len = (function()
2873 local _obj_0 = utf8
2874 if _obj_0 ~= nil then
2875 return _obj_0.len
2876 end
2877 return nil
2878end)() or (function()
2879 local _obj_0 = string
2880 if _obj_0 ~= nil then
2881 return _obj_0.len
2882 end
2883 return nil
2884end)() or function(o)
2885 return #o
2886end
2887if print and (x ~= nil) then
2888 print(x)
2889end
2890local _with_0 = io.open("test.txt", "w")
2891if _with_0 ~= nil then
2892 _with_0:write("你好")
2893 _with_0:close()
2894end
2895print("你好")
2896print(1, 2)
2897print(1, 2, 3)
2898print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
2899local a, b, c, d
2900if b ~= nil then
2901 a = b
2902else
2903 if c ~= nil then
2904 a = c
2905 else
2906 a = d
2907 end
2908end
2909func((function()
2910 if a ~= nil then
2911 return a
2912 else
2913 return { }
2914 end
2915end)())
2916if a == nil then
2917 a = false
2918end
2919local list = {
2920 1,
2921 2,
2922 3
2923}
2924func({
2925 1,
2926 2,
2927 3
2928})
2929local f
2930f = function()
2931 return {
2932 1,
2933 2,
2934 3
2935 }
2936end
2937local tb = {
2938 name = "abc",
2939 values = {
2940 "a",
2941 "b",
2942 "c"
2943 },
2944 objects = {
2945 {
2946 name = "a",
2947 value = 1,
2948 func = function(self)
2949 return self.value + 1
2950 end,
2951 tb = {
2952 fieldA = 1
2953 }
2954 },
2955 {
2956 name = "b",
2957 value = 2,
2958 func = function(self)
2959 return self.value + 2
2960 end,
2961 tb = { }
2962 }
2963 }
2964}
2965do
2966 local insert, concat = table.insert, table.concat
2967 local C, Ct, Cmt
2968 do
2969 local _obj_0 = require("lpeg")
2970 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
2971 end
2972 local x, y, z
2973 do
2974 local _obj_0 = require('mymodule')
2975 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z
2976 end
2977 local a, b, c
2978 local _obj_0 = require('module')
2979 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
2980end
2981do
2982 local module = require('module')
2983 local module_x = require('module_x')
2984 local d_a_s_h_e_s = require("d-a-s-h-e-s")
2985 local part = require("module.part")
2986end
2987do
2988 local PlayerModule = require("player")
2989 local C, Ct, Cmt
2990 do
2991 local _obj_0 = require("lpeg")
2992 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
2993 end
2994 local one, two, ch
2995 local _obj_0 = require("export")
2996 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
2997end
2998do
2999 local tostring <const> = tostring
3000 local concat <const> = table.concat
3001 print(concat({
3002 "a",
3003 tostring(1)
3004 }))
3005end
3006do
3007 local print <const> = print
3008 local math <const> = math
3009 print("hello")
3010 math.random(3)
3011end
3012do
3013 local print <const> = print
3014 print(FLAG)
3015 FLAG = 123
3016end
3017local _module_0 = { }
3018local a, b, c = 1, 2, 3
3019_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
3020local cool = "cat"
3021_module_0["cool"] = cool
3022local What
3023if this then
3024 What = "abc"
3025else
3026 What = "def"
3027end
3028_module_0["What"] = What
3029local y
3030y = function()
3031 local hallo = 3434
3032end
3033_module_0["y"] = y
3034local Something
3035local _class_0
3036local _base_0 = {
3037 umm = "cool"
3038}
3039if _base_0.__index == nil then
3040 _base_0.__index = _base_0
3041end
3042_class_0 = setmetatable({
3043 __init = function() end,
3044 __base = _base_0,
3045 __name = "Something"
3046}, {
3047 __index = _base_0,
3048 __call = function(cls, ...)
3049 local _self_0 = setmetatable({ }, _base_0)
3050 cls.__init(_self_0, ...)
3051 return _self_0
3052 end
3053})
3054_base_0.__class = _class_0
3055Something = _class_0
3056_module_0["Something"] = Something
3057return _module_0
3058local _module_0 = { }
3059local loadstring, tolua
3060do
3061 local _obj_0 = yue
3062 loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua
3063end
3064_module_0["loadstring"], _module_0["tolua"] = loadstring, tolua
3065local fieldA = tb.itemA.fieldA
3066if fieldA == nil then
3067 fieldA = '默认值'
3068end
3069_module_0["fieldA"] = fieldA
3070return _module_0
3071local _module_0 = setmetatable({ }, { })
3072_module_0.itemA = tb
3073getmetatable(_module_0).__index = items
3074_module_0["a-b-c"] = 123
3075return _module_0
3076local _module_0 = { }
3077local d, e, f = 3, 2, 1
3078_module_0[#_module_0 + 1] = d
3079_module_0[#_module_0 + 1] = e
3080_module_0[#_module_0 + 1] = f
3081if this then
3082 _module_0[#_module_0 + 1] = 123
3083else
3084 _module_0[#_module_0 + 1] = 456
3085end
3086local _with_0 = tmp
3087local j = 2000
3088_module_0[#_module_0 + 1] = _with_0
3089return _module_0
3090local _module_0 = nil
3091_module_0 = function()
3092 print("你好")
3093 return 123
3094end
3095return _module_0
3096local hello = "world"
3097local a, b, c = 1, 2, 3
3098hello = 123
3099local x = 1
3100x = x + 1
3101x = x - 1
3102x = x * 10
3103x = x / 10
3104x = x % 10
3105local s = s .. "world"
3106local arg = arg or "默认值"
3107local a = 0
3108local b = 0
3109local c = 0
3110local d = 0
3111local e = 0
3112local x = f()
3113local y = x
3114local z = x
3115do
3116 local a = 1
3117 local x, y, z
3118 print("预先声明后续所有变量为局部变量")
3119 x = function()
3120 return 1 + y + z
3121 end
3122 y, z = 2, 3
3123 instance = Item:new()
3124end
3125do
3126 local X = 1
3127 local B
3128 print("只预先声明后续大写的变量为局部变量")
3129 local a = 1
3130 B = 2
3131end
3132do
3133 a = 1
3134 print("预先声明所有变量为全局变量")
3135 x = function()
3136 return 1 + y + z
3137 end
3138 y, z = 2, 3
3139end
3140do
3141 x = 1
3142 print("只预先声明大写的变量为全局变量")
3143 local a = 1
3144 B = 2
3145 local Temp = "一个局部值"
3146end
3147local thing = {
3148 1,
3149 2
3150}
3151local a, b = thing[1], thing[2]
3152print(a, b)
3153local obj = {
3154 hello = "world",
3155 day = "tuesday",
3156 length = 20
3157}
3158local hello, the_day = obj.hello, obj.day
3159print(hello, the_day)
3160local day = obj.day
3161local obj2 = {
3162 numbers = {
3163 1,
3164 2,
3165 3,
3166 4
3167 },
3168 properties = {
3169 color = "green",
3170 height = 13.5
3171 }
3172}
3173local first, second = obj2.numbers[1], obj2.numbers[2]
3174print(first, second, color)
3175local first, second, color
3176local _obj_0 = obj2
3177first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color
3178local concat, insert
3179local _obj_0 = table
3180concat, insert = _obj_0.concat, _obj_0.insert
3181local mix, max, rand
3182local _obj_0 = math
3183mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random
3184local name, job
3185local _obj_0 = person
3186name, job = _obj_0.name, _obj_0.job
3187if name == nil then
3188 name = "nameless"
3189end
3190if job == nil then
3191 job = "jobless"
3192end
3193local two, four
3194local _obj_0 = items
3195two, four = _obj_0[2], _obj_0[4]
3196local orders = {
3197 "first",
3198 "second",
3199 "third",
3200 "fourth",
3201 "last"
3202}
3203local first, bulk, last = orders[1], (function()
3204 local _accum_0 = { }
3205 local _len_0 = 1
3206 local _max_0 = #orders + -2 + 1
3207 for _index_0 = 2, _max_0 do
3208 local _item_0 = orders[_index_0]
3209 _accum_0[_len_0] = _item_0
3210 _len_0 = _len_0 + 1
3211 end
3212 return _accum_0
3213end)(), orders[#orders]
3214print(first)
3215print(bulk)
3216print(last)
3217local first, rest
3218do
3219 local _obj_0 = orders
3220 first, rest = _obj_0[1], (function()
3221 local _accum_0 = { }
3222 local _len_0 = 1
3223 local _max_0 = #_obj_0
3224 for _index_0 = 2, _max_0 do
3225 local _item_0 = _obj_0[_index_0]
3226 _accum_0[_len_0] = _item_0
3227 _len_0 = _len_0 + 1
3228 end
3229 return _accum_0
3230 end)()
3231end
3232local start, last
3233do
3234 local _obj_0 = orders
3235 start, last = (function()
3236 local _accum_0 = { }
3237 local _len_0 = 1
3238 local _max_0 = #_obj_0 + -2 + 1
3239 for _index_0 = 1, _max_0 do
3240 local _item_0 = _obj_0[_index_0]
3241 _accum_0[_len_0] = _item_0
3242 _len_0 = _len_0 + 1
3243 end
3244 return _accum_0
3245 end)(), _obj_0[#_obj_0]
3246end
3247local _obj_0 = orders
3248first, last = _obj_0[1], _obj_0[#_obj_0]
3249local tuples = {
3250 {
3251 "hello",
3252 "world"
3253 },
3254 {
3255 "egg",
3256 "head"
3257 }
3258}
3259for _index_0 = 1, #tuples do
3260 local _des_0 = tuples[_index_0]
3261 local left, right = _des_0[1], _des_0[2]
3262 print(left, right)
3263end
3264local user = database.find_user("moon")
3265if user then
3266 print(user.name)
3267end
3268local hello = os.getenv("hello")
3269if hello then
3270 print("你有 hello", hello)
3271else
3272 local world = os.getenv("world")
3273 if world then
3274 print("你有 world", world)
3275 else
3276 print("什么都没有 :(")
3277 end
3278end
3279do
3280 local success, result = pcall(function()
3281 return "无报错地获取结果"
3282 end)
3283 if success then
3284 print(result)
3285 end
3286end
3287print("好的")
3288repeat
3289 local byte = stream:read_one()
3290 if byte then
3291 print(byte)
3292 else
3293 break
3294 end
3295until false
3296local list = {
3297 1,
3298 2,
3299 3,
3300 4,
3301 5
3302}
3303local fn
3304fn = function(ok)
3305 return ok, table.unpack(list)
3306end
3307(function(_arg_0, ...)
3308 local ok = _arg_0
3309 local count = select('#', ...)
3310 local first = select(1, ...)
3311 return print(ok, count, first)
3312end)(fn(true))
3313local a = 1
3314local b = 2
3315print(a + b)
3316Rx.Observable.fromRange(1, 8):filter(function(x)
3317 return x % 2 == 0
3318end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
3319 return value .. '!'
3320end):subscribe(print)
3321local str = strA .. strB .. strC
3322func(3000, "192.168.1.1")
3323xpcall(function()
3324 return func(1, 2, 3)
3325end, function(err)
3326 return print(yue.traceback(err))
3327end)
3328local success, result = xpcall(function()
3329 return func(1, 2, 3)
3330end, function(err)
3331 return yue.traceback(err)
3332end)
3333xpcall(function()
3334 return func(1, 2, 3)
3335end, function(err)
3336 return print(yue.traceback(err))
3337end)
3338success, result = pcall(function()
3339 return func(1, 2, 3)
3340end)
3341pcall(function()
3342 print("尝试中")
3343 return func(1, 2, 3)
3344end)
3345success, result = xpcall(function()
3346 return func(1, 2, 3)
3347end, function(err)
3348 return print(yue.traceback(err))
3349end)
3350if success then
3351 print(result)
3352end
3353local a, b, c
3354do
3355 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
3356 return func()
3357 end)
3358 if _ok_0 then
3359 a, b, c = _ret_0, _ret_1, _ret_2
3360 end
3361end
3362do
3363 local _exp_0 = ((function()
3364 return (function(_arg_0, ...)
3365 local _ok_0 = _arg_0
3366 if _ok_0 then
3367 return ...
3368 end
3369 end)(pcall(function()
3370 return func()
3371 end))
3372 end)())
3373 if _exp_0 ~= nil then
3374 a = _exp_0
3375 else
3376 a = "default"
3377 end
3378end
3379f((function()
3380 return (function(_arg_0, ...)
3381 local _ok_0 = _arg_0
3382 if _ok_0 then
3383 return ...
3384 end
3385 end)(pcall(function()
3386 return func()
3387 end))
3388end)())
3389f((function()
3390 return (function(_arg_0, ...)
3391 local _ok_0 = _arg_0
3392 if _ok_0 then
3393 return ...
3394 end
3395 end)(xpcall(function()
3396 print(123)
3397 return func()
3398 end, function(e)
3399 print(e)
3400 return e
3401 end))
3402end)())
3403local a <const> = 123
3404local _ <close> = setmetatable({ }, {
3405 __close = function()
3406 return print("超出范围。")
3407 end
3408})
3409local a, b, c, d
3410local _obj_0 = tb
3411a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
3412Constant = 123
3413local some_string = "这是一个字符串\n 并包括一个换行。"
3414print("我有" .. tostring(math.random() * 100) .. "%的把握。")
3415local integer = 1000000
3416local hex = 0xEFBBBF
3417local binary = 19
3418local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
3419local fn
3420fn = function()
3421 local str = "foo:\n bar: baz"
3422 return str
3423end
3424local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
3425local my_function
3426my_function = function() end
3427my_function()
3428local func_a
3429func_a = function()
3430 return print("你好,世界")
3431end
3432local func_b
3433func_b = function()
3434 local value = 100
3435 return print("这个值是:", value)
3436end
3437func_a()
3438func_b()
3439local sum
3440sum = function(x, y)
3441 return print("数字的和", x + y)
3442end
3443sum(10, 20)
3444print(sum(10, 20))
3445a(b(c("a", "b", "c")))
3446print("x:", sum(10, 20), "y:", sum(30, 40))
3447local sum
3448sum = function(x, y)
3449 return x + y
3450end
3451print("数字的和是", sum(10, 20))
3452local sum
3453sum = function(x, y)
3454 return x + y
3455end
3456local mystery
3457mystery = function(x, y)
3458 return x + y, x - y
3459end
3460local a, b = mystery(10, 20)
3461local func
3462func = function(self, num)
3463 return self.value + num
3464end
3465local my_function
3466my_function = function(name, height)
3467 if name == nil then
3468 name = "某物"
3469 end
3470 if height == nil then
3471 height = 100
3472 end
3473 print("你好,我是", name)
3474 return print("我的高度是", height)
3475end
3476local some_args
3477some_args = function(x, y)
3478 if x == nil then
3479 x = 100
3480 end
3481 if y == nil then
3482 y = x + 1000
3483 end
3484 return print(x + y)
3485end
3486my_func(5, 4, 3, 8, 9, 10)
3487cool_func(1, 2, 3, 4, 5, 6, 7, 8)
3488my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4)
3489local x = {
3490 1,
3491 2,
3492 3,
3493 4,
3494 a_func(4, 5, 5, 6),
3495 8,
3496 9,
3497 10
3498}
3499local y = {
3500 my_func(1, 2, 3, 4, 5),
3501 5,
3502 6,
3503 7
3504}
3505if func(1, 2, 3, "你好", "世界") then
3506 print("你好")
3507 print("我在if内部")
3508end
3509if func(1, 2, 3, "你好", "世界") then
3510 print("你好")
3511 print("我在if内部")
3512end
3513local f1
3514f1 = function(_arg_0)
3515 local a, b, c
3516 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
3517 return print(a, b, c)
3518end
3519f1({
3520 a = 1,
3521 b = "2",
3522 c = { }
3523})
3524local f2
3525f2 = function(_arg_0, c)
3526 local a1, b
3527 a1, b = _arg_0.a, _arg_0.b
3528 if a1 == nil then
3529 a1 = 123
3530 end
3531 if b == nil then
3532 b = 'abc'
3533 end
3534 if c == nil then
3535 c = { }
3536 end
3537 return print(a1, b, c)
3538end
3539local arg1 = {
3540 a = 0
3541}
3542f2(arg1, arg2)
3543local findFirstEven
3544findFirstEven = function(list)
3545 for _index_0 = 1, #list do
3546 local item = list[_index_0]
3547 if type(item) == "table" then
3548 for _index_1 = 1, #item do
3549 local sub = item[_index_1]
3550 if sub % 2 == 0 then
3551 return sub
3552 end
3553 end
3554 end
3555 end
3556 return nil
3557end
3558local findFirstEven
3559findFirstEven = function(list)
3560 for _index_0 = 1, #list do
3561 local item = list[_index_0]
3562 if type(item) == "table" then
3563 for _index_1 = 1, #item do
3564 local sub = item[_index_1]
3565 if sub % 2 == 0 then
3566 return sub
3567 end
3568 end
3569 end
3570 end
3571 return nil
3572end
3573local f
3574f = function(...)
3575 local t = {
3576 n = select("#", ...),
3577 ...
3578 }
3579 print("参数个数:", t.n)
3580 print("表长度:", #t)
3581 for i = 1, t.n do
3582 print(t[i])
3583 end
3584end
3585f(1, 2, 3)
3586f("a", "b", "c", "d")
3587f()
3588local process
3589process = function(...)
3590 local args = {
3591 n = select("#", ...),
3592 ...
3593 }
3594 local sum = 0
3595 for i = 1, args.n do
3596 if args[i] ~= nil and type(args[i]) == "number" then
3597 sum = sum + args[i]
3598 end
3599 end
3600 return sum
3601end
3602process(1, nil, 3, nil, 5)
3603f(function()
3604 return print("hello")
3605end)
3606f(function(self)
3607 return print(self.value)
3608end)
3609map(function(x)
3610 return x * 2
3611end, {
3612 1,
3613 2,
3614 3
3615})
3616local result, msg
3617do
3618 result, msg = readAsync("文件名.txt", function(data)
3619 print(data)
3620 return processAsync(data, function(info)
3621 return check(info)
3622 end)
3623 end)
3624end
3625print(result, msg)
3626local some_values = {
3627 1,
3628 2,
3629 3,
3630 4
3631}
3632local some_values = {
3633 name = "Bill",
3634 age = 200,
3635 ["favorite food"] = "rice"
3636}
3637local profile = {
3638 height = "4英尺",
3639 shoe_size = 13,
3640 favorite_foods = {
3641 "冰淇淋",
3642 "甜甜圈"
3643 }
3644}
3645local values = {
3646 1,
3647 2,
3648 3,
3649 4,
3650 5,
3651 6,
3652 7,
3653 8,
3654 name = "超人",
3655 occupation = "打击犯罪"
3656}
3657my_function({
3658 dance = "探戈",
3659 partner = "无"
3660})
3661local y = {
3662 type = "狗",
3663 legs = 4,
3664 tails = 1
3665}
3666local tbl = {
3667 ["do"] = "某事",
3668 ["end"] = "饥饿"
3669}
3670local hair = "金色"
3671local height = 200
3672local person = {
3673 hair = hair,
3674 height = height,
3675 shoe_size = 40
3676}
3677print_table({
3678 hair = hair,
3679 height = height
3680})
3681local t = {
3682 [1 + 2] = "你好",
3683 ["你好 世界"] = true
3684}
3685local some_values = {
3686 1,
3687 2,
3688 3,
3689 4
3690}
3691local list_with_one_element = {
3692 1
3693}
3694local items = {
3695 1,
3696 2,
3697 3,
3698 4
3699}
3700local doubled
3701local _accum_0 = { }
3702local _len_0 = 1
3703for i, item in ipairs(items) do
3704 _accum_0[_len_0] = item * 2
3705 _len_0 = _len_0 + 1
3706end
3707doubled = _accum_0
3708local slice
3709local _accum_0 = { }
3710local _len_0 = 1
3711for i, item in ipairs(items) do
3712 if i > 1 and i < 3 then
3713 _accum_0[_len_0] = item
3714 _len_0 = _len_0 + 1
3715 end
3716end
3717slice = _accum_0
3718local doubled
3719local _accum_0 = { }
3720local _len_0 = 1
3721local _list_0 = items
3722for _index_0 = 1, #_list_0 do
3723 local item = _list_0[_index_0]
3724 _accum_0[_len_0] = item * 2
3725 _len_0 = _len_0 + 1
3726end
3727doubled = _accum_0
3728local data = {
3729 a = {
3730 1,
3731 2,
3732 3
3733 },
3734 b = {
3735 4,
3736 5,
3737 6
3738 }
3739}
3740local flat
3741local _accum_0 = { }
3742for k, v in pairs(data) do
3743 local _len_0 = #_accum_0 + 1
3744 for _index_0 = 1, #v do
3745 local _elm_0 = v[_index_0]
3746 _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1
3747 end
3748end
3749flat = _accum_0
3750local x_coords = {
3751 4,
3752 5,
3753 6,
3754 7
3755}
3756local y_coords = {
3757 9,
3758 2,
3759 3
3760}
3761local points
3762local _accum_0 = { }
3763local _len_0 = 1
3764for _index_0 = 1, #x_coords do
3765 local x = x_coords[_index_0]
3766 for _index_1 = 1, #y_coords do
3767 local y = y_coords[_index_1]
3768 _accum_0[_len_0] = {
3769 x,
3770 y
3771 }
3772 _len_0 = _len_0 + 1
3773 end
3774end
3775points = _accum_0
3776local evens
3777local _accum_0 = { }
3778local _len_0 = 1
3779for i = 1, 100 do
3780 if i % 2 == 0 then
3781 _accum_0[_len_0] = i
3782 _len_0 = _len_0 + 1
3783 end
3784end
3785evens = _accum_0
3786local thing = {
3787 color = "red",
3788 name = "fast",
3789 width = 123
3790}
3791local thing_copy
3792local _tbl_0 = { }
3793for k, v in pairs(thing) do
3794 _tbl_0[k] = v
3795end
3796thing_copy = _tbl_0
3797local no_color
3798local _tbl_0 = { }
3799for k, v in pairs(thing) do
3800 if k ~= "color" then
3801 _tbl_0[k] = v
3802 end
3803end
3804no_color = _tbl_0
3805local numbers = {
3806 1,
3807 2,
3808 3,
3809 4
3810}
3811local sqrts
3812local _tbl_0 = { }
3813for _index_0 = 1, #numbers do
3814 local i = numbers[_index_0]
3815 _tbl_0[i] = math.sqrt(i)
3816end
3817sqrts = _tbl_0
3818local tuples = {
3819 {
3820 "hello",
3821 "world"
3822 },
3823 {
3824 "foo",
3825 "bar"
3826 }
3827}
3828local tbl
3829local _tbl_0 = { }
3830for _index_0 = 1, #tuples do
3831 local tuple = tuples[_index_0]
3832 local _key_0, _val_0 = unpack(tuple)
3833 _tbl_0[_key_0] = _val_0
3834end
3835tbl = _tbl_0
3836local slice
3837local _accum_0 = { }
3838local _len_0 = 1
3839local _list_0 = items
3840for _index_0 = 1, 5 do
3841 local item = _list_0[_index_0]
3842 _accum_0[_len_0] = item
3843 _len_0 = _len_0 + 1
3844end
3845slice = _accum_0
3846local slice
3847local _accum_0 = { }
3848local _len_0 = 1
3849local _list_0 = items
3850local _max_0 = #_list_0
3851for _index_0 = 2, _max_0 do
3852 local item = _list_0[_index_0]
3853 _accum_0[_len_0] = item
3854 _len_0 = _len_0 + 1
3855end
3856slice = _accum_0
3857local slice
3858local _accum_0 = { }
3859local _len_0 = 1
3860local _list_0 = items
3861local _max_0 = #_list_0
3862for _index_0 = 1, _max_0, 2 do
3863 local item = _list_0[_index_0]
3864 _accum_0[_len_0] = item
3865 _len_0 = _len_0 + 1
3866end
3867slice = _accum_0
3868local slice
3869local _accum_0 = { }
3870local _len_0 = 1
3871local _list_0 = items
3872local _min_0 = #_list_0 + -4 + 1
3873local _max_0 = #_list_0 + -1 + 1
3874for _index_0 = _min_0, _max_0 do
3875 local item = _list_0[_index_0]
3876 _accum_0[_len_0] = item
3877 _len_0 = _len_0 + 1
3878end
3879slice = _accum_0
3880local reverse_slice
3881local _accum_0 = { }
3882local _len_0 = 1
3883local _list_0 = items
3884local _min_0 = #_list_0 + -1 + 1
3885for _index_0 = _min_0, 1, -1 do
3886 local item = _list_0[_index_0]
3887 _accum_0[_len_0] = item
3888 _len_0 = _len_0 + 1
3889end
3890reverse_slice = _accum_0
3891local sub_list
3892local _accum_0 = { }
3893local _len_0 = 1
3894local _list_0 = items
3895for _index_0 = 2, 4 do
3896 local _item_0 = _list_0[_index_0]
3897 _accum_0[_len_0] = _item_0
3898 _len_0 = _len_0 + 1
3899end
3900sub_list = _accum_0
3901for i = 10, 20 do
3902 print(i)
3903end
3904for k = 1, 15, 2 do
3905 print(k)
3906end
3907for key, value in pairs(object) do
3908 print(key, value)
3909end
3910local _list_0 = items
3911for _index_0 = 2, 4 do
3912 local item = _list_0[_index_0]
3913 print(item)
3914end
3915local _list_0 = items
3916for _index_0 = 1, #_list_0 do
3917 local item = _list_0[_index_0]
3918 print(item)
3919end
3920for j = 1, 10, 3 do
3921 print(j)
3922end
3923local doubled_evens
3924local _accum_0 = { }
3925local _len_0 = 1
3926for i = 1, 20 do
3927 if i % 2 == 0 then
3928 _accum_0[_len_0] = i * 2
3929 _len_0 = _len_0 + 1
3930 else
3931 _accum_0[_len_0] = i
3932 _len_0 = _len_0 + 1
3933 end
3934end
3935doubled_evens = _accum_0
3936local first_large
3937local _accum_0
3938local _list_0 = numbers
3939for _index_0 = 1, #_list_0 do
3940 local n = _list_0[_index_0]
3941 if n > 10 then
3942 _accum_0 = n
3943 break
3944 end
3945end
3946first_large = _accum_0
3947local func_a
3948func_a = function()
3949 for i = 1, 10 do
3950 print(i)
3951 end
3952end
3953local func_b
3954func_b = function()
3955 local _accum_0 = { }
3956 local _len_0 = 1
3957 for i = 1, 10 do
3958 _accum_0[_len_0] = i
3959 _len_0 = _len_0 + 1
3960 end
3961 return _accum_0
3962end
3963print(func_a())
3964print(func_b())
3965local i = 10
3966repeat
3967 print(i)
3968 i = i - 1
3969until i == 0
3970local i = 10
3971while i > 0 do
3972 print(i)
3973 i = i - 1
3974end
3975while running == true do
3976 my_function()
3977end
3978local i = 10
3979while not (i == 0) do
3980 print(i)
3981 i = i - 1
3982end
3983while not (running == false) do
3984 my_function()
3985end
3986local i = 0
3987while i < 10 do
3988 i = i + 1
3989 if i % 2 == 0 then
3990 goto _continue_0
3991 end
3992 print(i)
3993 ::_continue_0::
3994end
3995local my_numbers = {
3996 1,
3997 2,
3998 3,
3999 4,
4000 5,
4001 6
4002}
4003local odds
4004local _accum_0 = { }
4005local _len_0 = 1
4006for _index_0 = 1, #my_numbers do
4007 local x = my_numbers[_index_0]
4008 if x % 2 == 1 then
4009 goto _continue_0
4010 end
4011 _accum_0[_len_0] = x
4012 _len_0 = _len_0 + 1
4013 ::_continue_0::
4014end
4015odds = _accum_0
4016local have_coins = false
4017if have_coins then
4018 print("有硬币")
4019else
4020 print("没有硬币")
4021end
4022local have_coins = false
4023if have_coins then
4024 print("有硬币")
4025else
4026 print("没有硬币")
4027end
4028local have_coins = false
4029print((function()
4030 if have_coins then
4031 return "有硬币"
4032 else
4033 return "没有硬币"
4034 end
4035end)())
4036local is_tall
4037is_tall = function(name)
4038 if name == "Rob" then
4039 return true
4040 else
4041 return false
4042 end
4043end
4044local message
4045if is_tall("Rob") then
4046 message = "我很高"
4047else
4048 message = "我不是很高"
4049end
4050print(message)
4051if not (os.date("%A") == "Monday") then
4052 print("今天不是星期一!")
4053end
4054if not (math.random() > 0.1) then
4055 print("你真幸运!")
4056end
4057local a = 5
4058if (1 == a or 3 == a or 5 == a or 7 == a) then
4059 print("检查离散值的相等性")
4060end
4061if (function()
4062 local _check_0 = list
4063 for _index_0 = 1, #_check_0 do
4064 if _check_0[_index_0] == a then
4065 return true
4066 end
4067 end
4068 return false
4069end)() then
4070 print("检查`a`是否在列表中")
4071end
4072if not (math.random() > 0.1) then
4073 print("你很幸运!")
4074end
4075if name == "Rob" then
4076 print("你好,世界")
4077end
4078local _list_0 = items
4079for _index_0 = 1, #_list_0 do
4080 local item = _list_0[_index_0]
4081 print("项目: ", item)
4082end
4083while game:isRunning() do
4084 game:update()
4085end
4086while not reader:eof() do
4087 reader:parse_line()
4088end
4089local name = "Dan"
4090if "Robert" == name then
4091 print("你是Robert")
4092elseif "Dan" == name or "Daniel" == name then
4093 print("你的名字是Dan")
4094else
4095 print("我不认识你,你的名字是" .. tostring(name))
4096end
4097local b = 1
4098local next_number
4099if 1 == b then
4100 next_number = 2
4101elseif 2 == b then
4102 next_number = 3
4103else
4104 next_number = error("数字数得太大了!")
4105end
4106local msg
4107local _exp_0 = math.random(1, 5)
4108if 1 == _exp_0 then
4109 msg = "你很幸运"
4110elseif 2 == _exp_0 then
4111 msg = "你差点很幸运"
4112else
4113 msg = "不太幸运"
4114end
4115do
4116 local _exp_0 = math.random(1, 5)
4117 if 1 == _exp_0 then
4118 print("你很幸运")
4119 else
4120 print("不太幸运")
4121 end
4122end
4123local _exp_0 = math.random(1, 5)
4124if 1 == _exp_0 then
4125 print("你很幸运")
4126else
4127 print("不太幸运")
4128end
4129local items = {
4130 {
4131 x = 100,
4132 y = 200
4133 },
4134 {
4135 width = 300,
4136 height = 400
4137 }
4138}
4139for _index_0 = 1, #items do
4140 local item = items[_index_0]
4141 local _type_0 = type(item)
4142 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4143 local _match_0 = false
4144 if _tab_0 then
4145 local x = item.x
4146 local y = item.y
4147 if x ~= nil and y ~= nil then
4148 _match_0 = true
4149 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
4150 end
4151 end
4152 if not _match_0 then
4153 if _tab_0 then
4154 local width = item.width
4155 local height = item.height
4156 if width ~= nil and height ~= nil then
4157 print("尺寸 " .. tostring(width) .. ", " .. tostring(height))
4158 end
4159 end
4160 end
4161end
4162local item = { }
4163local x, y = item.pos.x, item.pos.y
4164if x == nil then
4165 x = 50
4166end
4167if y == nil then
4168 y = 200
4169end
4170local _type_0 = type(item)
4171local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4172if _tab_0 then
4173 do
4174 local _obj_0 = item.pos
4175 local _type_1 = type(_obj_0)
4176 if "table" == _type_1 or "userdata" == _type_1 then
4177 x = _obj_0.x
4178 end
4179 end
4180 do
4181 local _obj_0 = item.pos
4182 local _type_1 = type(_obj_0)
4183 if "table" == _type_1 or "userdata" == _type_1 then
4184 y = _obj_0.y
4185 end
4186 end
4187 if x == nil then
4188 x = 50
4189 end
4190 if y == nil then
4191 y = 200
4192 end
4193 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
4194end
4195local _exp_0 = tb
4196local _type_0 = type(_exp_0)
4197local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4198local _match_0 = false
4199if _tab_0 then
4200 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
4201 _match_0 = true
4202 print("1, 2, 3")
4203 end
4204end
4205if not _match_0 then
4206 local _match_1 = false
4207 if _tab_0 then
4208 local b = _exp_0[2]
4209 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
4210 _match_1 = true
4211 print("1, " .. tostring(b) .. ", 3")
4212 end
4213 end
4214 if not _match_1 then
4215 if _tab_0 then
4216 local b = _exp_0[3]
4217 if b == nil then
4218 b = 3
4219 end
4220 if 1 == _exp_0[1] and 2 == _exp_0[2] then
4221 print("1, 2, " .. tostring(b))
4222 end
4223 end
4224 end
4225end
4226local _exp_0 = tb
4227local _type_0 = type(_exp_0)
4228local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4229local _match_0 = false
4230if _tab_0 then
4231 local result = _exp_0.result
4232 if true == _exp_0.success and result ~= nil then
4233 _match_0 = true
4234 print("成功", result)
4235 end
4236end
4237if not _match_0 then
4238 local _match_1 = false
4239 if _tab_0 then
4240 if false == _exp_0.success then
4241 _match_1 = true
4242 print("失败", result)
4243 end
4244 end
4245 if not _match_1 then
4246 print("无效值")
4247 end
4248end
4249local _exp_0 = tb
4250local _type_0 = type(_exp_0)
4251local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4252local _match_0 = false
4253if _tab_0 then
4254 local content
4255 do
4256 local _obj_0 = _exp_0.data
4257 local _type_1 = type(_obj_0)
4258 if "table" == _type_1 or "userdata" == _type_1 then
4259 content = _obj_0.content
4260 end
4261 end
4262 local _val_0
4263 do
4264 local _obj_0 = _exp_0.data
4265 if _obj_0 ~= nil then
4266 _val_0 = _obj_0.type
4267 end
4268 end
4269 if "success" == _val_0 and content ~= nil then
4270 _match_0 = true
4271 print("成功", content)
4272 end
4273end
4274if not _match_0 then
4275 local _match_1 = false
4276 if _tab_0 then
4277 local content
4278 do
4279 local _obj_0 = _exp_0.data
4280 local _type_1 = type(_obj_0)
4281 if "table" == _type_1 or "userdata" == _type_1 then
4282 content = _obj_0.content
4283 end
4284 end
4285 local _val_0
4286 do
4287 local _obj_0 = _exp_0.data
4288 if _obj_0 ~= nil then
4289 _val_0 = _obj_0.type
4290 end
4291 end
4292 if "error" == _val_0 and content ~= nil then
4293 _match_1 = true
4294 print("失败", content)
4295 end
4296 end
4297 if not _match_1 then
4298 print("无效值")
4299 end
4300end
4301local _exp_0 = tb
4302local _type_0 = type(_exp_0)
4303local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4304if _tab_0 then
4305 local fourth = _exp_0[4]
4306 local _val_0
4307 do
4308 local _obj_0 = _exp_0[1]
4309 if _obj_0 ~= nil then
4310 _val_0 = _obj_0.a
4311 end
4312 end
4313 local _val_1
4314 do
4315 local _obj_0 = _exp_0[1]
4316 if _obj_0 ~= nil then
4317 _val_1 = _obj_0.b
4318 end
4319 end
4320 local _val_2
4321 do
4322 local _obj_0 = _exp_0[2]
4323 if _obj_0 ~= nil then
4324 _val_2 = _obj_0.a
4325 end
4326 end
4327 local _val_3
4328 do
4329 local _obj_0 = _exp_0[2]
4330 if _obj_0 ~= nil then
4331 _val_3 = _obj_0.b
4332 end
4333 end
4334 local _val_4
4335 do
4336 local _obj_0 = _exp_0[3]
4337 if _obj_0 ~= nil then
4338 _val_4 = _obj_0.a
4339 end
4340 end
4341 local _val_5
4342 do
4343 local _obj_0 = _exp_0[3]
4344 if _obj_0 ~= nil then
4345 _val_5 = _obj_0.b
4346 end
4347 end
4348 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
4349 print("匹配成功", fourth)
4350 end
4351end
4352local segments = {
4353 "admin",
4354 "users",
4355 "logs",
4356 "view"
4357}
4358local _type_0 = type(segments)
4359local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4360if _tab_0 then
4361 local groups
4362 do
4363 local _accum_0 = { }
4364 local _len_0 = 1
4365 local _max_0 = #segments + -3 + 1
4366 for _index_0 = 1, _max_0 do
4367 local _item_0 = segments[_index_0]
4368 _accum_0[_len_0] = _item_0
4369 _len_0 = _len_0 + 1
4370 end
4371 groups = _accum_0
4372 end
4373 local resource = segments[#segments - 1]
4374 local action = segments[#segments]
4375 if resource ~= nil and action ~= nil then
4376 print("Group:", groups)
4377 print("Resource:", resource)
4378 print("Action:", action)
4379 end
4380end
4381local Inventory 4313local Inventory
4382local _class_0 4314local _class_0
4383local _base_0 = { 4315local _base_0 = {
@@ -5038,6 +4970,46 @@ local _with_0 = obj
5038if _with_0 ~= nil then 4970if _with_0 ~= nil then
5039 print(obj.name) 4971 print(obj.name)
5040end 4972end
4973local _with_0 = Person()
4974_with_0.name = "Oswald"
4975_with_0:add_relative(my_dad)
4976_with_0:save()
4977print(_with_0.name)
4978local file
4979local _with_0 = File("favorite_foods.txt")
4980_with_0:set_encoding("utf8")
4981file = _with_0
4982local create_person
4983create_person = function(name, relatives)
4984 local _with_0 = Person()
4985 _with_0.name = name
4986 for _index_0 = 1, #relatives do
4987 local relative = relatives[_index_0]
4988 _with_0:add_relative(relative)
4989 end
4990 return _with_0
4991end
4992local me = create_person("Leaf", {
4993 dad,
4994 mother,
4995 sister
4996})
4997local str = "你好"
4998print("原始:", str)
4999print("大写:", str:upper())
5000local _with_0 = tb
5001_with_0[1] = 1
5002print(_with_0[2])
5003do
5004 local _with_1 = _with_0[abc]
5005 _with_1[3] = _with_1[2]:func()
5006 _with_1["key-name"] = value
5007end
5008_with_0[#_with_0 + 1] = "abc"
5009local _with_0 = obj
5010if _with_0 ~= nil then
5011 print(obj.name)
5012end
5041do 5013do
5042 local var = "hello" 5014 local var = "hello"
5043 print(var) 5015 print(var)
@@ -5059,6 +5031,46 @@ local tbl = {
5059 return 1234 5031 return 1234
5060 end)() 5032 end)()
5061} 5033}
5034do
5035 local var = "hello"
5036 print(var)
5037end
5038print(var)
5039local counter
5040do
5041 local i = 0
5042 counter = function()
5043 i = i + 1
5044 return i
5045 end
5046end
5047print(counter())
5048print(counter())
5049local tbl = {
5050 key = (function()
5051 print("分配键值!")
5052 return 1234
5053 end)()
5054}
5055local my_object = {
5056 value = 1000,
5057 write = function(self)
5058 return print("值为:", self.value)
5059 end
5060}
5061local run_callback
5062run_callback = function(func)
5063 print("运行回调...")
5064 return func()
5065end
5066run_callback(my_object.write)
5067run_callback((function()
5068 local _base_0 = my_object
5069 local _fn_0 = _base_0.write
5070 return _fn_0 and function(...)
5071 return _fn_0(_base_0, ...)
5072 end
5073end)())
5062local my_object = { 5074local my_object = {
5063 value = 1000, 5075 value = 1000,
5064 write = function(self) 5076 write = function(self)
@@ -5106,3 +5118,31 @@ my_func = function(add)
5106end 5118end
5107my_func(22) 5119my_func(22)
5108print(i, k) 5120print(i, k)
5121local i = 100
5122local my_func
5123my_func = function()
5124 i = 10
5125 while i > 0 do
5126 print(i)
5127 i = i - 1
5128 end
5129end
5130my_func()
5131print(i)
5132local i = 100
5133local my_func
5134my_func = function()
5135 local i = "hello"
5136end
5137my_func()
5138print(i)
5139local tmp = 1213
5140local i, k = 100, 50
5141local my_func
5142my_func = function(add)
5143 local tmp = tmp + add
5144 i = i + tmp
5145 k = k + tmp
5146end
5147my_func(22)
5148print(i, k)