diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-02-06 10:30:49 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-02-06 10:30:49 +0800 |
| commit | aa3ecc7badfb39cb9167fb95c9a678257c1d9954 (patch) | |
| tree | a309d9af64ae060e2086c8bcdcf943693c8dcbba /spec/outputs/codes_from_doc.lua | |
| parent | 03902475c542c3ec4f1884c4217f8a4ef61f3ca8 (diff) | |
| download | yuescript-aa3ecc7badfb39cb9167fb95c9a678257c1d9954.tar.gz yuescript-aa3ecc7badfb39cb9167fb95c9a678257c1d9954.tar.bz2 yuescript-aa3ecc7badfb39cb9167fb95c9a678257c1d9954.zip | |
Fixed docs.
Diffstat (limited to 'spec/outputs/codes_from_doc.lua')
| -rw-r--r-- | spec/outputs/codes_from_doc.lua | 5148 |
1 files changed, 0 insertions, 5148 deletions
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua deleted file mode 100644 index d74ac16..0000000 --- a/spec/outputs/codes_from_doc.lua +++ /dev/null | |||
| @@ -1,5148 +0,0 @@ | |||
| 1 | local _module_0 = { } | ||
| 2 | local p, to_lua | ||
| 3 | do | ||
| 4 | local _obj_0 = require("yue") | ||
| 5 | p, to_lua = _obj_0.p, _obj_0.to_lua | ||
| 6 | end | ||
| 7 | local inventory = { | ||
| 8 | equipment = { | ||
| 9 | "sword", | ||
| 10 | "shield" | ||
| 11 | }, | ||
| 12 | items = { | ||
| 13 | { | ||
| 14 | name = "potion", | ||
| 15 | count = 10 | ||
| 16 | }, | ||
| 17 | { | ||
| 18 | name = "bread", | ||
| 19 | count = 3 | ||
| 20 | } | ||
| 21 | } | ||
| 22 | } | ||
| 23 | local map | ||
| 24 | map = function(arr, action) | ||
| 25 | local _accum_0 = { } | ||
| 26 | local _len_0 = 1 | ||
| 27 | for _index_0 = 1, #arr do | ||
| 28 | local item = arr[_index_0] | ||
| 29 | _accum_0[_len_0] = action(item) | ||
| 30 | _len_0 = _len_0 + 1 | ||
| 31 | end | ||
| 32 | return _accum_0 | ||
| 33 | end | ||
| 34 | local filter | ||
| 35 | filter = function(arr, cond) | ||
| 36 | local _accum_0 = { } | ||
| 37 | local _len_0 = 1 | ||
| 38 | for _index_0 = 1, #arr do | ||
| 39 | local item = arr[_index_0] | ||
| 40 | if cond(item) then | ||
| 41 | _accum_0[_len_0] = item | ||
| 42 | _len_0 = _len_0 + 1 | ||
| 43 | end | ||
| 44 | end | ||
| 45 | return _accum_0 | ||
| 46 | end | ||
| 47 | local reduce | ||
| 48 | reduce = function(arr, init, action) | ||
| 49 | for _index_0 = 1, #arr do | ||
| 50 | local item = arr[_index_0] | ||
| 51 | init = action(init, item) | ||
| 52 | end | ||
| 53 | return init | ||
| 54 | end | ||
| 55 | print(reduce(filter(map({ | ||
| 56 | 1, | ||
| 57 | 2, | ||
| 58 | 3 | ||
| 59 | }, function(x) | ||
| 60 | return x * 2 | ||
| 61 | end), function(x) | ||
| 62 | return x > 4 | ||
| 63 | end), 0, function(a, b) | ||
| 64 | return a + b | ||
| 65 | end)) | ||
| 66 | local apple = setmetatable({ | ||
| 67 | size = 15, | ||
| 68 | }, { | ||
| 69 | __index = { | ||
| 70 | color = 0x00ffff | ||
| 71 | } | ||
| 72 | }) | ||
| 73 | if (getmetatable(apple) ~= nil) then | ||
| 74 | p(apple.size, apple.color, getmetatable(apple).__index) | ||
| 75 | end | ||
| 76 | local _u1f31b = "ζδΉθζ¬" | ||
| 77 | _module_0["π"] = _u1f31b | ||
| 78 | return _module_0 | ||
| 79 | local _module_0 = { } | ||
| 80 | local p, to_lua | ||
| 81 | do | ||
| 82 | local _obj_0 = require("yue") | ||
| 83 | p, to_lua = _obj_0.p, _obj_0.to_lua | ||
| 84 | end | ||
| 85 | local 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 | } | ||
| 101 | local map | ||
| 102 | map = 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 | ||
| 111 | end | ||
| 112 | local filter | ||
| 113 | filter = 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 | ||
| 124 | end | ||
| 125 | local reduce | ||
| 126 | reduce = 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 | ||
| 132 | end | ||
| 133 | print(reduce(filter(map({ | ||
| 134 | 1, | ||
| 135 | 2, | ||
| 136 | 3 | ||
| 137 | }, function(x) | ||
| 138 | return x * 2 | ||
| 139 | end), function(x) | ||
| 140 | return x > 4 | ||
| 141 | end), 0, function(a, b) | ||
| 142 | return a + b | ||
| 143 | end)) | ||
| 144 | local apple = setmetatable({ | ||
| 145 | size = 15, | ||
| 146 | }, { | ||
| 147 | __index = { | ||
| 148 | color = 0x00ffff | ||
| 149 | } | ||
| 150 | }) | ||
| 151 | if (getmetatable(apple) ~= nil) then | ||
| 152 | p(apple.size, apple.color, getmetatable(apple).__index) | ||
| 153 | end | ||
| 154 | local _u1f31b = "ζδΉθζ¬" | ||
| 155 | _module_0["π"] = _u1f31b | ||
| 156 | return _module_0 | ||
| 157 | local area = 6.2831853071796 * 5 | ||
| 158 | print('hello world') | ||
| 159 | do | ||
| 160 | assert(item ~= nil) | ||
| 161 | end | ||
| 162 | local value = item | ||
| 163 | if (f1() and f2() and f3()) then | ||
| 164 | print("OK") | ||
| 165 | end | ||
| 166 | do | ||
| 167 | local funcA | ||
| 168 | funcA = function() end | ||
| 169 | end | ||
| 170 | local funcA | ||
| 171 | funcA = function() | ||
| 172 | return "fail to assign to the Yue macro defined variable" | ||
| 173 | end | ||
| 174 | do | ||
| 175 | local function funcB() end | ||
| 176 | end | ||
| 177 | local funcB | ||
| 178 | funcB = function() | ||
| 179 | return "fail to assign to the Lua macro defined variable" | ||
| 180 | end | ||
| 181 | do | ||
| 182 | -- raw Lua codes insertion | ||
| 183 | if cond then | ||
| 184 | print("output") | ||
| 185 | end | ||
| 186 | end | ||
| 187 | print("yuescript") | ||
| 188 | print(2) | ||
| 189 | print("Valid enum type:", "Static") | ||
| 190 | do | ||
| 191 | print(123, "hello") | ||
| 192 | end | ||
| 193 | do | ||
| 194 | print(123, "hello") | ||
| 195 | end | ||
| 196 | local area = 6.2831853071796 * 5 | ||
| 197 | print('hello world') | ||
| 198 | do | ||
| 199 | assert(item ~= nil) | ||
| 200 | end | ||
| 201 | local value = item | ||
| 202 | if (f1() and f2() and f3()) then | ||
| 203 | print("OK") | ||
| 204 | end | ||
| 205 | do | ||
| 206 | local funcA | ||
| 207 | funcA = function() end | ||
| 208 | end | ||
| 209 | local funcA | ||
| 210 | funcA = function() | ||
| 211 | return "fail to assign to the Yue macro defined variable" | ||
| 212 | end | ||
| 213 | do | ||
| 214 | local function funcB() end | ||
| 215 | end | ||
| 216 | local funcB | ||
| 217 | funcB = function() | ||
| 218 | return "fail to assign to the Lua macro defined variable" | ||
| 219 | end | ||
| 220 | do | ||
| 221 | -- raw Lua codes insertion | ||
| 222 | if cond then | ||
| 223 | print("output") | ||
| 224 | end | ||
| 225 | end | ||
| 226 | print("yuescript") | ||
| 227 | print(2) | ||
| 228 | print("Valid enum type:", "Static") | ||
| 229 | do | ||
| 230 | print(123, "hello") | ||
| 231 | end | ||
| 232 | do | ||
| 233 | print(123, "hello") | ||
| 234 | end | ||
| 235 | if tb ~= nil then | ||
| 236 | tb:func() | ||
| 237 | end | ||
| 238 | if tb ~= nil then | ||
| 239 | tb:func() | ||
| 240 | end | ||
| 241 | 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) | ||
| 242 | local a = 5 | ||
| 243 | print(1 <= a and a <= 10) | ||
| 244 | local v | ||
| 245 | v = function(x) | ||
| 246 | print(x) | ||
| 247 | return x | ||
| 248 | end | ||
| 249 | print((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 | ||
| 256 | end)()) | ||
| 257 | print((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 | ||
| 264 | end)()) | ||
| 265 | local tab = { } | ||
| 266 | tab[#tab + 1] = "Value" | ||
| 267 | local tbA = { | ||
| 268 | 1, | ||
| 269 | 2, | ||
| 270 | 3 | ||
| 271 | } | ||
| 272 | local tbB = { | ||
| 273 | 4, | ||
| 274 | 5, | ||
| 275 | 6 | ||
| 276 | } | ||
| 277 | local _len_0 = #tbA + 1 | ||
| 278 | for _index_0 = 1, #tbB do | ||
| 279 | local _elm_0 = tbB[_index_0] | ||
| 280 | tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 281 | end | ||
| 282 | local parts = { | ||
| 283 | "shoulders", | ||
| 284 | "knees" | ||
| 285 | } | ||
| 286 | local lyrics | ||
| 287 | do | ||
| 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 | ||
| 303 | end | ||
| 304 | local copy | ||
| 305 | do | ||
| 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 | ||
| 317 | end | ||
| 318 | local a = { | ||
| 319 | 1, | ||
| 320 | 2, | ||
| 321 | 3, | ||
| 322 | x = 1 | ||
| 323 | } | ||
| 324 | local b = { | ||
| 325 | 4, | ||
| 326 | 5, | ||
| 327 | y = 1 | ||
| 328 | } | ||
| 329 | local merge | ||
| 330 | local _tab_0 = { } | ||
| 331 | local _idx_0 = 1 | ||
| 332 | for _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 | ||
| 339 | end | ||
| 340 | local _idx_1 = 1 | ||
| 341 | for _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 | ||
| 348 | end | ||
| 349 | merge = _tab_0 | ||
| 350 | local last | ||
| 351 | do | ||
| 352 | local _item_0 = data.items | ||
| 353 | last = _item_0[#_item_0] | ||
| 354 | end | ||
| 355 | local second_last | ||
| 356 | do | ||
| 357 | local _item_0 = data.items | ||
| 358 | second_last = _item_0[#_item_0 - 1] | ||
| 359 | end | ||
| 360 | local _obj_0 = data.items | ||
| 361 | _obj_0[#_obj_0] = 1 | ||
| 362 | local mt = { } | ||
| 363 | local add | ||
| 364 | add = function(self, right) | ||
| 365 | return setmetatable({ | ||
| 366 | value = self.value + right.value | ||
| 367 | }, mt) | ||
| 368 | end | ||
| 369 | mt.__add = add | ||
| 370 | local a = setmetatable({ | ||
| 371 | value = 1 | ||
| 372 | }, mt) | ||
| 373 | local b = setmetatable({ | ||
| 374 | value = 2 | ||
| 375 | }, { | ||
| 376 | __add = add | ||
| 377 | }) | ||
| 378 | local c = setmetatable({ | ||
| 379 | value = 3 | ||
| 380 | }, { | ||
| 381 | __add = mt.__add | ||
| 382 | }) | ||
| 383 | local d = a + b + c | ||
| 384 | print(d.value) | ||
| 385 | local _ <close> = setmetatable({ }, { | ||
| 386 | __close = function() | ||
| 387 | return print("out of scope") | ||
| 388 | end | ||
| 389 | }) | ||
| 390 | local tb = setmetatable({ }, { | ||
| 391 | ["value"] = 123 | ||
| 392 | }) | ||
| 393 | getmetatable(tb).__index = getmetatable(tb) | ||
| 394 | print(tb.value) | ||
| 395 | setmetatable(tb, { | ||
| 396 | __index = { | ||
| 397 | item = "hello" | ||
| 398 | } | ||
| 399 | }) | ||
| 400 | print(tb.item) | ||
| 401 | local item, new, close, getter | ||
| 402 | do | ||
| 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 | ||
| 409 | end | ||
| 410 | print(item, new, close, getter) | ||
| 411 | do | ||
| 412 | local _obj_0 = func | ||
| 413 | if _obj_0 ~= nil then | ||
| 414 | _obj_0() | ||
| 415 | end | ||
| 416 | end | ||
| 417 | print((function() | ||
| 418 | local _obj_0 = abc | ||
| 419 | if _obj_0 ~= nil then | ||
| 420 | local _obj_1 = _obj_0["hello world"] | ||
| 421 | if _obj_1 ~= nil then | ||
| 422 | return _obj_1.xyz | ||
| 423 | end | ||
| 424 | return nil | ||
| 425 | end | ||
| 426 | return nil | ||
| 427 | end)()) | ||
| 428 | local x | ||
| 429 | do | ||
| 430 | local _obj_0 = tab | ||
| 431 | if _obj_0 ~= nil then | ||
| 432 | x = _obj_0.value | ||
| 433 | end | ||
| 434 | end | ||
| 435 | local len = (function() | ||
| 436 | local _obj_0 = utf8 | ||
| 437 | if _obj_0 ~= nil then | ||
| 438 | return _obj_0.len | ||
| 439 | end | ||
| 440 | return nil | ||
| 441 | end)() or (function() | ||
| 442 | local _obj_0 = string | ||
| 443 | if _obj_0 ~= nil then | ||
| 444 | return _obj_0.len | ||
| 445 | end | ||
| 446 | return nil | ||
| 447 | end)() or function(o) | ||
| 448 | return #o | ||
| 449 | end | ||
| 450 | if print and (x ~= nil) then | ||
| 451 | print(x) | ||
| 452 | end | ||
| 453 | local _with_0 = io.open("test.txt", "w") | ||
| 454 | if _with_0 ~= nil then | ||
| 455 | _with_0:write("hello") | ||
| 456 | _with_0:close() | ||
| 457 | end | ||
| 458 | print("hello") | ||
| 459 | print(1, 2) | ||
| 460 | print(1, 2, 3) | ||
| 461 | print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) | ||
| 462 | local a, b, c, d | ||
| 463 | if b ~= nil then | ||
| 464 | a = b | ||
| 465 | else | ||
| 466 | if c ~= nil then | ||
| 467 | a = c | ||
| 468 | else | ||
| 469 | a = d | ||
| 470 | end | ||
| 471 | end | ||
| 472 | func((function() | ||
| 473 | if a ~= nil then | ||
| 474 | return a | ||
| 475 | else | ||
| 476 | return { } | ||
| 477 | end | ||
| 478 | end)()) | ||
| 479 | if a == nil then | ||
| 480 | a = false | ||
| 481 | end | ||
| 482 | local list = { | ||
| 483 | 1, | ||
| 484 | 2, | ||
| 485 | 3 | ||
| 486 | } | ||
| 487 | func({ | ||
| 488 | 1, | ||
| 489 | 2, | ||
| 490 | 3 | ||
| 491 | }) | ||
| 492 | local f | ||
| 493 | f = function() | ||
| 494 | return { | ||
| 495 | 1, | ||
| 496 | 2, | ||
| 497 | 3 | ||
| 498 | } | ||
| 499 | end | ||
| 500 | local 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 | } | ||
| 528 | if tb ~= nil then | ||
| 529 | tb:func() | ||
| 530 | end | ||
| 531 | if tb ~= nil then | ||
| 532 | tb:func() | ||
| 533 | end | ||
| 534 | 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) | ||
| 535 | local a = 5 | ||
| 536 | print(1 <= a and a <= 10) | ||
| 537 | local v | ||
| 538 | v = function(x) | ||
| 539 | print(x) | ||
| 540 | return x | ||
| 541 | end | ||
| 542 | print((function() | ||
| 543 | local _cond_0 = v(2) | ||
| 544 | if not (v(1) < _cond_0) then | ||
| 545 | return false | ||
| 546 | else | ||
| 547 | return _cond_0 <= v(3) | ||
| 548 | end | ||
| 549 | end)()) | ||
| 550 | print((function() | ||
| 551 | local _cond_0 = v(2) | ||
| 552 | if not (v(1) > _cond_0) then | ||
| 553 | return false | ||
| 554 | else | ||
| 555 | return _cond_0 <= v(3) | ||
| 556 | end | ||
| 557 | end)()) | ||
| 558 | local tab = { } | ||
| 559 | tab[#tab + 1] = "Value" | ||
| 560 | local tbA = { | ||
| 561 | 1, | ||
| 562 | 2, | ||
| 563 | 3 | ||
| 564 | } | ||
| 565 | local tbB = { | ||
| 566 | 4, | ||
| 567 | 5, | ||
| 568 | 6 | ||
| 569 | } | ||
| 570 | local _len_0 = #tbA + 1 | ||
| 571 | for _index_0 = 1, #tbB do | ||
| 572 | local _elm_0 = tbB[_index_0] | ||
| 573 | tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 574 | end | ||
| 575 | local parts = { | ||
| 576 | "shoulders", | ||
| 577 | "knees" | ||
| 578 | } | ||
| 579 | local lyrics | ||
| 580 | do | ||
| 581 | local _tab_0 = { | ||
| 582 | "head" | ||
| 583 | } | ||
| 584 | local _idx_0 = 1 | ||
| 585 | for _key_0, _value_0 in pairs(parts) do | ||
| 586 | if _idx_0 == _key_0 then | ||
| 587 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 588 | _idx_0 = _idx_0 + 1 | ||
| 589 | else | ||
| 590 | _tab_0[_key_0] = _value_0 | ||
| 591 | end | ||
| 592 | end | ||
| 593 | _tab_0[#_tab_0 + 1] = "and" | ||
| 594 | _tab_0[#_tab_0 + 1] = "toes" | ||
| 595 | lyrics = _tab_0 | ||
| 596 | end | ||
| 597 | local copy | ||
| 598 | do | ||
| 599 | local _tab_0 = { } | ||
| 600 | local _idx_0 = 1 | ||
| 601 | for _key_0, _value_0 in pairs(other) do | ||
| 602 | if _idx_0 == _key_0 then | ||
| 603 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 604 | _idx_0 = _idx_0 + 1 | ||
| 605 | else | ||
| 606 | _tab_0[_key_0] = _value_0 | ||
| 607 | end | ||
| 608 | end | ||
| 609 | copy = _tab_0 | ||
| 610 | end | ||
| 611 | local a = { | ||
| 612 | 1, | ||
| 613 | 2, | ||
| 614 | 3, | ||
| 615 | x = 1 | ||
| 616 | } | ||
| 617 | local b = { | ||
| 618 | 4, | ||
| 619 | 5, | ||
| 620 | y = 1 | ||
| 621 | } | ||
| 622 | local merge | ||
| 623 | local _tab_0 = { } | ||
| 624 | local _idx_0 = 1 | ||
| 625 | for _key_0, _value_0 in pairs(a) do | ||
| 626 | if _idx_0 == _key_0 then | ||
| 627 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 628 | _idx_0 = _idx_0 + 1 | ||
| 629 | else | ||
| 630 | _tab_0[_key_0] = _value_0 | ||
| 631 | end | ||
| 632 | end | ||
| 633 | local _idx_1 = 1 | ||
| 634 | for _key_0, _value_0 in pairs(b) do | ||
| 635 | if _idx_1 == _key_0 then | ||
| 636 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 637 | _idx_1 = _idx_1 + 1 | ||
| 638 | else | ||
| 639 | _tab_0[_key_0] = _value_0 | ||
| 640 | end | ||
| 641 | end | ||
| 642 | merge = _tab_0 | ||
| 643 | local last | ||
| 644 | do | ||
| 645 | local _item_0 = data.items | ||
| 646 | last = _item_0[#_item_0] | ||
| 647 | end | ||
| 648 | local second_last | ||
| 649 | do | ||
| 650 | local _item_0 = data.items | ||
| 651 | second_last = _item_0[#_item_0 - 1] | ||
| 652 | end | ||
| 653 | local _obj_0 = data.items | ||
| 654 | _obj_0[#_obj_0] = 1 | ||
| 655 | local mt = { } | ||
| 656 | local add | ||
| 657 | add = function(self, right) | ||
| 658 | return setmetatable({ | ||
| 659 | value = self.value + right.value | ||
| 660 | }, mt) | ||
| 661 | end | ||
| 662 | mt.__add = add | ||
| 663 | local a = setmetatable({ | ||
| 664 | value = 1 | ||
| 665 | }, mt) | ||
| 666 | local b = setmetatable({ | ||
| 667 | value = 2 | ||
| 668 | }, { | ||
| 669 | __add = add | ||
| 670 | }) | ||
| 671 | local c = setmetatable({ | ||
| 672 | value = 3 | ||
| 673 | }, { | ||
| 674 | __add = mt.__add | ||
| 675 | }) | ||
| 676 | local d = a + b + c | ||
| 677 | print(d.value) | ||
| 678 | local _ <close> = setmetatable({ }, { | ||
| 679 | __close = function() | ||
| 680 | return print("out of scope") | ||
| 681 | end | ||
| 682 | }) | ||
| 683 | local tb = setmetatable({ }, { | ||
| 684 | ["value"] = 123 | ||
| 685 | }) | ||
| 686 | getmetatable(tb).__index = getmetatable(tb) | ||
| 687 | print(tb.value) | ||
| 688 | setmetatable(tb, { | ||
| 689 | __index = { | ||
| 690 | item = "hello" | ||
| 691 | } | ||
| 692 | }) | ||
| 693 | print(tb.item) | ||
| 694 | local item, new, close, getter | ||
| 695 | do | ||
| 696 | local _obj_0 = tb | ||
| 697 | item, new = _obj_0[1], _obj_0.new | ||
| 698 | do | ||
| 699 | local _obj_1 = getmetatable(_obj_0) | ||
| 700 | close, getter = _obj_1.__close, _obj_1.__index | ||
| 701 | end | ||
| 702 | end | ||
| 703 | print(item, new, close, getter) | ||
| 704 | do | ||
| 705 | local _obj_0 = func | ||
| 706 | if _obj_0 ~= nil then | ||
| 707 | _obj_0() | ||
| 708 | end | ||
| 709 | end | ||
| 710 | print((function() | ||
| 711 | local _obj_0 = abc | ||
| 712 | if _obj_0 ~= nil then | ||
| 713 | local _obj_1 = _obj_0["hello world"] | ||
| 714 | if _obj_1 ~= nil then | ||
| 715 | return _obj_1.xyz | ||
| 716 | end | ||
| 717 | return nil | ||
| 718 | end | ||
| 719 | return nil | ||
| 720 | end)()) | ||
| 721 | local x | ||
| 722 | do | ||
| 723 | local _obj_0 = tab | ||
| 724 | if _obj_0 ~= nil then | ||
| 725 | x = _obj_0.value | ||
| 726 | end | ||
| 727 | end | ||
| 728 | local len = (function() | ||
| 729 | local _obj_0 = utf8 | ||
| 730 | if _obj_0 ~= nil then | ||
| 731 | return _obj_0.len | ||
| 732 | end | ||
| 733 | return nil | ||
| 734 | end)() or (function() | ||
| 735 | local _obj_0 = string | ||
| 736 | if _obj_0 ~= nil then | ||
| 737 | return _obj_0.len | ||
| 738 | end | ||
| 739 | return nil | ||
| 740 | end)() or function(o) | ||
| 741 | return #o | ||
| 742 | end | ||
| 743 | if print and (x ~= nil) then | ||
| 744 | print(x) | ||
| 745 | end | ||
| 746 | local _with_0 = io.open("test.txt", "w") | ||
| 747 | if _with_0 ~= nil then | ||
| 748 | _with_0:write("hello") | ||
| 749 | _with_0:close() | ||
| 750 | end | ||
| 751 | print("hello") | ||
| 752 | print(1, 2) | ||
| 753 | print(1, 2, 3) | ||
| 754 | print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) | ||
| 755 | local a, b, c, d | ||
| 756 | if b ~= nil then | ||
| 757 | a = b | ||
| 758 | else | ||
| 759 | if c ~= nil then | ||
| 760 | a = c | ||
| 761 | else | ||
| 762 | a = d | ||
| 763 | end | ||
| 764 | end | ||
| 765 | func((function() | ||
| 766 | if a ~= nil then | ||
| 767 | return a | ||
| 768 | else | ||
| 769 | return { } | ||
| 770 | end | ||
| 771 | end)()) | ||
| 772 | if a == nil then | ||
| 773 | a = false | ||
| 774 | end | ||
| 775 | local list = { | ||
| 776 | 1, | ||
| 777 | 2, | ||
| 778 | 3 | ||
| 779 | } | ||
| 780 | func({ | ||
| 781 | 1, | ||
| 782 | 2, | ||
| 783 | 3 | ||
| 784 | }) | ||
| 785 | local f | ||
| 786 | f = function() | ||
| 787 | return { | ||
| 788 | 1, | ||
| 789 | 2, | ||
| 790 | 3 | ||
| 791 | } | ||
| 792 | end | ||
| 793 | local tb = { | ||
| 794 | name = "abc", | ||
| 795 | values = { | ||
| 796 | "a", | ||
| 797 | "b", | ||
| 798 | "c" | ||
| 799 | }, | ||
| 800 | objects = { | ||
| 801 | { | ||
| 802 | name = "a", | ||
| 803 | value = 1, | ||
| 804 | func = function(self) | ||
| 805 | return self.value + 1 | ||
| 806 | end, | ||
| 807 | tb = { | ||
| 808 | fieldA = 1 | ||
| 809 | } | ||
| 810 | }, | ||
| 811 | { | ||
| 812 | name = "b", | ||
| 813 | value = 2, | ||
| 814 | func = function(self) | ||
| 815 | return self.value + 2 | ||
| 816 | end, | ||
| 817 | tb = { } | ||
| 818 | } | ||
| 819 | } | ||
| 820 | } | ||
| 821 | do | ||
| 822 | local insert, concat = table.insert, table.concat | ||
| 823 | local C, Ct, Cmt | ||
| 824 | do | ||
| 825 | local _obj_0 = require("lpeg") | ||
| 826 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | ||
| 827 | end | ||
| 828 | local x, y, z | ||
| 829 | do | ||
| 830 | local _obj_0 = require('mymodule') | ||
| 831 | x, y, z = _obj_0.x, _obj_0.y, _obj_0.z | ||
| 832 | end | ||
| 833 | local a, b, c | ||
| 834 | local _obj_0 = require('module') | ||
| 835 | a, b, c = _obj_0.a, _obj_0.b, _obj_0.c | ||
| 836 | end | ||
| 837 | do | ||
| 838 | local module = require('module') | ||
| 839 | local module_x = require('module_x') | ||
| 840 | local d_a_s_h_e_s = require("d-a-s-h-e-s") | ||
| 841 | local part = require("module.part") | ||
| 842 | end | ||
| 843 | do | ||
| 844 | local PlayerModule = require("player") | ||
| 845 | local C, Ct, Cmt | ||
| 846 | do | ||
| 847 | local _obj_0 = require("lpeg") | ||
| 848 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | ||
| 849 | end | ||
| 850 | local one, two, ch | ||
| 851 | local _obj_0 = require("export") | ||
| 852 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | ||
| 853 | end | ||
| 854 | do | ||
| 855 | local tostring <const> = tostring | ||
| 856 | local concat <const> = table.concat | ||
| 857 | print(concat({ | ||
| 858 | "a", | ||
| 859 | tostring(1) | ||
| 860 | })) | ||
| 861 | end | ||
| 862 | do | ||
| 863 | local print <const> = print | ||
| 864 | local math <const> = math | ||
| 865 | print("hello") | ||
| 866 | math.random(3) | ||
| 867 | end | ||
| 868 | do | ||
| 869 | local print <const> = print | ||
| 870 | print(FLAG) | ||
| 871 | FLAG = 123 | ||
| 872 | end | ||
| 873 | local _module_0 = { } | ||
| 874 | local a, b, c = 1, 2, 3 | ||
| 875 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | ||
| 876 | local cool = "cat" | ||
| 877 | _module_0["cool"] = cool | ||
| 878 | local What | ||
| 879 | if this then | ||
| 880 | What = "abc" | ||
| 881 | else | ||
| 882 | What = "def" | ||
| 883 | end | ||
| 884 | _module_0["What"] = What | ||
| 885 | local y | ||
| 886 | y = function() | ||
| 887 | local hallo = 3434 | ||
| 888 | end | ||
| 889 | _module_0["y"] = y | ||
| 890 | local Something | ||
| 891 | local _class_0 | ||
| 892 | local _base_0 = { | ||
| 893 | umm = "cool" | ||
| 894 | } | ||
| 895 | if _base_0.__index == nil then | ||
| 896 | _base_0.__index = _base_0 | ||
| 897 | end | ||
| 898 | _class_0 = setmetatable({ | ||
| 899 | __init = function() end, | ||
| 900 | __base = _base_0, | ||
| 901 | __name = "Something" | ||
| 902 | }, { | ||
| 903 | __index = _base_0, | ||
| 904 | __call = function(cls, ...) | ||
| 905 | local _self_0 = setmetatable({ }, _base_0) | ||
| 906 | cls.__init(_self_0, ...) | ||
| 907 | return _self_0 | ||
| 908 | end | ||
| 909 | }) | ||
| 910 | _base_0.__class = _class_0 | ||
| 911 | Something = _class_0 | ||
| 912 | _module_0["Something"] = Something | ||
| 913 | return _module_0 | ||
| 914 | local _module_0 = { } | ||
| 915 | local loadstring, tolua | ||
| 916 | do | ||
| 917 | local _obj_0 = yue | ||
| 918 | loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua | ||
| 919 | end | ||
| 920 | _module_0["loadstring"], _module_0["tolua"] = loadstring, tolua | ||
| 921 | local fieldA = tb.itemA.fieldA | ||
| 922 | if fieldA == nil then | ||
| 923 | fieldA = 'default' | ||
| 924 | end | ||
| 925 | _module_0["fieldA"] = fieldA | ||
| 926 | return _module_0 | ||
| 927 | local _module_0 = setmetatable({ }, { }) | ||
| 928 | _module_0.itemA = tb | ||
| 929 | getmetatable(_module_0).__index = items | ||
| 930 | _module_0["a-b-c"] = 123 | ||
| 931 | return _module_0 | ||
| 932 | local _module_0 = { } | ||
| 933 | local d, e, f = 3, 2, 1 | ||
| 934 | _module_0[#_module_0 + 1] = d | ||
| 935 | _module_0[#_module_0 + 1] = e | ||
| 936 | _module_0[#_module_0 + 1] = f | ||
| 937 | if this then | ||
| 938 | _module_0[#_module_0 + 1] = 123 | ||
| 939 | else | ||
| 940 | _module_0[#_module_0 + 1] = 456 | ||
| 941 | end | ||
| 942 | local _with_0 = tmp | ||
| 943 | local j = 2000 | ||
| 944 | _module_0[#_module_0 + 1] = _with_0 | ||
| 945 | return _module_0 | ||
| 946 | local _module_0 = nil | ||
| 947 | _module_0 = function() | ||
| 948 | print("hello") | ||
| 949 | return 123 | ||
| 950 | end | ||
| 951 | return _module_0 | ||
| 952 | do | ||
| 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 | ||
| 967 | end | ||
| 968 | do | ||
| 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") | ||
| 973 | end | ||
| 974 | do | ||
| 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] | ||
| 984 | end | ||
| 985 | do | ||
| 986 | local tostring <const> = tostring | ||
| 987 | local concat <const> = table.concat | ||
| 988 | print(concat({ | ||
| 989 | "a", | ||
| 990 | tostring(1) | ||
| 991 | })) | ||
| 992 | end | ||
| 993 | do | ||
| 994 | local print <const> = print | ||
| 995 | local math <const> = math | ||
| 996 | print("hello") | ||
| 997 | math.random(3) | ||
| 998 | end | ||
| 999 | do | ||
| 1000 | local print <const> = print | ||
| 1001 | print(FLAG) | ||
| 1002 | FLAG = 123 | ||
| 1003 | end | ||
| 1004 | local _module_0 = { } | ||
| 1005 | local a, b, c = 1, 2, 3 | ||
| 1006 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | ||
| 1007 | local cool = "cat" | ||
| 1008 | _module_0["cool"] = cool | ||
| 1009 | local What | ||
| 1010 | if this then | ||
| 1011 | What = "abc" | ||
| 1012 | else | ||
| 1013 | What = "def" | ||
| 1014 | end | ||
| 1015 | _module_0["What"] = What | ||
| 1016 | local y | ||
| 1017 | y = function() | ||
| 1018 | local hallo = 3434 | ||
| 1019 | end | ||
| 1020 | _module_0["y"] = y | ||
| 1021 | local Something | ||
| 1022 | local _class_0 | ||
| 1023 | local _base_0 = { | ||
| 1024 | umm = "cool" | ||
| 1025 | } | ||
| 1026 | if _base_0.__index == nil then | ||
| 1027 | _base_0.__index = _base_0 | ||
| 1028 | end | ||
| 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 | ||
| 1042 | Something = _class_0 | ||
| 1043 | _module_0["Something"] = Something | ||
| 1044 | return _module_0 | ||
| 1045 | local _module_0 = { } | ||
| 1046 | local loadstring, tolua | ||
| 1047 | do | ||
| 1048 | local _obj_0 = yue | ||
| 1049 | loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua | ||
| 1050 | end | ||
| 1051 | _module_0["loadstring"], _module_0["tolua"] = loadstring, tolua | ||
| 1052 | local fieldA = tb.itemA.fieldA | ||
| 1053 | if fieldA == nil then | ||
| 1054 | fieldA = 'default' | ||
| 1055 | end | ||
| 1056 | _module_0["fieldA"] = fieldA | ||
| 1057 | return _module_0 | ||
| 1058 | local _module_0 = setmetatable({ }, { }) | ||
| 1059 | _module_0.itemA = tb | ||
| 1060 | getmetatable(_module_0).__index = items | ||
| 1061 | _module_0["a-b-c"] = 123 | ||
| 1062 | return _module_0 | ||
| 1063 | local _module_0 = { } | ||
| 1064 | local 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 | ||
| 1068 | if this then | ||
| 1069 | _module_0[#_module_0 + 1] = 123 | ||
| 1070 | else | ||
| 1071 | _module_0[#_module_0 + 1] = 456 | ||
| 1072 | end | ||
| 1073 | local _with_0 = tmp | ||
| 1074 | local j = 2000 | ||
| 1075 | _module_0[#_module_0 + 1] = _with_0 | ||
| 1076 | return _module_0 | ||
| 1077 | local _module_0 = nil | ||
| 1078 | _module_0 = function() | ||
| 1079 | print("hello") | ||
| 1080 | return 123 | ||
| 1081 | end | ||
| 1082 | return _module_0 | ||
| 1083 | local hello = "world" | ||
| 1084 | local a, b, c = 1, 2, 3 | ||
| 1085 | hello = 123 | ||
| 1086 | local x = 1 | ||
| 1087 | x = x + 1 | ||
| 1088 | x = x - 1 | ||
| 1089 | x = x * 10 | ||
| 1090 | x = x / 10 | ||
| 1091 | x = x % 10 | ||
| 1092 | local s = s .. "world" | ||
| 1093 | local arg = arg or "default value" | ||
| 1094 | local a = 0 | ||
| 1095 | local b = 0 | ||
| 1096 | local c = 0 | ||
| 1097 | local d = 0 | ||
| 1098 | local e = 0 | ||
| 1099 | local x = f() | ||
| 1100 | local y = x | ||
| 1101 | local z = x | ||
| 1102 | do | ||
| 1103 | local a = 1 | ||
| 1104 | local x, y, z | ||
| 1105 | print("forward declare all variables as locals") | ||
| 1106 | x = function() | ||
| 1107 | return 1 + y + z | ||
| 1108 | end | ||
| 1109 | y, z = 2, 3 | ||
| 1110 | instance = Item:new() | ||
| 1111 | end | ||
| 1112 | do | ||
| 1113 | local X = 1 | ||
| 1114 | local B | ||
| 1115 | print("only forward declare upper case variables") | ||
| 1116 | local a = 1 | ||
| 1117 | B = 2 | ||
| 1118 | end | ||
| 1119 | do | ||
| 1120 | a = 1 | ||
| 1121 | print("declare all variables as globals") | ||
| 1122 | x = function() | ||
| 1123 | return 1 + y + z | ||
| 1124 | end | ||
| 1125 | y, z = 2, 3 | ||
| 1126 | end | ||
| 1127 | do | ||
| 1128 | X = 1 | ||
| 1129 | print("only declare upper case variables as globals") | ||
| 1130 | local a = 1 | ||
| 1131 | B = 2 | ||
| 1132 | local Temp = "a local value" | ||
| 1133 | end | ||
| 1134 | local hello = "world" | ||
| 1135 | local a, b, c = 1, 2, 3 | ||
| 1136 | hello = 123 | ||
| 1137 | local x = 1 | ||
| 1138 | x = x + 1 | ||
| 1139 | x = x - 1 | ||
| 1140 | x = x * 10 | ||
| 1141 | x = x / 10 | ||
| 1142 | x = x % 10 | ||
| 1143 | local s = s .. "world" | ||
| 1144 | local arg = arg or "default value" | ||
| 1145 | local a = 0 | ||
| 1146 | local b = 0 | ||
| 1147 | local c = 0 | ||
| 1148 | local d = 0 | ||
| 1149 | local e = 0 | ||
| 1150 | local x = f() | ||
| 1151 | local y = x | ||
| 1152 | local z = x | ||
| 1153 | do | ||
| 1154 | local a = 1 | ||
| 1155 | local x, y, z | ||
| 1156 | print("forward declare all variables as locals") | ||
| 1157 | x = function() | ||
| 1158 | return 1 + y + z | ||
| 1159 | end | ||
| 1160 | y, z = 2, 3 | ||
| 1161 | instance = Item:new() | ||
| 1162 | end | ||
| 1163 | do | ||
| 1164 | local X = 1 | ||
| 1165 | local B | ||
| 1166 | print("only forward declare upper case variables") | ||
| 1167 | local a = 1 | ||
| 1168 | B = 2 | ||
| 1169 | end | ||
| 1170 | do | ||
| 1171 | a = 1 | ||
| 1172 | print("declare all variables as globals") | ||
| 1173 | x = function() | ||
| 1174 | return 1 + y + z | ||
| 1175 | end | ||
| 1176 | y, z = 2, 3 | ||
| 1177 | end | ||
| 1178 | do | ||
| 1179 | X = 1 | ||
| 1180 | print("only declare upper case variables as globals") | ||
| 1181 | local a = 1 | ||
| 1182 | B = 2 | ||
| 1183 | local Temp = "a local value" | ||
| 1184 | end | ||
| 1185 | local thing = { | ||
| 1186 | 1, | ||
| 1187 | 2 | ||
| 1188 | } | ||
| 1189 | local a, b = thing[1], thing[2] | ||
| 1190 | print(a, b) | ||
| 1191 | local obj = { | ||
| 1192 | hello = "world", | ||
| 1193 | day = "tuesday", | ||
| 1194 | length = 20 | ||
| 1195 | } | ||
| 1196 | local hello, the_day = obj.hello, obj.day | ||
| 1197 | print(hello, the_day) | ||
| 1198 | local day = obj.day | ||
| 1199 | local obj2 = { | ||
| 1200 | numbers = { | ||
| 1201 | 1, | ||
| 1202 | 2, | ||
| 1203 | 3, | ||
| 1204 | 4 | ||
| 1205 | }, | ||
| 1206 | properties = { | ||
| 1207 | color = "green", | ||
| 1208 | height = 13.5 | ||
| 1209 | } | ||
| 1210 | } | ||
| 1211 | local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color | ||
| 1212 | print(first, second, color) | ||
| 1213 | local first, second, color | ||
| 1214 | local _obj_0 = obj2 | ||
| 1215 | first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color | ||
| 1216 | local concat, insert | ||
| 1217 | local _obj_0 = table | ||
| 1218 | concat, insert = _obj_0.concat, _obj_0.insert | ||
| 1219 | local mix, max, rand | ||
| 1220 | local _obj_0 = math | ||
| 1221 | mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random | ||
| 1222 | local name, job | ||
| 1223 | local _obj_0 = person | ||
| 1224 | name, job = _obj_0.name, _obj_0.job | ||
| 1225 | if name == nil then | ||
| 1226 | name = "nameless" | ||
| 1227 | end | ||
| 1228 | if job == nil then | ||
| 1229 | job = "jobless" | ||
| 1230 | end | ||
| 1231 | local two, four | ||
| 1232 | local _obj_0 = items | ||
| 1233 | two, four = _obj_0[2], _obj_0[4] | ||
| 1234 | local orders = { | ||
| 1235 | "first", | ||
| 1236 | "second", | ||
| 1237 | "third", | ||
| 1238 | "fourth", | ||
| 1239 | "last" | ||
| 1240 | } | ||
| 1241 | local first, bulk, last = orders[1], (function() | ||
| 1242 | local _accum_0 = { } | ||
| 1243 | local _len_0 = 1 | ||
| 1244 | local _max_0 = #orders + -2 + 1 | ||
| 1245 | for _index_0 = 2, _max_0 do | ||
| 1246 | local _item_0 = orders[_index_0] | ||
| 1247 | _accum_0[_len_0] = _item_0 | ||
| 1248 | _len_0 = _len_0 + 1 | ||
| 1249 | end | ||
| 1250 | return _accum_0 | ||
| 1251 | end)(), orders[#orders] | ||
| 1252 | print(first) | ||
| 1253 | print(bulk) | ||
| 1254 | print(last) | ||
| 1255 | local first, rest | ||
| 1256 | do | ||
| 1257 | local _obj_0 = orders | ||
| 1258 | first, rest = _obj_0[1], (function() | ||
| 1259 | local _accum_0 = { } | ||
| 1260 | local _len_0 = 1 | ||
| 1261 | local _max_0 = #_obj_0 | ||
| 1262 | for _index_0 = 2, _max_0 do | ||
| 1263 | local _item_0 = _obj_0[_index_0] | ||
| 1264 | _accum_0[_len_0] = _item_0 | ||
| 1265 | _len_0 = _len_0 + 1 | ||
| 1266 | end | ||
| 1267 | return _accum_0 | ||
| 1268 | end)() | ||
| 1269 | end | ||
| 1270 | local start, last | ||
| 1271 | do | ||
| 1272 | local _obj_0 = orders | ||
| 1273 | start, last = (function() | ||
| 1274 | local _accum_0 = { } | ||
| 1275 | local _len_0 = 1 | ||
| 1276 | local _max_0 = #_obj_0 + -2 + 1 | ||
| 1277 | for _index_0 = 1, _max_0 do | ||
| 1278 | local _item_0 = _obj_0[_index_0] | ||
| 1279 | _accum_0[_len_0] = _item_0 | ||
| 1280 | _len_0 = _len_0 + 1 | ||
| 1281 | end | ||
| 1282 | return _accum_0 | ||
| 1283 | end)(), _obj_0[#_obj_0] | ||
| 1284 | end | ||
| 1285 | local _obj_0 = orders | ||
| 1286 | first, last = _obj_0[1], _obj_0[#_obj_0] | ||
| 1287 | local tuples = { | ||
| 1288 | { | ||
| 1289 | "hello", | ||
| 1290 | "world" | ||
| 1291 | }, | ||
| 1292 | { | ||
| 1293 | "egg", | ||
| 1294 | "head" | ||
| 1295 | } | ||
| 1296 | } | ||
| 1297 | for _index_0 = 1, #tuples do | ||
| 1298 | local _des_0 = tuples[_index_0] | ||
| 1299 | local left, right = _des_0[1], _des_0[2] | ||
| 1300 | print(left, right) | ||
| 1301 | end | ||
| 1302 | local thing = { | ||
| 1303 | 1, | ||
| 1304 | 2 | ||
| 1305 | } | ||
| 1306 | local a, b = thing[1], thing[2] | ||
| 1307 | print(a, b) | ||
| 1308 | local obj = { | ||
| 1309 | hello = "world", | ||
| 1310 | day = "tuesday", | ||
| 1311 | length = 20 | ||
| 1312 | } | ||
| 1313 | local hello, the_day = obj.hello, obj.day | ||
| 1314 | print(hello, the_day) | ||
| 1315 | local day = obj.day | ||
| 1316 | local obj2 = { | ||
| 1317 | numbers = { | ||
| 1318 | 1, | ||
| 1319 | 2, | ||
| 1320 | 3, | ||
| 1321 | 4 | ||
| 1322 | }, | ||
| 1323 | properties = { | ||
| 1324 | color = "green", | ||
| 1325 | height = 13.5 | ||
| 1326 | } | ||
| 1327 | } | ||
| 1328 | local first, second, color = obj2.numbers[1], obj2.numbers[2], obj2.properties.color | ||
| 1329 | print(first, second, color) | ||
| 1330 | local first, second, color | ||
| 1331 | local _obj_0 = obj2 | ||
| 1332 | first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color | ||
| 1333 | local concat, insert | ||
| 1334 | local _obj_0 = table | ||
| 1335 | concat, insert = _obj_0.concat, _obj_0.insert | ||
| 1336 | local mix, max, rand | ||
| 1337 | local _obj_0 = math | ||
| 1338 | mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random | ||
| 1339 | local name, job | ||
| 1340 | local _obj_0 = person | ||
| 1341 | name, job = _obj_0.name, _obj_0.job | ||
| 1342 | if name == nil then | ||
| 1343 | name = "nameless" | ||
| 1344 | end | ||
| 1345 | if job == nil then | ||
| 1346 | job = "jobless" | ||
| 1347 | end | ||
| 1348 | local two, four | ||
| 1349 | local _obj_0 = items | ||
| 1350 | two, four = _obj_0[2], _obj_0[4] | ||
| 1351 | local orders = { | ||
| 1352 | "first", | ||
| 1353 | "second", | ||
| 1354 | "third", | ||
| 1355 | "fourth", | ||
| 1356 | "last" | ||
| 1357 | } | ||
| 1358 | local 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 | ||
| 1368 | end)(), orders[#orders] | ||
| 1369 | print(first) | ||
| 1370 | print(bulk) | ||
| 1371 | print(last) | ||
| 1372 | local first, rest | ||
| 1373 | do | ||
| 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)() | ||
| 1386 | end | ||
| 1387 | local start, last | ||
| 1388 | do | ||
| 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] | ||
| 1401 | end | ||
| 1402 | local _obj_0 = orders | ||
| 1403 | first, last = _obj_0[1], _obj_0[#_obj_0] | ||
| 1404 | local tuples = { | ||
| 1405 | { | ||
| 1406 | "hello", | ||
| 1407 | "world" | ||
| 1408 | }, | ||
| 1409 | { | ||
| 1410 | "egg", | ||
| 1411 | "head" | ||
| 1412 | } | ||
| 1413 | } | ||
| 1414 | for _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) | ||
| 1418 | end | ||
| 1419 | local user = database.find_user("moon") | ||
| 1420 | if user then | ||
| 1421 | print(user.name) | ||
| 1422 | end | ||
| 1423 | local hello = os.getenv("hello") | ||
| 1424 | if hello then | ||
| 1425 | print("You have hello", hello) | ||
| 1426 | else | ||
| 1427 | local world = os.getenv("world") | ||
| 1428 | if world then | ||
| 1429 | print("you have world", world) | ||
| 1430 | else | ||
| 1431 | print("nothing :(") | ||
| 1432 | end | ||
| 1433 | end | ||
| 1434 | do | ||
| 1435 | local success, result = pcall(function() | ||
| 1436 | return "get result without problems" | ||
| 1437 | end) | ||
| 1438 | if success then | ||
| 1439 | print(result) | ||
| 1440 | end | ||
| 1441 | end | ||
| 1442 | print("OK") | ||
| 1443 | repeat | ||
| 1444 | local byte = stream:read_one() | ||
| 1445 | if byte then | ||
| 1446 | print(byte) | ||
| 1447 | else | ||
| 1448 | break | ||
| 1449 | end | ||
| 1450 | until false | ||
| 1451 | local user = database.find_user("moon") | ||
| 1452 | if user then | ||
| 1453 | print(user.name) | ||
| 1454 | end | ||
| 1455 | local hello = os.getenv("hello") | ||
| 1456 | if hello then | ||
| 1457 | print("You have hello", hello) | ||
| 1458 | else | ||
| 1459 | local world = os.getenv("world") | ||
| 1460 | if world then | ||
| 1461 | print("you have world", world) | ||
| 1462 | else | ||
| 1463 | print("nothing :(") | ||
| 1464 | end | ||
| 1465 | end | ||
| 1466 | do | ||
| 1467 | local success, result = pcall(function() | ||
| 1468 | return "get result without problems" | ||
| 1469 | end) | ||
| 1470 | if success then | ||
| 1471 | print(result) | ||
| 1472 | end | ||
| 1473 | end | ||
| 1474 | print("OK") | ||
| 1475 | repeat | ||
| 1476 | local byte = stream:read_one() | ||
| 1477 | if byte then | ||
| 1478 | print(byte) | ||
| 1479 | else | ||
| 1480 | break | ||
| 1481 | end | ||
| 1482 | until false | ||
| 1483 | local list = { | ||
| 1484 | 1, | ||
| 1485 | 2, | ||
| 1486 | 3, | ||
| 1487 | 4, | ||
| 1488 | 5 | ||
| 1489 | } | ||
| 1490 | local fn | ||
| 1491 | fn = function(ok) | ||
| 1492 | return ok, table.unpack(list) | ||
| 1493 | end | ||
| 1494 | (function(_arg_0, ...) | ||
| 1495 | local ok = _arg_0 | ||
| 1496 | local count = select('#', ...) | ||
| 1497 | local first = select(1, ...) | ||
| 1498 | return print(ok, count, first) | ||
| 1499 | end)(fn(true)) | ||
| 1500 | local list = { | ||
| 1501 | 1, | ||
| 1502 | 2, | ||
| 1503 | 3, | ||
| 1504 | 4, | ||
| 1505 | 5 | ||
| 1506 | } | ||
| 1507 | local fn | ||
| 1508 | fn = function(ok) | ||
| 1509 | return ok, table.unpack(list) | ||
| 1510 | end | ||
| 1511 | (function(_arg_0, ...) | ||
| 1512 | local ok = _arg_0 | ||
| 1513 | local count = select('#', ...) | ||
| 1514 | local first = select(1, ...) | ||
| 1515 | return print(ok, count, first) | ||
| 1516 | end)(fn(true)) | ||
| 1517 | local a = 1 | ||
| 1518 | local b = 2 | ||
| 1519 | print(a + b) | ||
| 1520 | Rx.Observable.fromRange(1, 8):filter(function(x) | ||
| 1521 | return x % 2 == 0 | ||
| 1522 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | ||
| 1523 | return value .. '!' | ||
| 1524 | end):subscribe(print) | ||
| 1525 | local a = 1 | ||
| 1526 | local b = 2 | ||
| 1527 | print(a + b) | ||
| 1528 | Rx.Observable.fromRange(1, 8):filter(function(x) | ||
| 1529 | return x % 2 == 0 | ||
| 1530 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | ||
| 1531 | return value .. '!' | ||
| 1532 | end):subscribe(print) | ||
| 1533 | local str = strA .. strB .. strC | ||
| 1534 | func(3000, "192.168.1.1") | ||
| 1535 | local str = strA .. strB .. strC | ||
| 1536 | func(3000, "192.168.1.1") | ||
| 1537 | xpcall(function() | ||
| 1538 | return func(1, 2, 3) | ||
| 1539 | end, function(err) | ||
| 1540 | return print(yue.traceback(err)) | ||
| 1541 | end) | ||
| 1542 | local success, result = xpcall(function() | ||
| 1543 | return func(1, 2, 3) | ||
| 1544 | end, function(err) | ||
| 1545 | return yue.traceback(err) | ||
| 1546 | end) | ||
| 1547 | xpcall(function() | ||
| 1548 | return func(1, 2, 3) | ||
| 1549 | end, function(err) | ||
| 1550 | return print(yue.traceback(err)) | ||
| 1551 | end) | ||
| 1552 | success, result = pcall(function() | ||
| 1553 | return func(1, 2, 3) | ||
| 1554 | end) | ||
| 1555 | pcall(function() | ||
| 1556 | print("trying") | ||
| 1557 | return func(1, 2, 3) | ||
| 1558 | end) | ||
| 1559 | success, result = xpcall(function() | ||
| 1560 | return func(1, 2, 3) | ||
| 1561 | end, function(err) | ||
| 1562 | return print(yue.traceback(err)) | ||
| 1563 | end) | ||
| 1564 | if success then | ||
| 1565 | print(result) | ||
| 1566 | end | ||
| 1567 | local a, b, c | ||
| 1568 | do | ||
| 1569 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
| 1570 | return func() | ||
| 1571 | end) | ||
| 1572 | if _ok_0 then | ||
| 1573 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
| 1574 | end | ||
| 1575 | end | ||
| 1576 | do | ||
| 1577 | local _exp_0 = ((function() | ||
| 1578 | return (function(_arg_0, ...) | ||
| 1579 | local _ok_0 = _arg_0 | ||
| 1580 | if _ok_0 then | ||
| 1581 | return ... | ||
| 1582 | end | ||
| 1583 | end)(pcall(function() | ||
| 1584 | return func() | ||
| 1585 | end)) | ||
| 1586 | end)()) | ||
| 1587 | if _exp_0 ~= nil then | ||
| 1588 | a = _exp_0 | ||
| 1589 | else | ||
| 1590 | a = "default" | ||
| 1591 | end | ||
| 1592 | end | ||
| 1593 | f((function() | ||
| 1594 | return (function(_arg_0, ...) | ||
| 1595 | local _ok_0 = _arg_0 | ||
| 1596 | if _ok_0 then | ||
| 1597 | return ... | ||
| 1598 | end | ||
| 1599 | end)(pcall(function() | ||
| 1600 | return func() | ||
| 1601 | end)) | ||
| 1602 | end)()) | ||
| 1603 | f((function() | ||
| 1604 | return (function(_arg_0, ...) | ||
| 1605 | local _ok_0 = _arg_0 | ||
| 1606 | if _ok_0 then | ||
| 1607 | return ... | ||
| 1608 | end | ||
| 1609 | end)(xpcall(function() | ||
| 1610 | print(123) | ||
| 1611 | return func() | ||
| 1612 | end, function(e) | ||
| 1613 | print(e) | ||
| 1614 | return e | ||
| 1615 | end)) | ||
| 1616 | end)()) | ||
| 1617 | xpcall(function() | ||
| 1618 | return func(1, 2, 3) | ||
| 1619 | end, function(err) | ||
| 1620 | return print(yue.traceback(err)) | ||
| 1621 | end) | ||
| 1622 | local success, result = xpcall(function() | ||
| 1623 | return func(1, 2, 3) | ||
| 1624 | end, function(err) | ||
| 1625 | return yue.traceback(err) | ||
| 1626 | end) | ||
| 1627 | xpcall(function() | ||
| 1628 | return func(1, 2, 3) | ||
| 1629 | end, function(err) | ||
| 1630 | return print(yue.traceback(err)) | ||
| 1631 | end) | ||
| 1632 | success, result = pcall(function() | ||
| 1633 | return func(1, 2, 3) | ||
| 1634 | end) | ||
| 1635 | pcall(function() | ||
| 1636 | print("trying") | ||
| 1637 | return func(1, 2, 3) | ||
| 1638 | end) | ||
| 1639 | success, result = xpcall(function() | ||
| 1640 | return func(1, 2, 3) | ||
| 1641 | end, function(err) | ||
| 1642 | return print(yue.traceback(err)) | ||
| 1643 | end) | ||
| 1644 | if success then | ||
| 1645 | print(result) | ||
| 1646 | end | ||
| 1647 | local a, b, c | ||
| 1648 | do | ||
| 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 | ||
| 1655 | end | ||
| 1656 | do | ||
| 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 | ||
| 1672 | end | ||
| 1673 | f((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)) | ||
| 1682 | end)()) | ||
| 1683 | f((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)) | ||
| 1696 | end)()) | ||
| 1697 | local a <const> = 123 | ||
| 1698 | local _ <close> = setmetatable({ }, { | ||
| 1699 | __close = function() | ||
| 1700 | return print("Out of scope.") | ||
| 1701 | end | ||
| 1702 | }) | ||
| 1703 | local a, b, c, d | ||
| 1704 | local _obj_0 = tb | ||
| 1705 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | ||
| 1706 | Constant = 123 | ||
| 1707 | local a <const> = 123 | ||
| 1708 | local _ <close> = setmetatable({ }, { | ||
| 1709 | __close = function() | ||
| 1710 | return print("Out of scope.") | ||
| 1711 | end | ||
| 1712 | }) | ||
| 1713 | local a, b, c, d | ||
| 1714 | local _obj_0 = tb | ||
| 1715 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | ||
| 1716 | Constant = 123 | ||
| 1717 | local some_string = "Here is a string\n that has a line break in it." | ||
| 1718 | print("I am " .. tostring(math.random() * 100) .. "% sure.") | ||
| 1719 | local integer = 1000000 | ||
| 1720 | local hex = 0xEFBBBF | ||
| 1721 | local binary = 19 | ||
| 1722 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
| 1723 | local fn | ||
| 1724 | fn = function() | ||
| 1725 | local str = "foo:\n bar: baz" | ||
| 1726 | return str | ||
| 1727 | end | ||
| 1728 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
| 1729 | local some_string = "Here is a string\n that has a line break in it." | ||
| 1730 | print("I am " .. tostring(math.random() * 100) .. "% sure.") | ||
| 1731 | local integer = 1000000 | ||
| 1732 | local hex = 0xEFBBBF | ||
| 1733 | local binary = 19 | ||
| 1734 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
| 1735 | local fn | ||
| 1736 | fn = function() | ||
| 1737 | local str = "foo:\n bar: baz" | ||
| 1738 | return str | ||
| 1739 | end | ||
| 1740 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
| 1741 | local my_function | ||
| 1742 | my_function = function() end | ||
| 1743 | my_function() | ||
| 1744 | local func_a | ||
| 1745 | func_a = function() | ||
| 1746 | return print("hello world") | ||
| 1747 | end | ||
| 1748 | local func_b | ||
| 1749 | func_b = function() | ||
| 1750 | local value = 100 | ||
| 1751 | return print("The value:", value) | ||
| 1752 | end | ||
| 1753 | func_a() | ||
| 1754 | func_b() | ||
| 1755 | local sum | ||
| 1756 | sum = function(x, y) | ||
| 1757 | return print("sum", x + y) | ||
| 1758 | end | ||
| 1759 | sum(10, 20) | ||
| 1760 | print(sum(10, 20)) | ||
| 1761 | a(b(c("a", "b", "c"))) | ||
| 1762 | print("x:", sum(10, 20), "y:", sum(30, 40)) | ||
| 1763 | local sum | ||
| 1764 | sum = function(x, y) | ||
| 1765 | return x + y | ||
| 1766 | end | ||
| 1767 | print("The sum is ", sum(10, 20)) | ||
| 1768 | local sum | ||
| 1769 | sum = function(x, y) | ||
| 1770 | return x + y | ||
| 1771 | end | ||
| 1772 | local mystery | ||
| 1773 | mystery = function(x, y) | ||
| 1774 | return x + y, x - y | ||
| 1775 | end | ||
| 1776 | local a, b = mystery(10, 20) | ||
| 1777 | local func | ||
| 1778 | func = function(self, num) | ||
| 1779 | return self.value + num | ||
| 1780 | end | ||
| 1781 | local my_function | ||
| 1782 | my_function = function(name, height) | ||
| 1783 | if name == nil then | ||
| 1784 | name = "something" | ||
| 1785 | end | ||
| 1786 | if height == nil then | ||
| 1787 | height = 100 | ||
| 1788 | end | ||
| 1789 | print("Hello I am", name) | ||
| 1790 | return print("My height is", height) | ||
| 1791 | end | ||
| 1792 | local some_args | ||
| 1793 | some_args = function(x, y) | ||
| 1794 | if x == nil then | ||
| 1795 | x = 100 | ||
| 1796 | end | ||
| 1797 | if y == nil then | ||
| 1798 | y = x + 1000 | ||
| 1799 | end | ||
| 1800 | return print(x + y) | ||
| 1801 | end | ||
| 1802 | local a = x - 10 | ||
| 1803 | local b = x - 10 | ||
| 1804 | local c = x(-y) | ||
| 1805 | local d = x - z | ||
| 1806 | local x = func("hello") + 100 | ||
| 1807 | local y = func("hello" + 100) | ||
| 1808 | my_func(5, 4, 3, 8, 9, 10) | ||
| 1809 | cool_func(1, 2, 3, 4, 5, 6, 7, 8) | ||
| 1810 | my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4) | ||
| 1811 | local x = { | ||
| 1812 | 1, | ||
| 1813 | 2, | ||
| 1814 | 3, | ||
| 1815 | 4, | ||
| 1816 | a_func(4, 5, 5, 6), | ||
| 1817 | 8, | ||
| 1818 | 9, | ||
| 1819 | 10 | ||
| 1820 | } | ||
| 1821 | local y = { | ||
| 1822 | my_func(1, 2, 3, 4, 5), | ||
| 1823 | 5, | ||
| 1824 | 6, | ||
| 1825 | 7 | ||
| 1826 | } | ||
| 1827 | if func(1, 2, 3, "hello", "world") then | ||
| 1828 | print("hello") | ||
| 1829 | print("I am inside if") | ||
| 1830 | end | ||
| 1831 | if func(1, 2, 3, "hello", "world") then | ||
| 1832 | print("hello") | ||
| 1833 | print("I am inside if") | ||
| 1834 | end | ||
| 1835 | local f1 | ||
| 1836 | f1 = function(_arg_0) | ||
| 1837 | local a, b, c | ||
| 1838 | a, b, c = _arg_0.a, _arg_0.b, _arg_0.c | ||
| 1839 | return print(a, b, c) | ||
| 1840 | end | ||
| 1841 | f1({ | ||
| 1842 | a = 1, | ||
| 1843 | b = "2", | ||
| 1844 | c = { } | ||
| 1845 | }) | ||
| 1846 | local f2 | ||
| 1847 | f2 = function(_arg_0, c) | ||
| 1848 | local a1, b | ||
| 1849 | a1, b = _arg_0.a, _arg_0.b | ||
| 1850 | if a1 == nil then | ||
| 1851 | a1 = 123 | ||
| 1852 | end | ||
| 1853 | if b == nil then | ||
| 1854 | b = 'abc' | ||
| 1855 | end | ||
| 1856 | if c == nil then | ||
| 1857 | c = { } | ||
| 1858 | end | ||
| 1859 | return print(a1, b, c) | ||
| 1860 | end | ||
| 1861 | local arg1 = { | ||
| 1862 | a = 0 | ||
| 1863 | } | ||
| 1864 | f2(arg1, arg2) | ||
| 1865 | local findFirstEven | ||
| 1866 | findFirstEven = function(list) | ||
| 1867 | for _index_0 = 1, #list do | ||
| 1868 | local item = list[_index_0] | ||
| 1869 | if type(item) == "table" then | ||
| 1870 | for _index_1 = 1, #item do | ||
| 1871 | local sub = item[_index_1] | ||
| 1872 | if sub % 2 == 0 then | ||
| 1873 | return sub | ||
| 1874 | end | ||
| 1875 | end | ||
| 1876 | end | ||
| 1877 | end | ||
| 1878 | return nil | ||
| 1879 | end | ||
| 1880 | local findFirstEven | ||
| 1881 | findFirstEven = function(list) | ||
| 1882 | for _index_0 = 1, #list do | ||
| 1883 | local item = list[_index_0] | ||
| 1884 | if type(item) == "table" then | ||
| 1885 | for _index_1 = 1, #item do | ||
| 1886 | local sub = item[_index_1] | ||
| 1887 | if sub % 2 == 0 then | ||
| 1888 | return sub | ||
| 1889 | end | ||
| 1890 | end | ||
| 1891 | end | ||
| 1892 | end | ||
| 1893 | return nil | ||
| 1894 | end | ||
| 1895 | local f | ||
| 1896 | f = function(...) | ||
| 1897 | local t = { | ||
| 1898 | n = select("#", ...), | ||
| 1899 | ... | ||
| 1900 | } | ||
| 1901 | print("argument count:", t.n) | ||
| 1902 | print("table length:", #t) | ||
| 1903 | for i = 1, t.n do | ||
| 1904 | print(t[i]) | ||
| 1905 | end | ||
| 1906 | end | ||
| 1907 | f(1, 2, 3) | ||
| 1908 | f("a", "b", "c", "d") | ||
| 1909 | f() | ||
| 1910 | local process | ||
| 1911 | process = function(...) | ||
| 1912 | local args = { | ||
| 1913 | n = select("#", ...), | ||
| 1914 | ... | ||
| 1915 | } | ||
| 1916 | local sum = 0 | ||
| 1917 | for i = 1, args.n do | ||
| 1918 | if args[i] ~= nil and type(args[i]) == "number" then | ||
| 1919 | sum = sum + args[i] | ||
| 1920 | end | ||
| 1921 | end | ||
| 1922 | return sum | ||
| 1923 | end | ||
| 1924 | process(1, nil, 3, nil, 5) | ||
| 1925 | local my_function | ||
| 1926 | my_function = function() end | ||
| 1927 | my_function() | ||
| 1928 | local func_a | ||
| 1929 | func_a = function() | ||
| 1930 | return print("hello world") | ||
| 1931 | end | ||
| 1932 | local func_b | ||
| 1933 | func_b = function() | ||
| 1934 | local value = 100 | ||
| 1935 | return print("The value:", value) | ||
| 1936 | end | ||
| 1937 | func_a() | ||
| 1938 | func_b() | ||
| 1939 | local sum | ||
| 1940 | sum = function(x, y) | ||
| 1941 | return print("sum", x + y) | ||
| 1942 | end | ||
| 1943 | sum(10, 20) | ||
| 1944 | print(sum(10, 20)) | ||
| 1945 | a(b(c("a", "b", "c"))) | ||
| 1946 | print("x:", sum(10, 20), "y:", sum(30, 40)) | ||
| 1947 | local sum | ||
| 1948 | sum = function(x, y) | ||
| 1949 | return x + y | ||
| 1950 | end | ||
| 1951 | print("The sum is ", sum(10, 20)) | ||
| 1952 | local sum | ||
| 1953 | sum = function(x, y) | ||
| 1954 | return x + y | ||
| 1955 | end | ||
| 1956 | local mystery | ||
| 1957 | mystery = function(x, y) | ||
| 1958 | return x + y, x - y | ||
| 1959 | end | ||
| 1960 | local a, b = mystery(10, 20) | ||
| 1961 | local func | ||
| 1962 | func = function(self, num) | ||
| 1963 | return self.value + num | ||
| 1964 | end | ||
| 1965 | local my_function | ||
| 1966 | my_function = function(name, height) | ||
| 1967 | if name == nil then | ||
| 1968 | name = "something" | ||
| 1969 | end | ||
| 1970 | if height == nil then | ||
| 1971 | height = 100 | ||
| 1972 | end | ||
| 1973 | print("Hello I am", name) | ||
| 1974 | return print("My height is", height) | ||
| 1975 | end | ||
| 1976 | local some_args | ||
| 1977 | some_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) | ||
| 1985 | end | ||
| 1986 | local a = x - 10 | ||
| 1987 | local b = x - 10 | ||
| 1988 | local c = x(-y) | ||
| 1989 | local d = x - z | ||
| 1990 | local x = func("hello") + 100 | ||
| 1991 | local y = func("hello" + 100) | ||
| 1992 | my_func(5, 4, 3, 8, 9, 10) | ||
| 1993 | cool_func(1, 2, 3, 4, 5, 6, 7, 8) | ||
| 1994 | my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4) | ||
| 1995 | local x = { | ||
| 1996 | 1, | ||
| 1997 | 2, | ||
| 1998 | 3, | ||
| 1999 | 4, | ||
| 2000 | a_func(4, 5, 5, 6), | ||
| 2001 | 8, | ||
| 2002 | 9, | ||
| 2003 | 10 | ||
| 2004 | } | ||
| 2005 | local y = { | ||
| 2006 | my_func(1, 2, 3, 4, 5), | ||
| 2007 | 5, | ||
| 2008 | 6, | ||
| 2009 | 7 | ||
| 2010 | } | ||
| 2011 | if func(1, 2, 3, "hello", "world") then | ||
| 2012 | print("hello") | ||
| 2013 | print("I am inside if") | ||
| 2014 | end | ||
| 2015 | if func(1, 2, 3, "hello", "world") then | ||
| 2016 | print("hello") | ||
| 2017 | print("I am inside if") | ||
| 2018 | end | ||
| 2019 | local f1 | ||
| 2020 | f1 = 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) | ||
| 2024 | end | ||
| 2025 | f1({ | ||
| 2026 | a = 1, | ||
| 2027 | b = "2", | ||
| 2028 | c = { } | ||
| 2029 | }) | ||
| 2030 | local f2 | ||
| 2031 | f2 = 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 | end | ||
| 2044 | print(a1, b, c) | ||
| 2045 | local arg1 = { | ||
| 2046 | a = 0 | ||
| 2047 | } | ||
| 2048 | f2(arg1, arg2) | ||
| 2049 | local findFirstEven | ||
| 2050 | findFirstEven = 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 | ||
| 2063 | end | ||
| 2064 | local findFirstEven | ||
| 2065 | findFirstEven = 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 | ||
| 2078 | end | ||
| 2079 | local f | ||
| 2080 | f = function(...) | ||
| 2081 | local t = { | ||
| 2082 | n = select("#", ...), | ||
| 2083 | ... | ||
| 2084 | } | ||
| 2085 | print("argument count:", t.n) | ||
| 2086 | print("table length:", #t) | ||
| 2087 | for i = 1, t.n do | ||
| 2088 | print(t[i]) | ||
| 2089 | end | ||
| 2090 | end | ||
| 2091 | f(1, 2, 3) | ||
| 2092 | f("a", "b", "c", "d") | ||
| 2093 | f() | ||
| 2094 | local process | ||
| 2095 | process = 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 | ||
| 2107 | end | ||
| 2108 | process(1, nil, 3, nil, 5) | ||
| 2109 | f(function(x) | ||
| 2110 | return print("hello" .. x) | ||
| 2111 | end) | ||
| 2112 | f(function(self) | ||
| 2113 | return print(self.value) | ||
| 2114 | end) | ||
| 2115 | map(function(x) | ||
| 2116 | return x * 2 | ||
| 2117 | end, { | ||
| 2118 | 1, | ||
| 2119 | 2, | ||
| 2120 | 3 | ||
| 2121 | }) | ||
| 2122 | local result, msg | ||
| 2123 | do | ||
| 2124 | result, msg = readAsync("filename.txt", function(data) | ||
| 2125 | print(data) | ||
| 2126 | return processAsync(data, function(info) | ||
| 2127 | return check(info) | ||
| 2128 | end) | ||
| 2129 | end) | ||
| 2130 | end | ||
| 2131 | print(result, msg) | ||
| 2132 | f(function(x) | ||
| 2133 | return print("hello" .. x) | ||
| 2134 | end) | ||
| 2135 | f(function(self) | ||
| 2136 | return print(self.value) | ||
| 2137 | end) | ||
| 2138 | map(function(x) | ||
| 2139 | return x * 2 | ||
| 2140 | end, { | ||
| 2141 | 1, | ||
| 2142 | 2, | ||
| 2143 | 3 | ||
| 2144 | }) | ||
| 2145 | local result, msg | ||
| 2146 | do | ||
| 2147 | result, msg = readAsync("filename.txt", function(data) | ||
| 2148 | print(data) | ||
| 2149 | return processAsync(data, function(info) | ||
| 2150 | return check(info) | ||
| 2151 | end) | ||
| 2152 | end) | ||
| 2153 | end | ||
| 2154 | print(result, msg) | ||
| 2155 | local some_values = { | ||
| 2156 | 1, | ||
| 2157 | 2, | ||
| 2158 | 3, | ||
| 2159 | 4 | ||
| 2160 | } | ||
| 2161 | local some_values = { | ||
| 2162 | name = "Bill", | ||
| 2163 | age = 200, | ||
| 2164 | ["favorite food"] = "rice" | ||
| 2165 | } | ||
| 2166 | local profile = { | ||
| 2167 | height = "4 feet", | ||
| 2168 | shoe_size = 13, | ||
| 2169 | favorite_foods = { | ||
| 2170 | "ice cream", | ||
| 2171 | "donuts" | ||
| 2172 | } | ||
| 2173 | } | ||
| 2174 | local values = { | ||
| 2175 | 1, | ||
| 2176 | 2, | ||
| 2177 | 3, | ||
| 2178 | 4, | ||
| 2179 | 5, | ||
| 2180 | 6, | ||
| 2181 | 7, | ||
| 2182 | 8, | ||
| 2183 | name = "superman", | ||
| 2184 | occupation = "crime fighting" | ||
| 2185 | } | ||
| 2186 | my_function({ | ||
| 2187 | dance = "Tango", | ||
| 2188 | partner = "none" | ||
| 2189 | }) | ||
| 2190 | local y = { | ||
| 2191 | type = "dog", | ||
| 2192 | legs = 4, | ||
| 2193 | tails = 1 | ||
| 2194 | } | ||
| 2195 | local tbl = { | ||
| 2196 | ["do"] = "something", | ||
| 2197 | ["end"] = "hunger" | ||
| 2198 | } | ||
| 2199 | local hair = "golden" | ||
| 2200 | local height = 200 | ||
| 2201 | local person = { | ||
| 2202 | hair = hair, | ||
| 2203 | height = height, | ||
| 2204 | shoe_size = 40 | ||
| 2205 | } | ||
| 2206 | print_table({ | ||
| 2207 | hair = hair, | ||
| 2208 | height = height | ||
| 2209 | }) | ||
| 2210 | local t = { | ||
| 2211 | [1 + 2] = "hello", | ||
| 2212 | ["hello world"] = true | ||
| 2213 | } | ||
| 2214 | local some_values = { | ||
| 2215 | 1, | ||
| 2216 | 2, | ||
| 2217 | 3, | ||
| 2218 | 4 | ||
| 2219 | } | ||
| 2220 | local list_with_one_element = { | ||
| 2221 | 1 | ||
| 2222 | } | ||
| 2223 | local some_values = { | ||
| 2224 | 1, | ||
| 2225 | 2, | ||
| 2226 | 3, | ||
| 2227 | 4 | ||
| 2228 | } | ||
| 2229 | local some_values = { | ||
| 2230 | name = "Bill", | ||
| 2231 | age = 200, | ||
| 2232 | ["favorite food"] = "rice" | ||
| 2233 | } | ||
| 2234 | local profile = { | ||
| 2235 | height = "4 feet", | ||
| 2236 | shoe_size = 13, | ||
| 2237 | favorite_foods = { | ||
| 2238 | "ice cream", | ||
| 2239 | "donuts" | ||
| 2240 | } | ||
| 2241 | } | ||
| 2242 | local values = { | ||
| 2243 | 1, | ||
| 2244 | 2, | ||
| 2245 | 3, | ||
| 2246 | 4, | ||
| 2247 | 5, | ||
| 2248 | 6, | ||
| 2249 | 7, | ||
| 2250 | 8, | ||
| 2251 | name = "superman", | ||
| 2252 | occupation = "crime fighting" | ||
| 2253 | } | ||
| 2254 | my_function({ | ||
| 2255 | dance = "Tango", | ||
| 2256 | partner = "none" | ||
| 2257 | }) | ||
| 2258 | local y = { | ||
| 2259 | type = "dog", | ||
| 2260 | legs = 4, | ||
| 2261 | tails = 1 | ||
| 2262 | } | ||
| 2263 | local tbl = { | ||
| 2264 | ["do"] = "something", | ||
| 2265 | ["end"] = "hunger" | ||
| 2266 | } | ||
| 2267 | local hair = "golden" | ||
| 2268 | local height = 200 | ||
| 2269 | local person = { | ||
| 2270 | hair = hair, | ||
| 2271 | height = height, | ||
| 2272 | shoe_size = 40 | ||
| 2273 | } | ||
| 2274 | print_table({ | ||
| 2275 | hair = hair, | ||
| 2276 | height = height | ||
| 2277 | }) | ||
| 2278 | local t = { | ||
| 2279 | [1 + 2] = "hello", | ||
| 2280 | ["hello world"] = true | ||
| 2281 | } | ||
| 2282 | local some_values = { | ||
| 2283 | 1, | ||
| 2284 | 2, | ||
| 2285 | 3, | ||
| 2286 | 4 | ||
| 2287 | } | ||
| 2288 | local list_with_one_element = { | ||
| 2289 | 1 | ||
| 2290 | } | ||
| 2291 | local items = { | ||
| 2292 | 1, | ||
| 2293 | 2, | ||
| 2294 | 3, | ||
| 2295 | 4 | ||
| 2296 | } | ||
| 2297 | local doubled | ||
| 2298 | local _accum_0 = { } | ||
| 2299 | local _len_0 = 1 | ||
| 2300 | for i, item in ipairs(items) do | ||
| 2301 | _accum_0[_len_0] = item * 2 | ||
| 2302 | _len_0 = _len_0 + 1 | ||
| 2303 | end | ||
| 2304 | doubled = _accum_0 | ||
| 2305 | local slice | ||
| 2306 | local _accum_0 = { } | ||
| 2307 | local _len_0 = 1 | ||
| 2308 | for i, item in ipairs(items) do | ||
| 2309 | if i > 1 and i < 3 then | ||
| 2310 | _accum_0[_len_0] = item | ||
| 2311 | _len_0 = _len_0 + 1 | ||
| 2312 | end | ||
| 2313 | end | ||
| 2314 | slice = _accum_0 | ||
| 2315 | local doubled | ||
| 2316 | local _accum_0 = { } | ||
| 2317 | local _len_0 = 1 | ||
| 2318 | local _list_0 = items | ||
| 2319 | for _index_0 = 1, #_list_0 do | ||
| 2320 | local item = _list_0[_index_0] | ||
| 2321 | _accum_0[_len_0] = item * 2 | ||
| 2322 | _len_0 = _len_0 + 1 | ||
| 2323 | end | ||
| 2324 | doubled = _accum_0 | ||
| 2325 | local data = { | ||
| 2326 | a = { | ||
| 2327 | 1, | ||
| 2328 | 2, | ||
| 2329 | 3 | ||
| 2330 | }, | ||
| 2331 | b = { | ||
| 2332 | 4, | ||
| 2333 | 5, | ||
| 2334 | 6 | ||
| 2335 | } | ||
| 2336 | } | ||
| 2337 | local flat | ||
| 2338 | local _accum_0 = { } | ||
| 2339 | for k, v in pairs(data) do | ||
| 2340 | local _len_0 = #_accum_0 + 1 | ||
| 2341 | for _index_0 = 1, #v do | ||
| 2342 | local _elm_0 = v[_index_0] | ||
| 2343 | _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 2344 | end | ||
| 2345 | end | ||
| 2346 | flat = _accum_0 | ||
| 2347 | local x_coords = { | ||
| 2348 | 4, | ||
| 2349 | 5, | ||
| 2350 | 6, | ||
| 2351 | 7 | ||
| 2352 | } | ||
| 2353 | local y_coords = { | ||
| 2354 | 9, | ||
| 2355 | 2, | ||
| 2356 | 3 | ||
| 2357 | } | ||
| 2358 | local points | ||
| 2359 | local _accum_0 = { } | ||
| 2360 | local _len_0 = 1 | ||
| 2361 | for _index_0 = 1, #x_coords do | ||
| 2362 | local x = x_coords[_index_0] | ||
| 2363 | for _index_1 = 1, #y_coords do | ||
| 2364 | local y = y_coords[_index_1] | ||
| 2365 | _accum_0[_len_0] = { | ||
| 2366 | x, | ||
| 2367 | y | ||
| 2368 | } | ||
| 2369 | _len_0 = _len_0 + 1 | ||
| 2370 | end | ||
| 2371 | end | ||
| 2372 | points = _accum_0 | ||
| 2373 | local evens | ||
| 2374 | local _accum_0 = { } | ||
| 2375 | local _len_0 = 1 | ||
| 2376 | for i = 1, 100 do | ||
| 2377 | if i % 2 == 0 then | ||
| 2378 | _accum_0[_len_0] = i | ||
| 2379 | _len_0 = _len_0 + 1 | ||
| 2380 | end | ||
| 2381 | end | ||
| 2382 | evens = _accum_0 | ||
| 2383 | local thing = { | ||
| 2384 | color = "red", | ||
| 2385 | name = "fast", | ||
| 2386 | width = 123 | ||
| 2387 | } | ||
| 2388 | local thing_copy | ||
| 2389 | local _tbl_0 = { } | ||
| 2390 | for k, v in pairs(thing) do | ||
| 2391 | _tbl_0[k] = v | ||
| 2392 | end | ||
| 2393 | thing_copy = _tbl_0 | ||
| 2394 | local no_color | ||
| 2395 | local _tbl_0 = { } | ||
| 2396 | for k, v in pairs(thing) do | ||
| 2397 | if k ~= "color" then | ||
| 2398 | _tbl_0[k] = v | ||
| 2399 | end | ||
| 2400 | end | ||
| 2401 | no_color = _tbl_0 | ||
| 2402 | local numbers = { | ||
| 2403 | 1, | ||
| 2404 | 2, | ||
| 2405 | 3, | ||
| 2406 | 4 | ||
| 2407 | } | ||
| 2408 | local sqrts | ||
| 2409 | local _tbl_0 = { } | ||
| 2410 | for _index_0 = 1, #numbers do | ||
| 2411 | local i = numbers[_index_0] | ||
| 2412 | _tbl_0[i] = math.sqrt(i) | ||
| 2413 | end | ||
| 2414 | sqrts = _tbl_0 | ||
| 2415 | local tuples = { | ||
| 2416 | { | ||
| 2417 | "hello", | ||
| 2418 | "world" | ||
| 2419 | }, | ||
| 2420 | { | ||
| 2421 | "foo", | ||
| 2422 | "bar" | ||
| 2423 | } | ||
| 2424 | } | ||
| 2425 | local tbl | ||
| 2426 | local _tbl_0 = { } | ||
| 2427 | for _index_0 = 1, #tuples do | ||
| 2428 | local tuple = tuples[_index_0] | ||
| 2429 | local _key_0, _val_0 = unpack(tuple) | ||
| 2430 | _tbl_0[_key_0] = _val_0 | ||
| 2431 | end | ||
| 2432 | tbl = _tbl_0 | ||
| 2433 | local slice | ||
| 2434 | local _accum_0 = { } | ||
| 2435 | local _len_0 = 1 | ||
| 2436 | local _list_0 = items | ||
| 2437 | for _index_0 = 1, 5 do | ||
| 2438 | local item = _list_0[_index_0] | ||
| 2439 | _accum_0[_len_0] = item | ||
| 2440 | _len_0 = _len_0 + 1 | ||
| 2441 | end | ||
| 2442 | slice = _accum_0 | ||
| 2443 | local slice | ||
| 2444 | local _accum_0 = { } | ||
| 2445 | local _len_0 = 1 | ||
| 2446 | local _list_0 = items | ||
| 2447 | local _max_0 = #_list_0 | ||
| 2448 | for _index_0 = 2, _max_0 do | ||
| 2449 | local item = _list_0[_index_0] | ||
| 2450 | _accum_0[_len_0] = item | ||
| 2451 | _len_0 = _len_0 + 1 | ||
| 2452 | end | ||
| 2453 | slice = _accum_0 | ||
| 2454 | local slice | ||
| 2455 | local _accum_0 = { } | ||
| 2456 | local _len_0 = 1 | ||
| 2457 | local _list_0 = items | ||
| 2458 | local _max_0 = #_list_0 | ||
| 2459 | for _index_0 = 1, _max_0, 2 do | ||
| 2460 | local item = _list_0[_index_0] | ||
| 2461 | _accum_0[_len_0] = item | ||
| 2462 | _len_0 = _len_0 + 1 | ||
| 2463 | end | ||
| 2464 | slice = _accum_0 | ||
| 2465 | local slice | ||
| 2466 | local _accum_0 = { } | ||
| 2467 | local _len_0 = 1 | ||
| 2468 | local _list_0 = items | ||
| 2469 | local _min_0 = #_list_0 + -4 + 1 | ||
| 2470 | local _max_0 = #_list_0 + -1 + 1 | ||
| 2471 | for _index_0 = _min_0, _max_0 do | ||
| 2472 | local item = _list_0[_index_0] | ||
| 2473 | _accum_0[_len_0] = item | ||
| 2474 | _len_0 = _len_0 + 1 | ||
| 2475 | end | ||
| 2476 | slice = _accum_0 | ||
| 2477 | local reverse_slice | ||
| 2478 | local _accum_0 = { } | ||
| 2479 | local _len_0 = 1 | ||
| 2480 | local _list_0 = items | ||
| 2481 | local _min_0 = #_list_0 + -1 + 1 | ||
| 2482 | for _index_0 = _min_0, 1, -1 do | ||
| 2483 | local item = _list_0[_index_0] | ||
| 2484 | _accum_0[_len_0] = item | ||
| 2485 | _len_0 = _len_0 + 1 | ||
| 2486 | end | ||
| 2487 | reverse_slice = _accum_0 | ||
| 2488 | local sub_list | ||
| 2489 | do | ||
| 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 | ||
| 2499 | end | ||
| 2500 | local last_four_items | ||
| 2501 | local _accum_0 = { } | ||
| 2502 | local _len_0 = 1 | ||
| 2503 | local _list_0 = items | ||
| 2504 | local _min_0 = #_list_0 + -4 + 1 | ||
| 2505 | local _max_0 = #_list_0 + -1 + 1 | ||
| 2506 | for _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 | ||
| 2510 | end | ||
| 2511 | last_four_items = _accum_0 | ||
| 2512 | local items = { | ||
| 2513 | 1, | ||
| 2514 | 2, | ||
| 2515 | 3, | ||
| 2516 | 4 | ||
| 2517 | } | ||
| 2518 | local doubled | ||
| 2519 | local _accum_0 = { } | ||
| 2520 | local _len_0 = 1 | ||
| 2521 | for i, item in ipairs(items) do | ||
| 2522 | _accum_0[_len_0] = item * 2 | ||
| 2523 | _len_0 = _len_0 + 1 | ||
| 2524 | end | ||
| 2525 | doubled = _accum_0 | ||
| 2526 | local slice | ||
| 2527 | local _accum_0 = { } | ||
| 2528 | local _len_0 = 1 | ||
| 2529 | for 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 | ||
| 2534 | end | ||
| 2535 | slice = _accum_0 | ||
| 2536 | local doubled | ||
| 2537 | local _accum_0 = { } | ||
| 2538 | local _len_0 = 1 | ||
| 2539 | local _list_0 = items | ||
| 2540 | for _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 | ||
| 2544 | end | ||
| 2545 | doubled = _accum_0 | ||
| 2546 | local data = { | ||
| 2547 | a = { | ||
| 2548 | 1, | ||
| 2549 | 2, | ||
| 2550 | 3 | ||
| 2551 | }, | ||
| 2552 | b = { | ||
| 2553 | 4, | ||
| 2554 | 5, | ||
| 2555 | 6 | ||
| 2556 | } | ||
| 2557 | } | ||
| 2558 | local flat | ||
| 2559 | local _accum_0 = { } | ||
| 2560 | for 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 | ||
| 2566 | end | ||
| 2567 | flat = _accum_0 | ||
| 2568 | local x_coords = { | ||
| 2569 | 4, | ||
| 2570 | 5, | ||
| 2571 | 6, | ||
| 2572 | 7 | ||
| 2573 | } | ||
| 2574 | local y_coords = { | ||
| 2575 | 9, | ||
| 2576 | 2, | ||
| 2577 | 3 | ||
| 2578 | } | ||
| 2579 | local points | ||
| 2580 | local _accum_0 = { } | ||
| 2581 | local _len_0 = 1 | ||
| 2582 | for _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 | ||
| 2592 | end | ||
| 2593 | points = _accum_0 | ||
| 2594 | local evens | ||
| 2595 | local _accum_0 = { } | ||
| 2596 | local _len_0 = 1 | ||
| 2597 | for i = 1, 100 do | ||
| 2598 | if i % 2 == 0 then | ||
| 2599 | _accum_0[_len_0] = i | ||
| 2600 | _len_0 = _len_0 + 1 | ||
| 2601 | end | ||
| 2602 | end | ||
| 2603 | evens = _accum_0 | ||
| 2604 | local thing = { | ||
| 2605 | color = "red", | ||
| 2606 | name = "fast", | ||
| 2607 | width = 123 | ||
| 2608 | } | ||
| 2609 | local thing_copy | ||
| 2610 | local _tbl_0 = { } | ||
| 2611 | for k, v in pairs(thing) do | ||
| 2612 | _tbl_0[k] = v | ||
| 2613 | end | ||
| 2614 | thing_copy = _tbl_0 | ||
| 2615 | local no_color | ||
| 2616 | local _tbl_0 = { } | ||
| 2617 | for k, v in pairs(thing) do | ||
| 2618 | if k ~= "color" then | ||
| 2619 | _tbl_0[k] = v | ||
| 2620 | end | ||
| 2621 | end | ||
| 2622 | no_color = _tbl_0 | ||
| 2623 | local numbers = { | ||
| 2624 | 1, | ||
| 2625 | 2, | ||
| 2626 | 3, | ||
| 2627 | 4 | ||
| 2628 | } | ||
| 2629 | local sqrts | ||
| 2630 | local _tbl_0 = { } | ||
| 2631 | for _index_0 = 1, #numbers do | ||
| 2632 | local i = numbers[_index_0] | ||
| 2633 | _tbl_0[i] = math.sqrt(i) | ||
| 2634 | end | ||
| 2635 | sqrts = _tbl_0 | ||
| 2636 | local tuples = { | ||
| 2637 | { | ||
| 2638 | "hello", | ||
| 2639 | "world" | ||
| 2640 | }, | ||
| 2641 | { | ||
| 2642 | "foo", | ||
| 2643 | "bar" | ||
| 2644 | } | ||
| 2645 | } | ||
| 2646 | local tbl | ||
| 2647 | local _tbl_0 = { } | ||
| 2648 | for _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 | ||
| 2652 | end | ||
| 2653 | tbl = _tbl_0 | ||
| 2654 | local slice | ||
| 2655 | local _accum_0 = { } | ||
| 2656 | local _len_0 = 1 | ||
| 2657 | local _list_0 = items | ||
| 2658 | for _index_0 = 1, 5 do | ||
| 2659 | local item = _list_0[_index_0] | ||
| 2660 | _accum_0[_len_0] = item | ||
| 2661 | _len_0 = _len_0 + 1 | ||
| 2662 | end | ||
| 2663 | slice = _accum_0 | ||
| 2664 | local slice | ||
| 2665 | local _accum_0 = { } | ||
| 2666 | local _len_0 = 1 | ||
| 2667 | local _list_0 = items | ||
| 2668 | local _max_0 = #_list_0 | ||
| 2669 | for _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 | ||
| 2673 | end | ||
| 2674 | slice = _accum_0 | ||
| 2675 | local slice | ||
| 2676 | local _accum_0 = { } | ||
| 2677 | local _len_0 = 1 | ||
| 2678 | local _list_0 = items | ||
| 2679 | local _max_0 = #_list_0 | ||
| 2680 | for _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 | ||
| 2684 | end | ||
| 2685 | slice = _accum_0 | ||
| 2686 | local slice | ||
| 2687 | local _accum_0 = { } | ||
| 2688 | local _len_0 = 1 | ||
| 2689 | local _list_0 = items | ||
| 2690 | local _min_0 = #_list_0 + -4 + 1 | ||
| 2691 | local _max_0 = #_list_0 + -1 + 1 | ||
| 2692 | for _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 | ||
| 2696 | end | ||
| 2697 | slice = _accum_0 | ||
| 2698 | local reverse_slice | ||
| 2699 | local _accum_0 = { } | ||
| 2700 | local _len_0 = 1 | ||
| 2701 | local _list_0 = items | ||
| 2702 | local _min_0 = #_list_0 + -1 + 1 | ||
| 2703 | for _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 | ||
| 2707 | end | ||
| 2708 | reverse_slice = _accum_0 | ||
| 2709 | local sub_list | ||
| 2710 | do | ||
| 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 | ||
| 2720 | end | ||
| 2721 | local last_four_items | ||
| 2722 | local _accum_0 = { } | ||
| 2723 | local _len_0 = 1 | ||
| 2724 | local _list_0 = items | ||
| 2725 | local _min_0 = #_list_0 + -4 + 1 | ||
| 2726 | local _max_0 = #_list_0 + -1 + 1 | ||
| 2727 | for _index_0 = _min_0, _max_0 do | ||
| 2728 | local _item_0 = _list_0[_index_0] | ||
| 2729 | _accum_0[_len_0] = _item_0 | ||
| 2730 | _len_0 = _len_0 + 1 | ||
| 2731 | end | ||
| 2732 | last_four_items = _accum_0 | ||
| 2733 | for i = 10, 20 do | ||
| 2734 | print(i) | ||
| 2735 | end | ||
| 2736 | for k = 1, 15, 2 do | ||
| 2737 | print(k) | ||
| 2738 | end | ||
| 2739 | for key, value in pairs(object) do | ||
| 2740 | print(key, value) | ||
| 2741 | end | ||
| 2742 | local _list_0 = items | ||
| 2743 | for _index_0 = 2, 4 do | ||
| 2744 | local item = _list_0[_index_0] | ||
| 2745 | print(item) | ||
| 2746 | end | ||
| 2747 | local _list_0 = items | ||
| 2748 | for _index_0 = 1, #_list_0 do | ||
| 2749 | local item = _list_0[_index_0] | ||
| 2750 | print(item) | ||
| 2751 | end | ||
| 2752 | for j = 1, 10, 3 do | ||
| 2753 | print(j) | ||
| 2754 | end | ||
| 2755 | local doubled_evens | ||
| 2756 | local _accum_0 = { } | ||
| 2757 | local _len_0 = 1 | ||
| 2758 | for i = 1, 20 do | ||
| 2759 | if i % 2 == 0 then | ||
| 2760 | _accum_0[_len_0] = i * 2 | ||
| 2761 | _len_0 = _len_0 + 1 | ||
| 2762 | else | ||
| 2763 | _accum_0[_len_0] = i | ||
| 2764 | _len_0 = _len_0 + 1 | ||
| 2765 | end | ||
| 2766 | end | ||
| 2767 | doubled_evens = _accum_0 | ||
| 2768 | local first_large | ||
| 2769 | local _accum_0 | ||
| 2770 | local _list_0 = numbers | ||
| 2771 | for _index_0 = 1, #_list_0 do | ||
| 2772 | local n = _list_0[_index_0] | ||
| 2773 | if n > 10 then | ||
| 2774 | _accum_0 = n | ||
| 2775 | break | ||
| 2776 | end | ||
| 2777 | end | ||
| 2778 | first_large = _accum_0 | ||
| 2779 | local func_a | ||
| 2780 | func_a = function() | ||
| 2781 | for i = 1, 10 do | ||
| 2782 | print(i) | ||
| 2783 | end | ||
| 2784 | end | ||
| 2785 | local func_b | ||
| 2786 | func_b = function() | ||
| 2787 | local _accum_0 = { } | ||
| 2788 | local _len_0 = 1 | ||
| 2789 | for i = 1, 10 do | ||
| 2790 | _accum_0[_len_0] = i | ||
| 2791 | _len_0 = _len_0 + 1 | ||
| 2792 | end | ||
| 2793 | return _accum_0 | ||
| 2794 | end | ||
| 2795 | print(func_a()) | ||
| 2796 | print(func_b()) | ||
| 2797 | for i = 10, 20 do | ||
| 2798 | print(i) | ||
| 2799 | end | ||
| 2800 | for k = 1, 15, 2 do | ||
| 2801 | print(k) | ||
| 2802 | end | ||
| 2803 | for key, value in pairs(object) do | ||
| 2804 | print(key, value) | ||
| 2805 | end | ||
| 2806 | local _list_0 = items | ||
| 2807 | for _index_0 = 2, 4 do | ||
| 2808 | local item = _list_0[_index_0] | ||
| 2809 | print(item) | ||
| 2810 | end | ||
| 2811 | local _list_0 = items | ||
| 2812 | for _index_0 = 1, #_list_0 do | ||
| 2813 | local item = _list_0[_index_0] | ||
| 2814 | print(item) | ||
| 2815 | end | ||
| 2816 | for j = 1, 10, 3 do | ||
| 2817 | print(j) | ||
| 2818 | end | ||
| 2819 | local doubled_evens | ||
| 2820 | local _accum_0 = { } | ||
| 2821 | local _len_0 = 1 | ||
| 2822 | for 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 | ||
| 2830 | end | ||
| 2831 | doubled_evens = _accum_0 | ||
| 2832 | local first_large | ||
| 2833 | local _accum_0 | ||
| 2834 | local _list_0 = numbers | ||
| 2835 | for _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 | ||
| 2841 | end | ||
| 2842 | first_large = _accum_0 | ||
| 2843 | local func_a | ||
| 2844 | func_a = function() | ||
| 2845 | for i = 1, 10 do | ||
| 2846 | print(i) | ||
| 2847 | end | ||
| 2848 | end | ||
| 2849 | local func_b | ||
| 2850 | func_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 | ||
| 2858 | end | ||
| 2859 | print(func_a()) | ||
| 2860 | print(func_b()) | ||
| 2861 | local i = 10 | ||
| 2862 | while i > 0 do | ||
| 2863 | print(i) | ||
| 2864 | i = i - 1 | ||
| 2865 | end | ||
| 2866 | while running == true do | ||
| 2867 | my_function() | ||
| 2868 | end | ||
| 2869 | local i = 10 | ||
| 2870 | while not (i == 0) do | ||
| 2871 | print(i) | ||
| 2872 | i = i - 1 | ||
| 2873 | end | ||
| 2874 | while not (running == false) do | ||
| 2875 | my_function() | ||
| 2876 | end | ||
| 2877 | local i = 10 | ||
| 2878 | repeat | ||
| 2879 | print(i) | ||
| 2880 | i = i - 1 | ||
| 2881 | until i == 0 | ||
| 2882 | local i = 10 | ||
| 2883 | while i > 0 do | ||
| 2884 | print(i) | ||
| 2885 | i = i - 1 | ||
| 2886 | end | ||
| 2887 | while running == true do | ||
| 2888 | my_function() | ||
| 2889 | end | ||
| 2890 | local i = 10 | ||
| 2891 | while not (i == 0) do | ||
| 2892 | print(i) | ||
| 2893 | i = i - 1 | ||
| 2894 | end | ||
| 2895 | while not (running == false) do | ||
| 2896 | my_function() | ||
| 2897 | end | ||
| 2898 | local i = 10 | ||
| 2899 | repeat | ||
| 2900 | print(i) | ||
| 2901 | i = i - 1 | ||
| 2902 | until i == 0 | ||
| 2903 | local i = 0 | ||
| 2904 | while i < 10 do | ||
| 2905 | i = i + 1 | ||
| 2906 | if i % 2 == 0 then | ||
| 2907 | goto _continue_0 | ||
| 2908 | end | ||
| 2909 | print(i) | ||
| 2910 | ::_continue_0:: | ||
| 2911 | end | ||
| 2912 | local my_numbers = { | ||
| 2913 | 1, | ||
| 2914 | 2, | ||
| 2915 | 3, | ||
| 2916 | 4, | ||
| 2917 | 5, | ||
| 2918 | 6 | ||
| 2919 | } | ||
| 2920 | local odds | ||
| 2921 | local _accum_0 = { } | ||
| 2922 | local _len_0 = 1 | ||
| 2923 | for _index_0 = 1, #my_numbers do | ||
| 2924 | local x = my_numbers[_index_0] | ||
| 2925 | if x % 2 == 1 then | ||
| 2926 | goto _continue_0 | ||
| 2927 | end | ||
| 2928 | _accum_0[_len_0] = x | ||
| 2929 | _len_0 = _len_0 + 1 | ||
| 2930 | ::_continue_0:: | ||
| 2931 | end | ||
| 2932 | odds = _accum_0 | ||
| 2933 | local i = 0 | ||
| 2934 | while 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:: | ||
| 2941 | end | ||
| 2942 | local my_numbers = { | ||
| 2943 | 1, | ||
| 2944 | 2, | ||
| 2945 | 3, | ||
| 2946 | 4, | ||
| 2947 | 5, | ||
| 2948 | 6 | ||
| 2949 | } | ||
| 2950 | local odds | ||
| 2951 | local _accum_0 = { } | ||
| 2952 | local _len_0 = 1 | ||
| 2953 | for _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:: | ||
| 2961 | end | ||
| 2962 | odds = _accum_0 | ||
| 2963 | local have_coins = false | ||
| 2964 | if have_coins then | ||
| 2965 | print("Got coins") | ||
| 2966 | else | ||
| 2967 | print("No coins") | ||
| 2968 | end | ||
| 2969 | local have_coins = false | ||
| 2970 | if have_coins then | ||
| 2971 | print("Got coins") | ||
| 2972 | else | ||
| 2973 | print("No coins") | ||
| 2974 | end | ||
| 2975 | local have_coins = false | ||
| 2976 | print((function() | ||
| 2977 | if have_coins then | ||
| 2978 | return "Got coins" | ||
| 2979 | else | ||
| 2980 | return "No coins" | ||
| 2981 | end | ||
| 2982 | end)()) | ||
| 2983 | local is_tall | ||
| 2984 | is_tall = function(name) | ||
| 2985 | if name == "Rob" then | ||
| 2986 | return true | ||
| 2987 | else | ||
| 2988 | return false | ||
| 2989 | end | ||
| 2990 | end | ||
| 2991 | local message | ||
| 2992 | if is_tall("Rob") then | ||
| 2993 | message = "I am very tall" | ||
| 2994 | else | ||
| 2995 | message = "I am not so tall" | ||
| 2996 | end | ||
| 2997 | print(message) | ||
| 2998 | if not (os.date("%A") == "Monday") then | ||
| 2999 | print("it is not Monday!") | ||
| 3000 | end | ||
| 3001 | if not (math.random() > 0.1) then | ||
| 3002 | print("You're lucky!") | ||
| 3003 | end | ||
| 3004 | local a = 5 | ||
| 3005 | if (1 == a or 3 == a or 5 == a or 7 == a) then | ||
| 3006 | print("checking equality with discrete values") | ||
| 3007 | end | ||
| 3008 | if (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 | ||
| 3016 | end)() then | ||
| 3017 | print("checking if `a` is in a list") | ||
| 3018 | end | ||
| 3019 | if not (math.random() > 0.1) then | ||
| 3020 | print("You're lucky!") | ||
| 3021 | end | ||
| 3022 | local have_coins = false | ||
| 3023 | if have_coins then | ||
| 3024 | print("Got coins") | ||
| 3025 | else | ||
| 3026 | print("No coins") | ||
| 3027 | end | ||
| 3028 | local have_coins = false | ||
| 3029 | if have_coins then | ||
| 3030 | print("Got coins") | ||
| 3031 | else | ||
| 3032 | print("No coins") | ||
| 3033 | end | ||
| 3034 | local have_coins = false | ||
| 3035 | print((function() | ||
| 3036 | if have_coins then | ||
| 3037 | return "Got coins" | ||
| 3038 | else | ||
| 3039 | return "No coins" | ||
| 3040 | end | ||
| 3041 | end)()) | ||
| 3042 | local is_tall | ||
| 3043 | is_tall = function(name) | ||
| 3044 | if name == "Rob" then | ||
| 3045 | return true | ||
| 3046 | else | ||
| 3047 | return false | ||
| 3048 | end | ||
| 3049 | end | ||
| 3050 | local message | ||
| 3051 | if is_tall("Rob") then | ||
| 3052 | message = "I am very tall" | ||
| 3053 | else | ||
| 3054 | message = "I am not so tall" | ||
| 3055 | end | ||
| 3056 | print(message) | ||
| 3057 | if not (os.date("%A") == "Monday") then | ||
| 3058 | print("it is not Monday!") | ||
| 3059 | end | ||
| 3060 | if not (math.random() > 0.1) then | ||
| 3061 | print("You're lucky!") | ||
| 3062 | end | ||
| 3063 | local a = 5 | ||
| 3064 | if (1 == a or 3 == a or 5 == a or 7 == a) then | ||
| 3065 | print("checking equality with discrete values") | ||
| 3066 | end | ||
| 3067 | if (function() | ||
| 3068 | local _check_0 = list | ||
| 3069 | for _index_0 = 1, #_check_0 do | ||
| 3070 | if _check_0[_index_0] == a then | ||
| 3071 | return true | ||
| 3072 | end | ||
| 3073 | end | ||
| 3074 | return false | ||
| 3075 | end)() then | ||
| 3076 | print("checking if `a` is in a list") | ||
| 3077 | end | ||
| 3078 | if not (math.random() > 0.1) then | ||
| 3079 | print("You're lucky!") | ||
| 3080 | end | ||
| 3081 | if name == "Rob" then | ||
| 3082 | print("hello world") | ||
| 3083 | end | ||
| 3084 | local _list_0 = items | ||
| 3085 | for _index_0 = 1, #_list_0 do | ||
| 3086 | local item = _list_0[_index_0] | ||
| 3087 | print("item: ", item) | ||
| 3088 | end | ||
| 3089 | while game:isRunning() do | ||
| 3090 | game:update() | ||
| 3091 | end | ||
| 3092 | while not reader:eof() do | ||
| 3093 | reader:parse_line() | ||
| 3094 | end | ||
| 3095 | if name == "Rob" then | ||
| 3096 | print("hello world") | ||
| 3097 | end | ||
| 3098 | local _list_0 = items | ||
| 3099 | for _index_0 = 1, #_list_0 do | ||
| 3100 | local item = _list_0[_index_0] | ||
| 3101 | print("item: ", item) | ||
| 3102 | end | ||
| 3103 | while game:isRunning() do | ||
| 3104 | game:update() | ||
| 3105 | end | ||
| 3106 | while not reader:eof() do | ||
| 3107 | reader:parse_line() | ||
| 3108 | end | ||
| 3109 | local name = "Dan" | ||
| 3110 | if "Robert" == name then | ||
| 3111 | print("You are Robert") | ||
| 3112 | elseif "Dan" == name or "Daniel" == name then | ||
| 3113 | print("Your name, it's Dan") | ||
| 3114 | else | ||
| 3115 | print("I don't know about you with name " .. tostring(name)) | ||
| 3116 | end | ||
| 3117 | local b = 1 | ||
| 3118 | local next_number | ||
| 3119 | if 1 == b then | ||
| 3120 | next_number = 2 | ||
| 3121 | elseif 2 == b then | ||
| 3122 | next_number = 3 | ||
| 3123 | else | ||
| 3124 | next_number = error("can't count that high!") | ||
| 3125 | end | ||
| 3126 | local msg | ||
| 3127 | local _exp_0 = math.random(1, 5) | ||
| 3128 | if 1 == _exp_0 then | ||
| 3129 | msg = "you are lucky" | ||
| 3130 | elseif 2 == _exp_0 then | ||
| 3131 | msg = "you are almost lucky" | ||
| 3132 | else | ||
| 3133 | msg = "not so lucky" | ||
| 3134 | end | ||
| 3135 | do | ||
| 3136 | local _exp_0 = math.random(1, 5) | ||
| 3137 | if 1 == _exp_0 then | ||
| 3138 | print("you are lucky") | ||
| 3139 | else | ||
| 3140 | print("not so lucky") | ||
| 3141 | end | ||
| 3142 | end | ||
| 3143 | local _exp_0 = math.random(1, 5) | ||
| 3144 | if 1 == _exp_0 then | ||
| 3145 | print("you are lucky") | ||
| 3146 | else | ||
| 3147 | print("not so lucky") | ||
| 3148 | end | ||
| 3149 | local items = { | ||
| 3150 | { | ||
| 3151 | x = 100, | ||
| 3152 | y = 200 | ||
| 3153 | }, | ||
| 3154 | { | ||
| 3155 | width = 300, | ||
| 3156 | height = 400 | ||
| 3157 | } | ||
| 3158 | } | ||
| 3159 | for _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("size " .. tostring(width) .. ", " .. tostring(height)) | ||
| 3178 | end | ||
| 3179 | end | ||
| 3180 | end | ||
| 3181 | end | ||
| 3182 | local item = { } | ||
| 3183 | local x, y = item.pos.x, item.pos.y | ||
| 3184 | if x == nil then | ||
| 3185 | x = 50 | ||
| 3186 | end | ||
| 3187 | if y == nil then | ||
| 3188 | y = 200 | ||
| 3189 | end | ||
| 3190 | local _type_0 = type(item) | ||
| 3191 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3192 | if _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)) | ||
| 3214 | end | ||
| 3215 | local _exp_0 = tb | ||
| 3216 | local _type_0 = type(_exp_0) | ||
| 3217 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3218 | local _match_0 = false | ||
| 3219 | if _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 | ||
| 3224 | end | ||
| 3225 | if 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 | ||
| 3245 | end | ||
| 3246 | local _exp_0 = tb | ||
| 3247 | local _type_0 = type(_exp_0) | ||
| 3248 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3249 | local _match_0 = false | ||
| 3250 | if _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("success", result) | ||
| 3255 | end | ||
| 3256 | end | ||
| 3257 | if 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("failed", result) | ||
| 3263 | end | ||
| 3264 | end | ||
| 3265 | if not _match_1 then | ||
| 3266 | print("invalid") | ||
| 3267 | end | ||
| 3268 | end | ||
| 3269 | local _exp_0 = tb | ||
| 3270 | local _type_0 = type(_exp_0) | ||
| 3271 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3272 | local _match_0 = false | ||
| 3273 | if _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("success", content) | ||
| 3292 | end | ||
| 3293 | end | ||
| 3294 | if 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("failed", content) | ||
| 3315 | end | ||
| 3316 | end | ||
| 3317 | if not _match_1 then | ||
| 3318 | print("invalid") | ||
| 3319 | end | ||
| 3320 | end | ||
| 3321 | local _exp_0 = tb | ||
| 3322 | local _type_0 = type(_exp_0) | ||
| 3323 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3324 | if _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("matched", fourth) | ||
| 3370 | end | ||
| 3371 | end | ||
| 3372 | local segments = { | ||
| 3373 | "admin", | ||
| 3374 | "users", | ||
| 3375 | "logs", | ||
| 3376 | "view" | ||
| 3377 | } | ||
| 3378 | local _type_0 = type(segments) | ||
| 3379 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3380 | if _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 | ||
| 3400 | end | ||
| 3401 | local name = "Dan" | ||
| 3402 | if "Robert" == name then | ||
| 3403 | print("You are Robert") | ||
| 3404 | elseif "Dan" == name or "Daniel" == name then | ||
| 3405 | print("Your name, it's Dan") | ||
| 3406 | else | ||
| 3407 | print("I don't know about you with name " .. tostring(name)) | ||
| 3408 | end | ||
| 3409 | local b = 1 | ||
| 3410 | local next_number | ||
| 3411 | if 1 == b then | ||
| 3412 | next_number = 2 | ||
| 3413 | elseif 2 == b then | ||
| 3414 | next_number = 3 | ||
| 3415 | else | ||
| 3416 | next_number = error("can't count that high!") | ||
| 3417 | end | ||
| 3418 | local msg | ||
| 3419 | local _exp_0 = math.random(1, 5) | ||
| 3420 | if 1 == _exp_0 then | ||
| 3421 | msg = "you are lucky" | ||
| 3422 | elseif 2 == _exp_0 then | ||
| 3423 | msg = "you are almost lucky" | ||
| 3424 | else | ||
| 3425 | msg = "not so lucky" | ||
| 3426 | end | ||
| 3427 | do | ||
| 3428 | local _exp_0 = math.random(1, 5) | ||
| 3429 | if 1 == _exp_0 then | ||
| 3430 | print("you are lucky") | ||
| 3431 | else | ||
| 3432 | print("not so lucky") | ||
| 3433 | end | ||
| 3434 | end | ||
| 3435 | local _exp_0 = math.random(1, 5) | ||
| 3436 | if 1 == _exp_0 then | ||
| 3437 | print("you are lucky") | ||
| 3438 | else | ||
| 3439 | print("not so lucky") | ||
| 3440 | end | ||
| 3441 | local items = { | ||
| 3442 | { | ||
| 3443 | x = 100, | ||
| 3444 | y = 200 | ||
| 3445 | }, | ||
| 3446 | { | ||
| 3447 | width = 300, | ||
| 3448 | height = 400 | ||
| 3449 | } | ||
| 3450 | } | ||
| 3451 | for _index_0 = 1, #items do | ||
| 3452 | local item = items[_index_0] | ||
| 3453 | local _type_0 = type(item) | ||
| 3454 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3455 | local _match_0 = false | ||
| 3456 | if _tab_0 then | ||
| 3457 | local x = item.x | ||
| 3458 | local y = item.y | ||
| 3459 | if x ~= nil and y ~= nil then | ||
| 3460 | _match_0 = true | ||
| 3461 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 3462 | end | ||
| 3463 | end | ||
| 3464 | if not _match_0 then | ||
| 3465 | if _tab_0 then | ||
| 3466 | local width = item.width | ||
| 3467 | local height = item.height | ||
| 3468 | if width ~= nil and height ~= nil then | ||
| 3469 | print("size " .. tostring(width) .. ", " .. tostring(height)) | ||
| 3470 | end | ||
| 3471 | end | ||
| 3472 | end | ||
| 3473 | end | ||
| 3474 | local item = { } | ||
| 3475 | local x, y = item.pos.x, item.pos.y | ||
| 3476 | if x == nil then | ||
| 3477 | x = 50 | ||
| 3478 | end | ||
| 3479 | if y == nil then | ||
| 3480 | y = 200 | ||
| 3481 | end | ||
| 3482 | local _type_0 = type(item) | ||
| 3483 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3484 | if _tab_0 then | ||
| 3485 | do | ||
| 3486 | local _obj_0 = item.pos | ||
| 3487 | local _type_1 = type(_obj_0) | ||
| 3488 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3489 | x = _obj_0.x | ||
| 3490 | end | ||
| 3491 | end | ||
| 3492 | do | ||
| 3493 | local _obj_0 = item.pos | ||
| 3494 | local _type_1 = type(_obj_0) | ||
| 3495 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3496 | y = _obj_0.y | ||
| 3497 | end | ||
| 3498 | end | ||
| 3499 | if x == nil then | ||
| 3500 | x = 50 | ||
| 3501 | end | ||
| 3502 | if y == nil then | ||
| 3503 | y = 200 | ||
| 3504 | end | ||
| 3505 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 3506 | end | ||
| 3507 | local _exp_0 = tb | ||
| 3508 | local _type_0 = type(_exp_0) | ||
| 3509 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3510 | local _match_0 = false | ||
| 3511 | if _tab_0 then | ||
| 3512 | if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then | ||
| 3513 | _match_0 = true | ||
| 3514 | print("1, 2, 3") | ||
| 3515 | end | ||
| 3516 | end | ||
| 3517 | if not _match_0 then | ||
| 3518 | local _match_1 = false | ||
| 3519 | if _tab_0 then | ||
| 3520 | local b = _exp_0[2] | ||
| 3521 | if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then | ||
| 3522 | _match_1 = true | ||
| 3523 | print("1, " .. tostring(b) .. ", 3") | ||
| 3524 | end | ||
| 3525 | end | ||
| 3526 | if not _match_1 then | ||
| 3527 | if _tab_0 then | ||
| 3528 | local b = _exp_0[3] | ||
| 3529 | if b == nil then | ||
| 3530 | b = 3 | ||
| 3531 | end | ||
| 3532 | if 1 == _exp_0[1] and 2 == _exp_0[2] then | ||
| 3533 | print("1, 2, " .. tostring(b)) | ||
| 3534 | end | ||
| 3535 | end | ||
| 3536 | end | ||
| 3537 | end | ||
| 3538 | local _exp_0 = tb | ||
| 3539 | local _type_0 = type(_exp_0) | ||
| 3540 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3541 | local _match_0 = false | ||
| 3542 | if _tab_0 then | ||
| 3543 | local result = _exp_0.result | ||
| 3544 | if true == _exp_0.success and result ~= nil then | ||
| 3545 | _match_0 = true | ||
| 3546 | print("success", result) | ||
| 3547 | end | ||
| 3548 | end | ||
| 3549 | if not _match_0 then | ||
| 3550 | local _match_1 = false | ||
| 3551 | if _tab_0 then | ||
| 3552 | if false == _exp_0.success then | ||
| 3553 | _match_1 = true | ||
| 3554 | print("failed", result) | ||
| 3555 | end | ||
| 3556 | end | ||
| 3557 | if not _match_1 then | ||
| 3558 | print("invalid") | ||
| 3559 | end | ||
| 3560 | end | ||
| 3561 | local _exp_0 = tb | ||
| 3562 | local _type_0 = type(_exp_0) | ||
| 3563 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3564 | local _match_0 = false | ||
| 3565 | if _tab_0 then | ||
| 3566 | local content | ||
| 3567 | do | ||
| 3568 | local _obj_0 = _exp_0.data | ||
| 3569 | local _type_1 = type(_obj_0) | ||
| 3570 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3571 | content = _obj_0.content | ||
| 3572 | end | ||
| 3573 | end | ||
| 3574 | local _val_0 | ||
| 3575 | do | ||
| 3576 | local _obj_0 = _exp_0.data | ||
| 3577 | if _obj_0 ~= nil then | ||
| 3578 | _val_0 = _obj_0.type | ||
| 3579 | end | ||
| 3580 | end | ||
| 3581 | if "success" == _val_0 and content ~= nil then | ||
| 3582 | _match_0 = true | ||
| 3583 | print("success", content) | ||
| 3584 | end | ||
| 3585 | end | ||
| 3586 | if not _match_0 then | ||
| 3587 | local _match_1 = false | ||
| 3588 | if _tab_0 then | ||
| 3589 | local content | ||
| 3590 | do | ||
| 3591 | local _obj_0 = _exp_0.data | ||
| 3592 | local _type_1 = type(_obj_0) | ||
| 3593 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3594 | content = _obj_0.content | ||
| 3595 | end | ||
| 3596 | end | ||
| 3597 | local _val_0 | ||
| 3598 | do | ||
| 3599 | local _obj_0 = _exp_0.data | ||
| 3600 | if _obj_0 ~= nil then | ||
| 3601 | _val_0 = _obj_0.type | ||
| 3602 | end | ||
| 3603 | end | ||
| 3604 | if "error" == _val_0 and content ~= nil then | ||
| 3605 | _match_1 = true | ||
| 3606 | print("failed", content) | ||
| 3607 | end | ||
| 3608 | end | ||
| 3609 | if not _match_1 then | ||
| 3610 | print("invalid") | ||
| 3611 | end | ||
| 3612 | end | ||
| 3613 | local _exp_0 = tb | ||
| 3614 | local _type_0 = type(_exp_0) | ||
| 3615 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3616 | if _tab_0 then | ||
| 3617 | local fourth = _exp_0[4] | ||
| 3618 | local _val_0 | ||
| 3619 | do | ||
| 3620 | local _obj_0 = _exp_0[1] | ||
| 3621 | if _obj_0 ~= nil then | ||
| 3622 | _val_0 = _obj_0.a | ||
| 3623 | end | ||
| 3624 | end | ||
| 3625 | local _val_1 | ||
| 3626 | do | ||
| 3627 | local _obj_0 = _exp_0[1] | ||
| 3628 | if _obj_0 ~= nil then | ||
| 3629 | _val_1 = _obj_0.b | ||
| 3630 | end | ||
| 3631 | end | ||
| 3632 | local _val_2 | ||
| 3633 | do | ||
| 3634 | local _obj_0 = _exp_0[2] | ||
| 3635 | if _obj_0 ~= nil then | ||
| 3636 | _val_2 = _obj_0.a | ||
| 3637 | end | ||
| 3638 | end | ||
| 3639 | local _val_3 | ||
| 3640 | do | ||
| 3641 | local _obj_0 = _exp_0[2] | ||
| 3642 | if _obj_0 ~= nil then | ||
| 3643 | _val_3 = _obj_0.b | ||
| 3644 | end | ||
| 3645 | end | ||
| 3646 | local _val_4 | ||
| 3647 | do | ||
| 3648 | local _obj_0 = _exp_0[3] | ||
| 3649 | if _obj_0 ~= nil then | ||
| 3650 | _val_4 = _obj_0.a | ||
| 3651 | end | ||
| 3652 | end | ||
| 3653 | local _val_5 | ||
| 3654 | do | ||
| 3655 | local _obj_0 = _exp_0[3] | ||
| 3656 | if _obj_0 ~= nil then | ||
| 3657 | _val_5 = _obj_0.b | ||
| 3658 | end | ||
| 3659 | end | ||
| 3660 | 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 | ||
| 3661 | print("matched", fourth) | ||
| 3662 | end | ||
| 3663 | end | ||
| 3664 | local segments = { | ||
| 3665 | "admin", | ||
| 3666 | "users", | ||
| 3667 | "logs", | ||
| 3668 | "view" | ||
| 3669 | } | ||
| 3670 | local _type_0 = type(segments) | ||
| 3671 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3672 | if _tab_0 then | ||
| 3673 | local groups | ||
| 3674 | do | ||
| 3675 | local _accum_0 = { } | ||
| 3676 | local _len_0 = 1 | ||
| 3677 | local _max_0 = #segments + -3 + 1 | ||
| 3678 | for _index_0 = 1, _max_0 do | ||
| 3679 | local _item_0 = segments[_index_0] | ||
| 3680 | _accum_0[_len_0] = _item_0 | ||
| 3681 | _len_0 = _len_0 + 1 | ||
| 3682 | end | ||
| 3683 | groups = _accum_0 | ||
| 3684 | end | ||
| 3685 | local resource = segments[#segments - 1] | ||
| 3686 | local action = segments[#segments] | ||
| 3687 | if resource ~= nil and action ~= nil then | ||
| 3688 | print("Group:", groups) | ||
| 3689 | print("Resource:", resource) | ||
| 3690 | print("Action:", action) | ||
| 3691 | end | ||
| 3692 | end | ||
| 3693 | local Inventory | ||
| 3694 | local _class_0 | ||
| 3695 | local _base_0 = { | ||
| 3696 | add_item = function(self, name) | ||
| 3697 | if self.items[name] then | ||
| 3698 | local _obj_0 = self.items | ||
| 3699 | _obj_0[name] = _obj_0[name] + 1 | ||
| 3700 | else | ||
| 3701 | self.items[name] = 1 | ||
| 3702 | end | ||
| 3703 | end | ||
| 3704 | } | ||
| 3705 | if _base_0.__index == nil then | ||
| 3706 | _base_0.__index = _base_0 | ||
| 3707 | end | ||
| 3708 | _class_0 = setmetatable({ | ||
| 3709 | __init = function(self) | ||
| 3710 | self.items = { } | ||
| 3711 | end, | ||
| 3712 | __base = _base_0, | ||
| 3713 | __name = "Inventory" | ||
| 3714 | }, { | ||
| 3715 | __index = _base_0, | ||
| 3716 | __call = function(cls, ...) | ||
| 3717 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3718 | cls.__init(_self_0, ...) | ||
| 3719 | return _self_0 | ||
| 3720 | end | ||
| 3721 | }) | ||
| 3722 | _base_0.__class = _class_0 | ||
| 3723 | Inventory = _class_0 | ||
| 3724 | local inv = Inventory() | ||
| 3725 | inv:add_item("t-shirt") | ||
| 3726 | inv:add_item("pants") | ||
| 3727 | local Person | ||
| 3728 | do | ||
| 3729 | local _class_0 | ||
| 3730 | local _base_0 = { | ||
| 3731 | clothes = { }, | ||
| 3732 | give_item = function(self, name) | ||
| 3733 | return table.insert(self.clothes, name) | ||
| 3734 | end | ||
| 3735 | } | ||
| 3736 | if _base_0.__index == nil then | ||
| 3737 | _base_0.__index = _base_0 | ||
| 3738 | end | ||
| 3739 | _class_0 = setmetatable({ | ||
| 3740 | __init = function() end, | ||
| 3741 | __base = _base_0, | ||
| 3742 | __name = "Person" | ||
| 3743 | }, { | ||
| 3744 | __index = _base_0, | ||
| 3745 | __call = function(cls, ...) | ||
| 3746 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3747 | cls.__init(_self_0, ...) | ||
| 3748 | return _self_0 | ||
| 3749 | end | ||
| 3750 | }) | ||
| 3751 | _base_0.__class = _class_0 | ||
| 3752 | Person = _class_0 | ||
| 3753 | end | ||
| 3754 | local a = Person() | ||
| 3755 | local b = Person() | ||
| 3756 | a:give_item("pants") | ||
| 3757 | b:give_item("shirt") | ||
| 3758 | local _list_0 = a.clothes | ||
| 3759 | for _index_0 = 1, #_list_0 do | ||
| 3760 | local item = _list_0[_index_0] | ||
| 3761 | print(item) | ||
| 3762 | end | ||
| 3763 | local Person | ||
| 3764 | local _class_0 | ||
| 3765 | local _base_0 = { } | ||
| 3766 | if _base_0.__index == nil then | ||
| 3767 | _base_0.__index = _base_0 | ||
| 3768 | end | ||
| 3769 | _class_0 = setmetatable({ | ||
| 3770 | __init = function(self) | ||
| 3771 | self.clothes = { } | ||
| 3772 | end, | ||
| 3773 | __base = _base_0, | ||
| 3774 | __name = "Person" | ||
| 3775 | }, { | ||
| 3776 | __index = _base_0, | ||
| 3777 | __call = function(cls, ...) | ||
| 3778 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3779 | cls.__init(_self_0, ...) | ||
| 3780 | return _self_0 | ||
| 3781 | end | ||
| 3782 | }) | ||
| 3783 | _base_0.__class = _class_0 | ||
| 3784 | Person = _class_0 | ||
| 3785 | local BackPack | ||
| 3786 | local _class_0 | ||
| 3787 | local _parent_0 = Inventory | ||
| 3788 | local _base_0 = { | ||
| 3789 | size = 10, | ||
| 3790 | add_item = function(self, name) | ||
| 3791 | if #self.items > size then | ||
| 3792 | error("backpack is full") | ||
| 3793 | end | ||
| 3794 | return _class_0.__parent.__base.add_item(self, name) | ||
| 3795 | end | ||
| 3796 | } | ||
| 3797 | for _key_0, _val_0 in pairs(_parent_0.__base) do | ||
| 3798 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
| 3799 | _base_0[_key_0] = _val_0 | ||
| 3800 | end | ||
| 3801 | end | ||
| 3802 | if _base_0.__index == nil then | ||
| 3803 | _base_0.__index = _base_0 | ||
| 3804 | end | ||
| 3805 | setmetatable(_base_0, _parent_0.__base) | ||
| 3806 | _class_0 = setmetatable({ | ||
| 3807 | __init = function(self, ...) | ||
| 3808 | return _class_0.__parent.__init(self, ...) | ||
| 3809 | end, | ||
| 3810 | __base = _base_0, | ||
| 3811 | __name = "BackPack", | ||
| 3812 | __parent = _parent_0 | ||
| 3813 | }, { | ||
| 3814 | __index = function(cls, name) | ||
| 3815 | local val = rawget(_base_0, name) | ||
| 3816 | if val == nil then | ||
| 3817 | local parent = rawget(cls, "__parent") | ||
| 3818 | if parent then | ||
| 3819 | return parent[name] | ||
| 3820 | end | ||
| 3821 | else | ||
| 3822 | return val | ||
| 3823 | end | ||
| 3824 | end, | ||
| 3825 | __call = function(cls, ...) | ||
| 3826 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3827 | cls.__init(_self_0, ...) | ||
| 3828 | return _self_0 | ||
| 3829 | end | ||
| 3830 | }) | ||
| 3831 | _base_0.__class = _class_0 | ||
| 3832 | if _parent_0.__inherited then | ||
| 3833 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 3834 | end | ||
| 3835 | BackPack = _class_0 | ||
| 3836 | local Shelf | ||
| 3837 | do | ||
| 3838 | local _class_0 | ||
| 3839 | local _base_0 = { } | ||
| 3840 | if _base_0.__index == nil then | ||
| 3841 | _base_0.__index = _base_0 | ||
| 3842 | end | ||
| 3843 | _class_0 = setmetatable({ | ||
| 3844 | __init = function() end, | ||
| 3845 | __base = _base_0, | ||
| 3846 | __name = "Shelf" | ||
| 3847 | }, { | ||
| 3848 | __index = _base_0, | ||
| 3849 | __call = function(cls, ...) | ||
| 3850 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3851 | cls.__init(_self_0, ...) | ||
| 3852 | return _self_0 | ||
| 3853 | end | ||
| 3854 | }) | ||
| 3855 | _base_0.__class = _class_0 | ||
| 3856 | local self = _class_0; | ||
| 3857 | self.__inherited = function(self, child) | ||
| 3858 | return print(self.__name, "was inherited by", child.__name) | ||
| 3859 | end | ||
| 3860 | Shelf = _class_0 | ||
| 3861 | end | ||
| 3862 | local Cupboard | ||
| 3863 | local _class_0 | ||
| 3864 | local _parent_0 = Shelf | ||
| 3865 | local _base_0 = { } | ||
| 3866 | for _key_0, _val_0 in pairs(_parent_0.__base) do | ||
| 3867 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
| 3868 | _base_0[_key_0] = _val_0 | ||
| 3869 | end | ||
| 3870 | end | ||
| 3871 | if _base_0.__index == nil then | ||
| 3872 | _base_0.__index = _base_0 | ||
| 3873 | end | ||
| 3874 | setmetatable(_base_0, _parent_0.__base) | ||
| 3875 | _class_0 = setmetatable({ | ||
| 3876 | __init = function(self, ...) | ||
| 3877 | return _class_0.__parent.__init(self, ...) | ||
| 3878 | end, | ||
| 3879 | __base = _base_0, | ||
| 3880 | __name = "Cupboard", | ||
| 3881 | __parent = _parent_0 | ||
| 3882 | }, { | ||
| 3883 | __index = function(cls, name) | ||
| 3884 | local val = rawget(_base_0, name) | ||
| 3885 | if val == nil then | ||
| 3886 | local parent = rawget(cls, "__parent") | ||
| 3887 | if parent then | ||
| 3888 | return parent[name] | ||
| 3889 | end | ||
| 3890 | else | ||
| 3891 | return val | ||
| 3892 | end | ||
| 3893 | end, | ||
| 3894 | __call = function(cls, ...) | ||
| 3895 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3896 | cls.__init(_self_0, ...) | ||
| 3897 | return _self_0 | ||
| 3898 | end | ||
| 3899 | }) | ||
| 3900 | _base_0.__class = _class_0 | ||
| 3901 | if _parent_0.__inherited then | ||
| 3902 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 3903 | end | ||
| 3904 | Cupboard = _class_0 | ||
| 3905 | local MyClass | ||
| 3906 | local _class_0 | ||
| 3907 | local _parent_0 = ParentClass | ||
| 3908 | local _base_0 = { | ||
| 3909 | a_method = function(self) | ||
| 3910 | _class_0.__parent.__base.a_method(self, "hello", "world") | ||
| 3911 | _class_0.__parent.a_method(self, "hello", "world") | ||
| 3912 | _class_0.__parent.a_method(self, "hello", "world") | ||
| 3913 | return assert(_class_0.__parent == ParentClass) | ||
| 3914 | end | ||
| 3915 | } | ||
| 3916 | for _key_0, _val_0 in pairs(_parent_0.__base) do | ||
| 3917 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
| 3918 | _base_0[_key_0] = _val_0 | ||
| 3919 | end | ||
| 3920 | end | ||
| 3921 | if _base_0.__index == nil then | ||
| 3922 | _base_0.__index = _base_0 | ||
| 3923 | end | ||
| 3924 | setmetatable(_base_0, _parent_0.__base) | ||
| 3925 | _class_0 = setmetatable({ | ||
| 3926 | __init = function(self, ...) | ||
| 3927 | return _class_0.__parent.__init(self, ...) | ||
| 3928 | end, | ||
| 3929 | __base = _base_0, | ||
| 3930 | __name = "MyClass", | ||
| 3931 | __parent = _parent_0 | ||
| 3932 | }, { | ||
| 3933 | __index = function(cls, name) | ||
| 3934 | local val = rawget(_base_0, name) | ||
| 3935 | if val == nil then | ||
| 3936 | local parent = rawget(cls, "__parent") | ||
| 3937 | if parent then | ||
| 3938 | return parent[name] | ||
| 3939 | end | ||
| 3940 | else | ||
| 3941 | return val | ||
| 3942 | end | ||
| 3943 | end, | ||
| 3944 | __call = function(cls, ...) | ||
| 3945 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3946 | cls.__init(_self_0, ...) | ||
| 3947 | return _self_0 | ||
| 3948 | end | ||
| 3949 | }) | ||
| 3950 | _base_0.__class = _class_0 | ||
| 3951 | if _parent_0.__inherited then | ||
| 3952 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 3953 | end | ||
| 3954 | MyClass = _class_0 | ||
| 3955 | local b = BackPack() | ||
| 3956 | assert(b.__class == BackPack) | ||
| 3957 | print(BackPack.size) | ||
| 3958 | print(BackPack.__name) | ||
| 3959 | local Things | ||
| 3960 | do | ||
| 3961 | local _class_0 | ||
| 3962 | local _base_0 = { } | ||
| 3963 | if _base_0.__index == nil then | ||
| 3964 | _base_0.__index = _base_0 | ||
| 3965 | end | ||
| 3966 | _class_0 = setmetatable({ | ||
| 3967 | __init = function() end, | ||
| 3968 | __base = _base_0, | ||
| 3969 | __name = "Things" | ||
| 3970 | }, { | ||
| 3971 | __index = _base_0, | ||
| 3972 | __call = function(cls, ...) | ||
| 3973 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3974 | cls.__init(_self_0, ...) | ||
| 3975 | return _self_0 | ||
| 3976 | end | ||
| 3977 | }) | ||
| 3978 | _base_0.__class = _class_0 | ||
| 3979 | local self = _class_0; | ||
| 3980 | self.some_func = function(self) | ||
| 3981 | return print("Hello from", self.__name) | ||
| 3982 | end | ||
| 3983 | Things = _class_0 | ||
| 3984 | end | ||
| 3985 | Things:some_func() | ||
| 3986 | assert(Things().some_func == nil) | ||
| 3987 | local Counter | ||
| 3988 | do | ||
| 3989 | local _class_0 | ||
| 3990 | local _base_0 = { } | ||
| 3991 | if _base_0.__index == nil then | ||
| 3992 | _base_0.__index = _base_0 | ||
| 3993 | end | ||
| 3994 | _class_0 = setmetatable({ | ||
| 3995 | __init = function(self) | ||
| 3996 | self.__class.count = self.__class.count + 1 | ||
| 3997 | end, | ||
| 3998 | __base = _base_0, | ||
| 3999 | __name = "Counter" | ||
| 4000 | }, { | ||
| 4001 | __index = _base_0, | ||
| 4002 | __call = function(cls, ...) | ||
| 4003 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4004 | cls.__init(_self_0, ...) | ||
| 4005 | return _self_0 | ||
| 4006 | end | ||
| 4007 | }) | ||
| 4008 | _base_0.__class = _class_0 | ||
| 4009 | local self = _class_0; | ||
| 4010 | self.count = 0 | ||
| 4011 | Counter = _class_0 | ||
| 4012 | end | ||
| 4013 | Counter() | ||
| 4014 | Counter() | ||
| 4015 | print(Counter.count) | ||
| 4016 | self.__class:hello(1, 2, 3, 4) | ||
| 4017 | local Things | ||
| 4018 | local _class_0 | ||
| 4019 | local _base_0 = { } | ||
| 4020 | if _base_0.__index == nil then | ||
| 4021 | _base_0.__index = _base_0 | ||
| 4022 | end | ||
| 4023 | _class_0 = setmetatable({ | ||
| 4024 | __init = function() end, | ||
| 4025 | __base = _base_0, | ||
| 4026 | __name = "Things" | ||
| 4027 | }, { | ||
| 4028 | __index = _base_0, | ||
| 4029 | __call = function(cls, ...) | ||
| 4030 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4031 | cls.__init(_self_0, ...) | ||
| 4032 | return _self_0 | ||
| 4033 | end | ||
| 4034 | }) | ||
| 4035 | _base_0.__class = _class_0 | ||
| 4036 | local self = _class_0; | ||
| 4037 | self.class_var = "hello world" | ||
| 4038 | Things = _class_0 | ||
| 4039 | local MoreThings | ||
| 4040 | local _class_0 | ||
| 4041 | local secret, log | ||
| 4042 | local _base_0 = { | ||
| 4043 | some_method = function(self) | ||
| 4044 | return log("hello world: " .. secret) | ||
| 4045 | end | ||
| 4046 | } | ||
| 4047 | if _base_0.__index == nil then | ||
| 4048 | _base_0.__index = _base_0 | ||
| 4049 | end | ||
| 4050 | _class_0 = setmetatable({ | ||
| 4051 | __init = function() end, | ||
| 4052 | __base = _base_0, | ||
| 4053 | __name = "MoreThings" | ||
| 4054 | }, { | ||
| 4055 | __index = _base_0, | ||
| 4056 | __call = function(cls, ...) | ||
| 4057 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4058 | cls.__init(_self_0, ...) | ||
| 4059 | return _self_0 | ||
| 4060 | end | ||
| 4061 | }) | ||
| 4062 | _base_0.__class = _class_0 | ||
| 4063 | local self = _class_0; | ||
| 4064 | secret = 123 | ||
| 4065 | log = function(msg) | ||
| 4066 | return print("LOG:", msg) | ||
| 4067 | end | ||
| 4068 | MoreThings = _class_0 | ||
| 4069 | assert(self == self) | ||
| 4070 | assert(self.__class == self.__class) | ||
| 4071 | local some_instance_method | ||
| 4072 | some_instance_method = function(self, ...) | ||
| 4073 | return self.__class(...) | ||
| 4074 | end | ||
| 4075 | local Something | ||
| 4076 | do | ||
| 4077 | local _class_0 | ||
| 4078 | local _base_0 = { } | ||
| 4079 | if _base_0.__index == nil then | ||
| 4080 | _base_0.__index = _base_0 | ||
| 4081 | end | ||
| 4082 | _class_0 = setmetatable({ | ||
| 4083 | __init = function(self, foo, bar, biz, baz) | ||
| 4084 | self.foo = foo | ||
| 4085 | self.bar = bar | ||
| 4086 | self.__class.biz = biz | ||
| 4087 | self.__class.baz = baz | ||
| 4088 | end, | ||
| 4089 | __base = _base_0, | ||
| 4090 | __name = "Something" | ||
| 4091 | }, { | ||
| 4092 | __index = _base_0, | ||
| 4093 | __call = function(cls, ...) | ||
| 4094 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4095 | cls.__init(_self_0, ...) | ||
| 4096 | return _self_0 | ||
| 4097 | end | ||
| 4098 | }) | ||
| 4099 | _base_0.__class = _class_0 | ||
| 4100 | Something = _class_0 | ||
| 4101 | end | ||
| 4102 | local _class_0 | ||
| 4103 | local _base_0 = { } | ||
| 4104 | if _base_0.__index == nil then | ||
| 4105 | _base_0.__index = _base_0 | ||
| 4106 | end | ||
| 4107 | _class_0 = setmetatable({ | ||
| 4108 | __init = function(self, foo, bar, biz, baz) | ||
| 4109 | self.foo = foo | ||
| 4110 | self.bar = bar | ||
| 4111 | self.__class.biz = biz | ||
| 4112 | self.__class.baz = baz | ||
| 4113 | end, | ||
| 4114 | __base = _base_0, | ||
| 4115 | __name = "Something" | ||
| 4116 | }, { | ||
| 4117 | __index = _base_0, | ||
| 4118 | __call = function(cls, ...) | ||
| 4119 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4120 | cls.__init(_self_0, ...) | ||
| 4121 | return _self_0 | ||
| 4122 | end | ||
| 4123 | }) | ||
| 4124 | _base_0.__class = _class_0 | ||
| 4125 | Something = _class_0 | ||
| 4126 | local new | ||
| 4127 | new = function(self, fieldA, fieldB) | ||
| 4128 | self.fieldA = fieldA | ||
| 4129 | self.fieldB = fieldB | ||
| 4130 | return self | ||
| 4131 | end | ||
| 4132 | local obj = new({ }, 123, "abc") | ||
| 4133 | print(obj) | ||
| 4134 | local x | ||
| 4135 | local Bucket | ||
| 4136 | local _class_0 | ||
| 4137 | local _base_0 = { | ||
| 4138 | drops = 0, | ||
| 4139 | add_drop = function(self) | ||
| 4140 | self.drops = self.drops + 1 | ||
| 4141 | end | ||
| 4142 | } | ||
| 4143 | if _base_0.__index == nil then | ||
| 4144 | _base_0.__index = _base_0 | ||
| 4145 | end | ||
| 4146 | _class_0 = setmetatable({ | ||
| 4147 | __init = function() end, | ||
| 4148 | __base = _base_0, | ||
| 4149 | __name = "Bucket" | ||
| 4150 | }, { | ||
| 4151 | __index = _base_0, | ||
| 4152 | __call = function(cls, ...) | ||
| 4153 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4154 | cls.__init(_self_0, ...) | ||
| 4155 | return _self_0 | ||
| 4156 | end | ||
| 4157 | }) | ||
| 4158 | _base_0.__class = _class_0 | ||
| 4159 | Bucket = _class_0 | ||
| 4160 | x = _class_0 | ||
| 4161 | local BigBucket | ||
| 4162 | do | ||
| 4163 | local _class_0 | ||
| 4164 | local _parent_0 = Bucket | ||
| 4165 | local _base_0 = { | ||
| 4166 | add_drop = function(self) | ||
| 4167 | self.drops = self.drops + 10 | ||
| 4168 | end | ||
| 4169 | } | ||
| 4170 | for _key_0, _val_0 in pairs(_parent_0.__base) do | ||
| 4171 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
| 4172 | _base_0[_key_0] = _val_0 | ||
| 4173 | end | ||
| 4174 | end | ||
| 4175 | if _base_0.__index == nil then | ||
| 4176 | _base_0.__index = _base_0 | ||
| 4177 | end | ||
| 4178 | setmetatable(_base_0, _parent_0.__base) | ||
| 4179 | _class_0 = setmetatable({ | ||
| 4180 | __init = function(self, ...) | ||
| 4181 | return _class_0.__parent.__init(self, ...) | ||
| 4182 | end, | ||
| 4183 | __base = _base_0, | ||
| 4184 | __name = "BigBucket", | ||
| 4185 | __parent = _parent_0 | ||
| 4186 | }, { | ||
| 4187 | __index = function(cls, name) | ||
| 4188 | local val = rawget(_base_0, name) | ||
| 4189 | if val == nil then | ||
| 4190 | local parent = rawget(cls, "__parent") | ||
| 4191 | if parent then | ||
| 4192 | return parent[name] | ||
| 4193 | end | ||
| 4194 | else | ||
| 4195 | return val | ||
| 4196 | end | ||
| 4197 | end, | ||
| 4198 | __call = function(cls, ...) | ||
| 4199 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4200 | cls.__init(_self_0, ...) | ||
| 4201 | return _self_0 | ||
| 4202 | end | ||
| 4203 | }) | ||
| 4204 | _base_0.__class = _class_0 | ||
| 4205 | if _parent_0.__inherited then | ||
| 4206 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 4207 | end | ||
| 4208 | BigBucket = _class_0 | ||
| 4209 | end | ||
| 4210 | assert(Bucket.__name == "BigBucket") | ||
| 4211 | local x | ||
| 4212 | local _class_0 | ||
| 4213 | local _base_0 = { } | ||
| 4214 | if _base_0.__index == nil then | ||
| 4215 | _base_0.__index = _base_0 | ||
| 4216 | end | ||
| 4217 | _class_0 = setmetatable({ | ||
| 4218 | __init = function() end, | ||
| 4219 | __base = _base_0, | ||
| 4220 | __name = "x" | ||
| 4221 | }, { | ||
| 4222 | __index = _base_0, | ||
| 4223 | __call = function(cls, ...) | ||
| 4224 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4225 | cls.__init(_self_0, ...) | ||
| 4226 | return _self_0 | ||
| 4227 | end | ||
| 4228 | }) | ||
| 4229 | _base_0.__class = _class_0 | ||
| 4230 | x = _class_0 | ||
| 4231 | local MyIndex = { | ||
| 4232 | __index = { | ||
| 4233 | var = 1 | ||
| 4234 | } | ||
| 4235 | } | ||
| 4236 | local X | ||
| 4237 | do | ||
| 4238 | local _class_0 | ||
| 4239 | local _base_0 = { | ||
| 4240 | func = function(self) | ||
| 4241 | return print(123) | ||
| 4242 | end | ||
| 4243 | } | ||
| 4244 | local _list_0 = { | ||
| 4245 | MyIndex | ||
| 4246 | } | ||
| 4247 | for _index_0 = 1, #_list_0 do | ||
| 4248 | local _item_0 = _list_0[_index_0] | ||
| 4249 | local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0 | ||
| 4250 | for _key_0, _val_0 in pairs(_mixin_0) do | ||
| 4251 | if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then | ||
| 4252 | _base_0[_key_0] = _val_0 | ||
| 4253 | end | ||
| 4254 | end | ||
| 4255 | end | ||
| 4256 | if _base_0.__index == nil then | ||
| 4257 | _base_0.__index = _base_0 | ||
| 4258 | end | ||
| 4259 | _class_0 = setmetatable({ | ||
| 4260 | __init = function() end, | ||
| 4261 | __base = _base_0, | ||
| 4262 | __name = "X" | ||
| 4263 | }, { | ||
| 4264 | __index = _base_0, | ||
| 4265 | __call = function(cls, ...) | ||
| 4266 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4267 | cls.__init(_self_0, ...) | ||
| 4268 | return _self_0 | ||
| 4269 | end | ||
| 4270 | }) | ||
| 4271 | _base_0.__class = _class_0 | ||
| 4272 | X = _class_0 | ||
| 4273 | end | ||
| 4274 | local x = X() | ||
| 4275 | print(x.var) | ||
| 4276 | local Y | ||
| 4277 | do | ||
| 4278 | local _class_0 | ||
| 4279 | local _base_0 = { } | ||
| 4280 | local _list_0 = { | ||
| 4281 | X | ||
| 4282 | } | ||
| 4283 | for _index_0 = 1, #_list_0 do | ||
| 4284 | local _item_0 = _list_0[_index_0] | ||
| 4285 | local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0 | ||
| 4286 | for _key_0, _val_0 in pairs(_mixin_0) do | ||
| 4287 | if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then | ||
| 4288 | _base_0[_key_0] = _val_0 | ||
| 4289 | end | ||
| 4290 | end | ||
| 4291 | end | ||
| 4292 | if _base_0.__index == nil then | ||
| 4293 | _base_0.__index = _base_0 | ||
| 4294 | end | ||
| 4295 | _class_0 = setmetatable({ | ||
| 4296 | __init = function() end, | ||
| 4297 | __base = _base_0, | ||
| 4298 | __name = "Y" | ||
| 4299 | }, { | ||
| 4300 | __index = _base_0, | ||
| 4301 | __call = function(cls, ...) | ||
| 4302 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4303 | cls.__init(_self_0, ...) | ||
| 4304 | return _self_0 | ||
| 4305 | end | ||
| 4306 | }) | ||
| 4307 | _base_0.__class = _class_0 | ||
| 4308 | Y = _class_0 | ||
| 4309 | end | ||
| 4310 | local y = Y() | ||
| 4311 | y:func() | ||
| 4312 | assert(y.__class.__parent ~= X) | ||
| 4313 | local Inventory | ||
| 4314 | local _class_0 | ||
| 4315 | local _base_0 = { | ||
| 4316 | add_item = function(self, name) | ||
| 4317 | if self.items[name] then | ||
| 4318 | local _obj_0 = self.items | ||
| 4319 | _obj_0[name] = _obj_0[name] + 1 | ||
| 4320 | else | ||
| 4321 | self.items[name] = 1 | ||
| 4322 | end | ||
| 4323 | end | ||
| 4324 | } | ||
| 4325 | if _base_0.__index == nil then | ||
| 4326 | _base_0.__index = _base_0 | ||
| 4327 | end | ||
| 4328 | _class_0 = setmetatable({ | ||
| 4329 | __init = function(self) | ||
| 4330 | self.items = { } | ||
| 4331 | end, | ||
| 4332 | __base = _base_0, | ||
| 4333 | __name = "Inventory" | ||
| 4334 | }, { | ||
| 4335 | __index = _base_0, | ||
| 4336 | __call = function(cls, ...) | ||
| 4337 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4338 | cls.__init(_self_0, ...) | ||
| 4339 | return _self_0 | ||
| 4340 | end | ||
| 4341 | }) | ||
| 4342 | _base_0.__class = _class_0 | ||
| 4343 | Inventory = _class_0 | ||
| 4344 | local inv = Inventory() | ||
| 4345 | inv:add_item("t-shirt") | ||
| 4346 | inv:add_item("pants") | ||
| 4347 | local Person | ||
| 4348 | do | ||
| 4349 | local _class_0 | ||
| 4350 | local _base_0 = { | ||
| 4351 | clothes = { }, | ||
| 4352 | give_item = function(self, name) | ||
| 4353 | return table.insert(self.clothes, name) | ||
| 4354 | end | ||
| 4355 | } | ||
| 4356 | if _base_0.__index == nil then | ||
| 4357 | _base_0.__index = _base_0 | ||
| 4358 | end | ||
| 4359 | _class_0 = setmetatable({ | ||
| 4360 | __init = function() end, | ||
| 4361 | __base = _base_0, | ||
| 4362 | __name = "Person" | ||
| 4363 | }, { | ||
| 4364 | __index = _base_0, | ||
| 4365 | __call = function(cls, ...) | ||
| 4366 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4367 | cls.__init(_self_0, ...) | ||
| 4368 | return _self_0 | ||
| 4369 | end | ||
| 4370 | }) | ||
| 4371 | _base_0.__class = _class_0 | ||
| 4372 | Person = _class_0 | ||
| 4373 | end | ||
| 4374 | local a = Person() | ||
| 4375 | local b = Person() | ||
| 4376 | a:give_item("pants") | ||
| 4377 | b:give_item("shirt") | ||
| 4378 | local _list_0 = a.clothes | ||
| 4379 | for _index_0 = 1, #_list_0 do | ||
| 4380 | local item = _list_0[_index_0] | ||
| 4381 | print(item) | ||
| 4382 | end | ||
| 4383 | local Person | ||
| 4384 | local _class_0 | ||
| 4385 | local _base_0 = { } | ||
| 4386 | if _base_0.__index == nil then | ||
| 4387 | _base_0.__index = _base_0 | ||
| 4388 | end | ||
| 4389 | _class_0 = setmetatable({ | ||
| 4390 | __init = function(self) | ||
| 4391 | self.clothes = { } | ||
| 4392 | end, | ||
| 4393 | __base = _base_0, | ||
| 4394 | __name = "Person" | ||
| 4395 | }, { | ||
| 4396 | __index = _base_0, | ||
| 4397 | __call = function(cls, ...) | ||
| 4398 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4399 | cls.__init(_self_0, ...) | ||
| 4400 | return _self_0 | ||
| 4401 | end | ||
| 4402 | }) | ||
| 4403 | _base_0.__class = _class_0 | ||
| 4404 | Person = _class_0 | ||
| 4405 | local BackPack | ||
| 4406 | local _class_0 | ||
| 4407 | local _parent_0 = Inventory | ||
| 4408 | local _base_0 = { | ||
| 4409 | size = 10, | ||
| 4410 | add_item = function(self, name) | ||
| 4411 | if #self.items > size then | ||
| 4412 | error("backpack is full") | ||
| 4413 | end | ||
| 4414 | return _class_0.__parent.__base.add_item(self, name) | ||
| 4415 | end | ||
| 4416 | } | ||
| 4417 | for _key_0, _val_0 in pairs(_parent_0.__base) do | ||
| 4418 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
| 4419 | _base_0[_key_0] = _val_0 | ||
| 4420 | end | ||
| 4421 | end | ||
| 4422 | if _base_0.__index == nil then | ||
| 4423 | _base_0.__index = _base_0 | ||
| 4424 | end | ||
| 4425 | setmetatable(_base_0, _parent_0.__base) | ||
| 4426 | _class_0 = setmetatable({ | ||
| 4427 | __init = function(self, ...) | ||
| 4428 | return _class_0.__parent.__init(self, ...) | ||
| 4429 | end, | ||
| 4430 | __base = _base_0, | ||
| 4431 | __name = "BackPack", | ||
| 4432 | __parent = _parent_0 | ||
| 4433 | }, { | ||
| 4434 | __index = function(cls, name) | ||
| 4435 | local val = rawget(_base_0, name) | ||
| 4436 | if val == nil then | ||
| 4437 | local parent = rawget(cls, "__parent") | ||
| 4438 | if parent then | ||
| 4439 | return parent[name] | ||
| 4440 | end | ||
| 4441 | else | ||
| 4442 | return val | ||
| 4443 | end | ||
| 4444 | end, | ||
| 4445 | __call = function(cls, ...) | ||
| 4446 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4447 | cls.__init(_self_0, ...) | ||
| 4448 | return _self_0 | ||
| 4449 | end | ||
| 4450 | }) | ||
| 4451 | _base_0.__class = _class_0 | ||
| 4452 | if _parent_0.__inherited then | ||
| 4453 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 4454 | end | ||
| 4455 | BackPack = _class_0 | ||
| 4456 | local Shelf | ||
| 4457 | do | ||
| 4458 | local _class_0 | ||
| 4459 | local _base_0 = { } | ||
| 4460 | if _base_0.__index == nil then | ||
| 4461 | _base_0.__index = _base_0 | ||
| 4462 | end | ||
| 4463 | _class_0 = setmetatable({ | ||
| 4464 | __init = function() end, | ||
| 4465 | __base = _base_0, | ||
| 4466 | __name = "Shelf" | ||
| 4467 | }, { | ||
| 4468 | __index = _base_0, | ||
| 4469 | __call = function(cls, ...) | ||
| 4470 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4471 | cls.__init(_self_0, ...) | ||
| 4472 | return _self_0 | ||
| 4473 | end | ||
| 4474 | }) | ||
| 4475 | _base_0.__class = _class_0 | ||
| 4476 | local self = _class_0; | ||
| 4477 | self.__inherited = function(self, child) | ||
| 4478 | return print(self.__name, "was inherited by", child.__name) | ||
| 4479 | end | ||
| 4480 | Shelf = _class_0 | ||
| 4481 | end | ||
| 4482 | local Cupboard | ||
| 4483 | local _class_0 | ||
| 4484 | local _parent_0 = Shelf | ||
| 4485 | local _base_0 = { } | ||
| 4486 | for _key_0, _val_0 in pairs(_parent_0.__base) do | ||
| 4487 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
| 4488 | _base_0[_key_0] = _val_0 | ||
| 4489 | end | ||
| 4490 | end | ||
| 4491 | if _base_0.__index == nil then | ||
| 4492 | _base_0.__index = _base_0 | ||
| 4493 | end | ||
| 4494 | setmetatable(_base_0, _parent_0.__base) | ||
| 4495 | _class_0 = setmetatable({ | ||
| 4496 | __init = function(self, ...) | ||
| 4497 | return _class_0.__parent.__init(self, ...) | ||
| 4498 | end, | ||
| 4499 | __base = _base_0, | ||
| 4500 | __name = "Cupboard", | ||
| 4501 | __parent = _parent_0 | ||
| 4502 | }, { | ||
| 4503 | __index = function(cls, name) | ||
| 4504 | local val = rawget(_base_0, name) | ||
| 4505 | if val == nil then | ||
| 4506 | local parent = rawget(cls, "__parent") | ||
| 4507 | if parent then | ||
| 4508 | return parent[name] | ||
| 4509 | end | ||
| 4510 | else | ||
| 4511 | return val | ||
| 4512 | end | ||
| 4513 | end, | ||
| 4514 | __call = function(cls, ...) | ||
| 4515 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4516 | cls.__init(_self_0, ...) | ||
| 4517 | return _self_0 | ||
| 4518 | end | ||
| 4519 | }) | ||
| 4520 | _base_0.__class = _class_0 | ||
| 4521 | if _parent_0.__inherited then | ||
| 4522 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 4523 | end | ||
| 4524 | Cupboard = _class_0 | ||
| 4525 | local MyClass | ||
| 4526 | local _class_0 | ||
| 4527 | local _parent_0 = ParentClass | ||
| 4528 | local _base_0 = { | ||
| 4529 | a_method = function(self) | ||
| 4530 | _class_0.__parent.__base.a_method(self, "hello", "world") | ||
| 4531 | _class_0.__parent.a_method(self, "hello", "world") | ||
| 4532 | _class_0.__parent.a_method(self, "hello", "world") | ||
| 4533 | return assert(_class_0.__parent == ParentClass) | ||
| 4534 | end | ||
| 4535 | } | ||
| 4536 | for _key_0, _val_0 in pairs(_parent_0.__base) do | ||
| 4537 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
| 4538 | _base_0[_key_0] = _val_0 | ||
| 4539 | end | ||
| 4540 | end | ||
| 4541 | if _base_0.__index == nil then | ||
| 4542 | _base_0.__index = _base_0 | ||
| 4543 | end | ||
| 4544 | setmetatable(_base_0, _parent_0.__base) | ||
| 4545 | _class_0 = setmetatable({ | ||
| 4546 | __init = function(self, ...) | ||
| 4547 | return _class_0.__parent.__init(self, ...) | ||
| 4548 | end, | ||
| 4549 | __base = _base_0, | ||
| 4550 | __name = "MyClass", | ||
| 4551 | __parent = _parent_0 | ||
| 4552 | }, { | ||
| 4553 | __index = function(cls, name) | ||
| 4554 | local val = rawget(_base_0, name) | ||
| 4555 | if val == nil then | ||
| 4556 | local parent = rawget(cls, "__parent") | ||
| 4557 | if parent then | ||
| 4558 | return parent[name] | ||
| 4559 | end | ||
| 4560 | else | ||
| 4561 | return val | ||
| 4562 | end | ||
| 4563 | end, | ||
| 4564 | __call = function(cls, ...) | ||
| 4565 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4566 | cls.__init(_self_0, ...) | ||
| 4567 | return _self_0 | ||
| 4568 | end | ||
| 4569 | }) | ||
| 4570 | _base_0.__class = _class_0 | ||
| 4571 | if _parent_0.__inherited then | ||
| 4572 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 4573 | end | ||
| 4574 | MyClass = _class_0 | ||
| 4575 | local b = BackPack() | ||
| 4576 | assert(b.__class == BackPack) | ||
| 4577 | print(BackPack.size) | ||
| 4578 | print(BackPack.__name) | ||
| 4579 | local Things | ||
| 4580 | do | ||
| 4581 | local _class_0 | ||
| 4582 | local _base_0 = { } | ||
| 4583 | if _base_0.__index == nil then | ||
| 4584 | _base_0.__index = _base_0 | ||
| 4585 | end | ||
| 4586 | _class_0 = setmetatable({ | ||
| 4587 | __init = function() end, | ||
| 4588 | __base = _base_0, | ||
| 4589 | __name = "Things" | ||
| 4590 | }, { | ||
| 4591 | __index = _base_0, | ||
| 4592 | __call = function(cls, ...) | ||
| 4593 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4594 | cls.__init(_self_0, ...) | ||
| 4595 | return _self_0 | ||
| 4596 | end | ||
| 4597 | }) | ||
| 4598 | _base_0.__class = _class_0 | ||
| 4599 | local self = _class_0; | ||
| 4600 | self.some_func = function(self) | ||
| 4601 | return print("Hello from", self.__name) | ||
| 4602 | end | ||
| 4603 | Things = _class_0 | ||
| 4604 | end | ||
| 4605 | Things:some_func() | ||
| 4606 | assert(Things().some_func == nil) | ||
| 4607 | local Counter | ||
| 4608 | do | ||
| 4609 | local _class_0 | ||
| 4610 | local _base_0 = { } | ||
| 4611 | if _base_0.__index == nil then | ||
| 4612 | _base_0.__index = _base_0 | ||
| 4613 | end | ||
| 4614 | _class_0 = setmetatable({ | ||
| 4615 | __init = function(self) | ||
| 4616 | self.__class.count = self.__class.count + 1 | ||
| 4617 | end, | ||
| 4618 | __base = _base_0, | ||
| 4619 | __name = "Counter" | ||
| 4620 | }, { | ||
| 4621 | __index = _base_0, | ||
| 4622 | __call = function(cls, ...) | ||
| 4623 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4624 | cls.__init(_self_0, ...) | ||
| 4625 | return _self_0 | ||
| 4626 | end | ||
| 4627 | }) | ||
| 4628 | _base_0.__class = _class_0 | ||
| 4629 | local self = _class_0; | ||
| 4630 | self.count = 0 | ||
| 4631 | Counter = _class_0 | ||
| 4632 | end | ||
| 4633 | Counter() | ||
| 4634 | Counter() | ||
| 4635 | print(Counter.count) | ||
| 4636 | self.__class:hello(1, 2, 3, 4) | ||
| 4637 | local Things | ||
| 4638 | local _class_0 | ||
| 4639 | local _base_0 = { } | ||
| 4640 | if _base_0.__index == nil then | ||
| 4641 | _base_0.__index = _base_0 | ||
| 4642 | end | ||
| 4643 | _class_0 = setmetatable({ | ||
| 4644 | __init = function() end, | ||
| 4645 | __base = _base_0, | ||
| 4646 | __name = "Things" | ||
| 4647 | }, { | ||
| 4648 | __index = _base_0, | ||
| 4649 | __call = function(cls, ...) | ||
| 4650 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4651 | cls.__init(_self_0, ...) | ||
| 4652 | return _self_0 | ||
| 4653 | end | ||
| 4654 | }) | ||
| 4655 | _base_0.__class = _class_0 | ||
| 4656 | local self = _class_0; | ||
| 4657 | self.class_var = "hello world" | ||
| 4658 | Things = _class_0 | ||
| 4659 | local MoreThings | ||
| 4660 | local _class_0 | ||
| 4661 | local secret, log | ||
| 4662 | local _base_0 = { | ||
| 4663 | some_method = function(self) | ||
| 4664 | return log("hello world: " .. secret) | ||
| 4665 | end | ||
| 4666 | } | ||
| 4667 | if _base_0.__index == nil then | ||
| 4668 | _base_0.__index = _base_0 | ||
| 4669 | end | ||
| 4670 | _class_0 = setmetatable({ | ||
| 4671 | __init = function() end, | ||
| 4672 | __base = _base_0, | ||
| 4673 | __name = "MoreThings" | ||
| 4674 | }, { | ||
| 4675 | __index = _base_0, | ||
| 4676 | __call = function(cls, ...) | ||
| 4677 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4678 | cls.__init(_self_0, ...) | ||
| 4679 | return _self_0 | ||
| 4680 | end | ||
| 4681 | }) | ||
| 4682 | _base_0.__class = _class_0 | ||
| 4683 | local self = _class_0; | ||
| 4684 | secret = 123 | ||
| 4685 | log = function(msg) | ||
| 4686 | return print("LOG:", msg) | ||
| 4687 | end | ||
| 4688 | MoreThings = _class_0 | ||
| 4689 | assert(self == self) | ||
| 4690 | assert(self.__class == self.__class) | ||
| 4691 | local some_instance_method | ||
| 4692 | some_instance_method = function(self, ...) | ||
| 4693 | return self.__class(...) | ||
| 4694 | end | ||
| 4695 | local Something | ||
| 4696 | do | ||
| 4697 | local _class_0 | ||
| 4698 | local _base_0 = { } | ||
| 4699 | if _base_0.__index == nil then | ||
| 4700 | _base_0.__index = _base_0 | ||
| 4701 | end | ||
| 4702 | _class_0 = setmetatable({ | ||
| 4703 | __init = function(self, foo, bar, biz, baz) | ||
| 4704 | self.foo = foo | ||
| 4705 | self.bar = bar | ||
| 4706 | self.__class.biz = biz | ||
| 4707 | self.__class.baz = baz | ||
| 4708 | end, | ||
| 4709 | __base = _base_0, | ||
| 4710 | __name = "Something" | ||
| 4711 | }, { | ||
| 4712 | __index = _base_0, | ||
| 4713 | __call = function(cls, ...) | ||
| 4714 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4715 | cls.__init(_self_0, ...) | ||
| 4716 | return _self_0 | ||
| 4717 | end | ||
| 4718 | }) | ||
| 4719 | _base_0.__class = _class_0 | ||
| 4720 | Something = _class_0 | ||
| 4721 | end | ||
| 4722 | local _class_0 | ||
| 4723 | local _base_0 = { } | ||
| 4724 | if _base_0.__index == nil then | ||
| 4725 | _base_0.__index = _base_0 | ||
| 4726 | end | ||
| 4727 | _class_0 = setmetatable({ | ||
| 4728 | __init = function(self, foo, bar, biz, baz) | ||
| 4729 | self.foo = foo | ||
| 4730 | self.bar = bar | ||
| 4731 | self.__class.biz = biz | ||
| 4732 | self.__class.baz = baz | ||
| 4733 | end, | ||
| 4734 | __base = _base_0, | ||
| 4735 | __name = "Something" | ||
| 4736 | }, { | ||
| 4737 | __index = _base_0, | ||
| 4738 | __call = function(cls, ...) | ||
| 4739 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4740 | cls.__init(_self_0, ...) | ||
| 4741 | return _self_0 | ||
| 4742 | end | ||
| 4743 | }) | ||
| 4744 | _base_0.__class = _class_0 | ||
| 4745 | Something = _class_0 | ||
| 4746 | local new | ||
| 4747 | new = function(self, fieldA, fieldB) | ||
| 4748 | self.fieldA = fieldA | ||
| 4749 | self.fieldB = fieldB | ||
| 4750 | return self | ||
| 4751 | end | ||
| 4752 | local obj = new({ }, 123, "abc") | ||
| 4753 | print(obj) | ||
| 4754 | local x | ||
| 4755 | local Bucket | ||
| 4756 | local _class_0 | ||
| 4757 | local _base_0 = { | ||
| 4758 | drops = 0, | ||
| 4759 | add_drop = function(self) | ||
| 4760 | self.drops = self.drops + 1 | ||
| 4761 | end | ||
| 4762 | } | ||
| 4763 | if _base_0.__index == nil then | ||
| 4764 | _base_0.__index = _base_0 | ||
| 4765 | end | ||
| 4766 | _class_0 = setmetatable({ | ||
| 4767 | __init = function() end, | ||
| 4768 | __base = _base_0, | ||
| 4769 | __name = "Bucket" | ||
| 4770 | }, { | ||
| 4771 | __index = _base_0, | ||
| 4772 | __call = function(cls, ...) | ||
| 4773 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4774 | cls.__init(_self_0, ...) | ||
| 4775 | return _self_0 | ||
| 4776 | end | ||
| 4777 | }) | ||
| 4778 | _base_0.__class = _class_0 | ||
| 4779 | Bucket = _class_0 | ||
| 4780 | x = _class_0 | ||
| 4781 | local BigBucket | ||
| 4782 | do | ||
| 4783 | local _class_0 | ||
| 4784 | local _parent_0 = Bucket | ||
| 4785 | local _base_0 = { | ||
| 4786 | add_drop = function(self) | ||
| 4787 | self.drops = self.drops + 10 | ||
| 4788 | end | ||
| 4789 | } | ||
| 4790 | for _key_0, _val_0 in pairs(_parent_0.__base) do | ||
| 4791 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
| 4792 | _base_0[_key_0] = _val_0 | ||
| 4793 | end | ||
| 4794 | end | ||
| 4795 | if _base_0.__index == nil then | ||
| 4796 | _base_0.__index = _base_0 | ||
| 4797 | end | ||
| 4798 | setmetatable(_base_0, _parent_0.__base) | ||
| 4799 | _class_0 = setmetatable({ | ||
| 4800 | __init = function(self, ...) | ||
| 4801 | return _class_0.__parent.__init(self, ...) | ||
| 4802 | end, | ||
| 4803 | __base = _base_0, | ||
| 4804 | __name = "BigBucket", | ||
| 4805 | __parent = _parent_0 | ||
| 4806 | }, { | ||
| 4807 | __index = function(cls, name) | ||
| 4808 | local val = rawget(_base_0, name) | ||
| 4809 | if val == nil then | ||
| 4810 | local parent = rawget(cls, "__parent") | ||
| 4811 | if parent then | ||
| 4812 | return parent[name] | ||
| 4813 | end | ||
| 4814 | else | ||
| 4815 | return val | ||
| 4816 | end | ||
| 4817 | end, | ||
| 4818 | __call = function(cls, ...) | ||
| 4819 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4820 | cls.__init(_self_0, ...) | ||
| 4821 | return _self_0 | ||
| 4822 | end | ||
| 4823 | }) | ||
| 4824 | _base_0.__class = _class_0 | ||
| 4825 | if _parent_0.__inherited then | ||
| 4826 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 4827 | end | ||
| 4828 | BigBucket = _class_0 | ||
| 4829 | end | ||
| 4830 | assert(Bucket.__name == "BigBucket") | ||
| 4831 | local x | ||
| 4832 | local _class_0 | ||
| 4833 | local _base_0 = { } | ||
| 4834 | if _base_0.__index == nil then | ||
| 4835 | _base_0.__index = _base_0 | ||
| 4836 | end | ||
| 4837 | _class_0 = setmetatable({ | ||
| 4838 | __init = function() end, | ||
| 4839 | __base = _base_0, | ||
| 4840 | __name = "x" | ||
| 4841 | }, { | ||
| 4842 | __index = _base_0, | ||
| 4843 | __call = function(cls, ...) | ||
| 4844 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4845 | cls.__init(_self_0, ...) | ||
| 4846 | return _self_0 | ||
| 4847 | end | ||
| 4848 | }) | ||
| 4849 | _base_0.__class = _class_0 | ||
| 4850 | x = _class_0 | ||
| 4851 | local MyIndex = { | ||
| 4852 | __index = { | ||
| 4853 | var = 1 | ||
| 4854 | } | ||
| 4855 | } | ||
| 4856 | local X | ||
| 4857 | do | ||
| 4858 | local _class_0 | ||
| 4859 | local _base_0 = { | ||
| 4860 | func = function(self) | ||
| 4861 | return print(123) | ||
| 4862 | end | ||
| 4863 | } | ||
| 4864 | local _list_0 = { | ||
| 4865 | MyIndex | ||
| 4866 | } | ||
| 4867 | for _index_0 = 1, #_list_0 do | ||
| 4868 | local _item_0 = _list_0[_index_0] | ||
| 4869 | local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0 | ||
| 4870 | for _key_0, _val_0 in pairs(_mixin_0) do | ||
| 4871 | if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then | ||
| 4872 | _base_0[_key_0] = _val_0 | ||
| 4873 | end | ||
| 4874 | end | ||
| 4875 | end | ||
| 4876 | if _base_0.__index == nil then | ||
| 4877 | _base_0.__index = _base_0 | ||
| 4878 | end | ||
| 4879 | _class_0 = setmetatable({ | ||
| 4880 | __init = function() end, | ||
| 4881 | __base = _base_0, | ||
| 4882 | __name = "X" | ||
| 4883 | }, { | ||
| 4884 | __index = _base_0, | ||
| 4885 | __call = function(cls, ...) | ||
| 4886 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4887 | cls.__init(_self_0, ...) | ||
| 4888 | return _self_0 | ||
| 4889 | end | ||
| 4890 | }) | ||
| 4891 | _base_0.__class = _class_0 | ||
| 4892 | X = _class_0 | ||
| 4893 | end | ||
| 4894 | local x = X() | ||
| 4895 | print(x.var) | ||
| 4896 | local Y | ||
| 4897 | do | ||
| 4898 | local _class_0 | ||
| 4899 | local _base_0 = { } | ||
| 4900 | local _list_0 = { | ||
| 4901 | X | ||
| 4902 | } | ||
| 4903 | for _index_0 = 1, #_list_0 do | ||
| 4904 | local _item_0 = _list_0[_index_0] | ||
| 4905 | local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0 | ||
| 4906 | for _key_0, _val_0 in pairs(_mixin_0) do | ||
| 4907 | if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then | ||
| 4908 | _base_0[_key_0] = _val_0 | ||
| 4909 | end | ||
| 4910 | end | ||
| 4911 | end | ||
| 4912 | if _base_0.__index == nil then | ||
| 4913 | _base_0.__index = _base_0 | ||
| 4914 | end | ||
| 4915 | _class_0 = setmetatable({ | ||
| 4916 | __init = function() end, | ||
| 4917 | __base = _base_0, | ||
| 4918 | __name = "Y" | ||
| 4919 | }, { | ||
| 4920 | __index = _base_0, | ||
| 4921 | __call = function(cls, ...) | ||
| 4922 | local _self_0 = setmetatable({ }, _base_0) | ||
| 4923 | cls.__init(_self_0, ...) | ||
| 4924 | return _self_0 | ||
| 4925 | end | ||
| 4926 | }) | ||
| 4927 | _base_0.__class = _class_0 | ||
| 4928 | Y = _class_0 | ||
| 4929 | end | ||
| 4930 | local y = Y() | ||
| 4931 | y:func() | ||
| 4932 | assert(y.__class.__parent ~= X) | ||
| 4933 | local _with_0 = Person() | ||
| 4934 | _with_0.name = "Oswald" | ||
| 4935 | _with_0:add_relative(my_dad) | ||
| 4936 | _with_0:save() | ||
| 4937 | print(_with_0.name) | ||
| 4938 | local file | ||
| 4939 | local _with_0 = File("favorite_foods.txt") | ||
| 4940 | _with_0:set_encoding("utf8") | ||
| 4941 | file = _with_0 | ||
| 4942 | local create_person | ||
| 4943 | create_person = function(name, relatives) | ||
| 4944 | local _with_0 = Person() | ||
| 4945 | _with_0.name = name | ||
| 4946 | for _index_0 = 1, #relatives do | ||
| 4947 | local relative = relatives[_index_0] | ||
| 4948 | _with_0:add_relative(relative) | ||
| 4949 | end | ||
| 4950 | return _with_0 | ||
| 4951 | end | ||
| 4952 | local me = create_person("Leaf", { | ||
| 4953 | dad, | ||
| 4954 | mother, | ||
| 4955 | sister | ||
| 4956 | }) | ||
| 4957 | local str = "Hello" | ||
| 4958 | print("original:", str) | ||
| 4959 | print("upper:", str:upper()) | ||
| 4960 | local _with_0 = tb | ||
| 4961 | _with_0[1] = 1 | ||
| 4962 | print(_with_0[2]) | ||
| 4963 | do | ||
| 4964 | local _with_1 = _with_0[abc] | ||
| 4965 | _with_1[3] = _with_1[2]:func() | ||
| 4966 | _with_1["key-name"] = value | ||
| 4967 | end | ||
| 4968 | _with_0[#_with_0 + 1] = "abc" | ||
| 4969 | local _with_0 = obj | ||
| 4970 | if _with_0 ~= nil then | ||
| 4971 | print(obj.name) | ||
| 4972 | end | ||
| 4973 | local _with_0 = Person() | ||
| 4974 | _with_0.name = "Oswald" | ||
| 4975 | _with_0:add_relative(my_dad) | ||
| 4976 | _with_0:save() | ||
| 4977 | print(_with_0.name) | ||
| 4978 | local file | ||
| 4979 | local _with_0 = File("favorite_foods.txt") | ||
| 4980 | _with_0:set_encoding("utf8") | ||
| 4981 | file = _with_0 | ||
| 4982 | local create_person | ||
| 4983 | create_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 | ||
| 4991 | end | ||
| 4992 | local me = create_person("Leaf", { | ||
| 4993 | dad, | ||
| 4994 | mother, | ||
| 4995 | sister | ||
| 4996 | }) | ||
| 4997 | local str = "Hello" | ||
| 4998 | print("original:", str) | ||
| 4999 | print("upper:", str:upper()) | ||
| 5000 | local _with_0 = tb | ||
| 5001 | _with_0[1] = 1 | ||
| 5002 | print(_with_0[2]) | ||
| 5003 | do | ||
| 5004 | local _with_1 = _with_0[abc] | ||
| 5005 | _with_1[3] = _with_1[2]:func() | ||
| 5006 | _with_1["key-name"] = value | ||
| 5007 | end | ||
| 5008 | _with_0[#_with_0 + 1] = "abc" | ||
| 5009 | local _with_0 = obj | ||
| 5010 | if _with_0 ~= nil then | ||
| 5011 | print(obj.name) | ||
| 5012 | end | ||
| 5013 | do | ||
| 5014 | local var = "hello" | ||
| 5015 | print(var) | ||
| 5016 | end | ||
| 5017 | print(var) | ||
| 5018 | local counter | ||
| 5019 | do | ||
| 5020 | local i = 0 | ||
| 5021 | counter = function() | ||
| 5022 | i = i + 1 | ||
| 5023 | return i | ||
| 5024 | end | ||
| 5025 | end | ||
| 5026 | print(counter()) | ||
| 5027 | print(counter()) | ||
| 5028 | local tbl = { | ||
| 5029 | key = (function() | ||
| 5030 | print("assigning key!") | ||
| 5031 | return 1234 | ||
| 5032 | end)() | ||
| 5033 | } | ||
| 5034 | do | ||
| 5035 | local var = "hello" | ||
| 5036 | print(var) | ||
| 5037 | end | ||
| 5038 | print(var) | ||
| 5039 | local counter | ||
| 5040 | do | ||
| 5041 | local i = 0 | ||
| 5042 | counter = function() | ||
| 5043 | i = i + 1 | ||
| 5044 | return i | ||
| 5045 | end | ||
| 5046 | end | ||
| 5047 | print(counter()) | ||
| 5048 | print(counter()) | ||
| 5049 | local tbl = { | ||
| 5050 | key = (function() | ||
| 5051 | print("assigning key!") | ||
| 5052 | return 1234 | ||
| 5053 | end)() | ||
| 5054 | } | ||
| 5055 | local my_object = { | ||
| 5056 | value = 1000, | ||
| 5057 | write = function(self) | ||
| 5058 | return print("the value:", self.value) | ||
| 5059 | end | ||
| 5060 | } | ||
| 5061 | local run_callback | ||
| 5062 | run_callback = function(func) | ||
| 5063 | print("running callback...") | ||
| 5064 | return func() | ||
| 5065 | end | ||
| 5066 | run_callback(my_object.write) | ||
| 5067 | run_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 | ||
| 5073 | end)()) | ||
| 5074 | local my_object = { | ||
| 5075 | value = 1000, | ||
| 5076 | write = function(self) | ||
| 5077 | return print("the value:", self.value) | ||
| 5078 | end | ||
| 5079 | } | ||
| 5080 | local run_callback | ||
| 5081 | run_callback = function(func) | ||
| 5082 | print("running callback...") | ||
| 5083 | return func() | ||
| 5084 | end | ||
| 5085 | run_callback(my_object.write) | ||
| 5086 | run_callback((function() | ||
| 5087 | local _base_0 = my_object | ||
| 5088 | local _fn_0 = _base_0.write | ||
| 5089 | return _fn_0 and function(...) | ||
| 5090 | return _fn_0(_base_0, ...) | ||
| 5091 | end | ||
| 5092 | end)()) | ||
| 5093 | local i = 100 | ||
| 5094 | local my_func | ||
| 5095 | my_func = function() | ||
| 5096 | i = 10 | ||
| 5097 | while i > 0 do | ||
| 5098 | print(i) | ||
| 5099 | i = i - 1 | ||
| 5100 | end | ||
| 5101 | end | ||
| 5102 | my_func() | ||
| 5103 | print(i) | ||
| 5104 | local i = 100 | ||
| 5105 | local my_func | ||
| 5106 | my_func = function() | ||
| 5107 | local i = "hello" | ||
| 5108 | end | ||
| 5109 | my_func() | ||
| 5110 | print(i) | ||
| 5111 | local tmp = 1213 | ||
| 5112 | local i, k = 100, 50 | ||
| 5113 | local my_func | ||
| 5114 | my_func = function(add) | ||
| 5115 | local tmp = tmp + add | ||
| 5116 | i = i + tmp | ||
| 5117 | k = k + tmp | ||
| 5118 | end | ||
| 5119 | my_func(22) | ||
| 5120 | print(i, k) | ||
| 5121 | local i = 100 | ||
| 5122 | local my_func | ||
| 5123 | my_func = function() | ||
| 5124 | i = 10 | ||
| 5125 | while i > 0 do | ||
| 5126 | print(i) | ||
| 5127 | i = i - 1 | ||
| 5128 | end | ||
| 5129 | end | ||
| 5130 | my_func() | ||
| 5131 | print(i) | ||
| 5132 | local i = 100 | ||
| 5133 | local my_func | ||
| 5134 | my_func = function() | ||
| 5135 | local i = "hello" | ||
| 5136 | end | ||
| 5137 | my_func() | ||
| 5138 | print(i) | ||
| 5139 | local tmp = 1213 | ||
| 5140 | local i, k = 100, 50 | ||
| 5141 | local my_func | ||
| 5142 | my_func = function(add) | ||
| 5143 | local tmp = tmp + add | ||
| 5144 | i = i + tmp | ||
| 5145 | k = k + tmp | ||
| 5146 | end | ||
| 5147 | my_func(22) | ||
| 5148 | print(i, k) | ||
