├── .gitmodules ├── .travis.yml ├── ChunkSpy ├── ChunkSpy51.lua ├── ChunkSpy52.lua └── ChunkSpy53.lua ├── ReadMe.md ├── bin ├── ChunkSpy-Test.bat ├── ChunkSpy51.bat ├── ChunkSpy52.bat ├── ChunkSpy53.bat ├── allopcodes-5.1.lua ├── allopcodes-5.2.lua ├── allopcodes-5.3.lua ├── bin2c.lua ├── fun_check_count.lua ├── ilua.bat ├── issue41_gen_large_table.lua ├── lasmc.bat ├── lasmd.bat └── test-long.bat ├── compare ├── compare.rb └── luadecguess.rb ├── luadec ├── Makefile ├── StringBuffer.c ├── StringBuffer.h ├── common.h ├── decompile.c ├── decompile.h ├── disassemble.c ├── disassemble.h ├── expression.c ├── expression.h ├── gen-allopcodes-h.cmd ├── gen-git-srcversion.cmd ├── gen-svn-srcversion.cmd ├── guess.c ├── lua-compat.h ├── luadec.c ├── luaopswap.c ├── luareplace.c ├── lundump-5.1.c ├── macro-array.c ├── macro-array.h ├── proto.c ├── proto.h ├── srcversion.h.template ├── statement.c ├── statement.h ├── structs.c └── structs.h ├── test-compiled └── lua-5.1 │ ├── JX3_BF_Base_BigFoot.lua │ ├── JX3_BF_ChannelsSimulator.lua │ ├── JX3_BF_InfoBox.lua │ ├── JX3_BF_QuestPlus.lua │ ├── JX3_BF_Quest_Data.lua │ ├── JX3_Xu_MacroFHX_Main.lua │ ├── defense_witches │ ├── c01_daisy01.lua │ ├── config.lua │ ├── cont.lua │ ├── cont_game.lua │ ├── crystal.lua │ ├── game.lua │ ├── help_reload.lua │ ├── invite.lua │ ├── kpi.lua │ ├── main.lua │ ├── modstatus.lua │ ├── modstatus1.lua │ ├── powerup.lua │ ├── stage.lua │ ├── status.lua │ ├── status4.lua │ └── title.lua │ ├── dialer_md5_encrypt_data.lua │ ├── gcode1_db_m.lua │ ├── gcode7_cave.lua │ ├── gcode9_WeightStation.lua │ ├── pangu_formula_action_formula_c.lua │ ├── pangu_formula_gossip_lingshou.lua │ ├── popup_hint.lua │ └── xunlei │ ├── Button.xml.lua │ ├── CheckBox.xml.lua │ ├── DownloaderAssistantWnd.xml.lua │ ├── DownloaderHelper.lua │ ├── DownloaderMainWnd.xml.lua │ ├── DownloaderMainWnd727.xml.lua │ ├── DownloaderMessageBox.xml.lua │ ├── ImageButton.xml.lua │ ├── Progress.xml.lua │ ├── Root.lua │ ├── TextLink.xml.lua │ ├── checkEnv.lua │ └── onload.lua ├── test ├── 20130707 │ ├── _logic_leaks.lua │ ├── _nestif.lua │ ├── _repeat_repeat.lua │ ├── _while.lua │ └── _while_if.lua ├── 0512 │ ├── if.lua │ ├── repeat-for.lua │ ├── repeat-repeat.lua │ ├── repeat-until.lua │ ├── repeat.lua │ ├── repeat4.lua │ ├── upvalue-list.lua │ ├── while-error.lua │ ├── while-error2.lua │ ├── while.lua │ ├── while1-while1-error.lua │ ├── while1-while1.lua │ ├── while2-error.lua │ ├── while2.lua │ ├── while3.lua │ ├── while4.lua │ ├── while5.lua │ └── while6.lua ├── error_nested_if │ ├── doreturnend.lua │ ├── doreturnend2.lua │ ├── doreturnend3.lua │ ├── if1.lua │ ├── if2.lua │ └── logic │ │ ├── if.lua │ │ ├── if2.lua │ │ ├── if_all.lua │ │ ├── if_error.lua │ │ └── logic.lua ├── issues │ ├── issue13_direct_call.lua │ ├── issue15_fn_upvalue.lua │ ├── issue17_self_call.lua │ ├── issue22_exp_settable.lua │ ├── issue23_cannot_jmp_out_else.lua │ ├── issue24_while_if.lua │ ├── issue27_and_or_or.lua │ ├── issue28_lt_le_const.lua │ ├── issue29_vararg.lua │ ├── issue30_local_reuse.lua │ ├── issue32_global_or_to_if.lua │ ├── issue33_if_if.lua │ ├── issue41_most_const_51.lua │ ├── issue42_function_local_scope.lua │ ├── issue42_local_scope.lua │ ├── issue43_local_func_as_upval.lua │ ├── issue4_jmp_loadbool.lua │ └── issue4_jmp_loadbool_all.lua ├── loop_structure │ ├── 4while1.lua │ ├── complex_while.lua │ ├── complex_while2.lua │ ├── for.lua │ ├── repeat-for.lua │ ├── repeat-while.lua │ ├── repeat.lua │ ├── tfor.lua │ ├── until1.lua │ ├── while-while.lua │ ├── while.lua │ ├── while1-if.lua │ ├── while1-until.lua │ ├── while1-while1.lua │ └── while1.lua ├── lua-5.1-test │ ├── README │ ├── bisect.lua │ ├── cf.lua │ ├── echo.lua │ ├── env.lua │ ├── factorial.lua │ ├── fib.lua │ ├── fibfor.lua │ ├── globals.lua │ ├── hello.lua │ ├── life.lua │ ├── luac.lua │ ├── printf.lua │ ├── readonly.lua │ ├── sieve.lua │ ├── sort.lua │ ├── table.lua │ ├── trace-calls.lua │ ├── trace-globals.lua │ └── xd.lua ├── lua-5.1-tests │ ├── README │ ├── all.lua │ ├── api.lua │ ├── attrib.lua │ ├── big.lua │ ├── calls.lua │ ├── checktable.lua │ ├── closure.lua │ ├── code.lua │ ├── constructs.lua │ ├── db.lua │ ├── errors.lua │ ├── etc │ │ ├── ltests.c │ │ └── ltests.h │ ├── events.lua │ ├── files.lua │ ├── gc.lua │ ├── libs │ │ └── P1 │ │ │ └── .gitignore │ ├── literals.lua │ ├── locals.lua │ ├── main.lua │ ├── math.lua │ ├── nextvar.lua │ ├── pm.lua │ ├── sort.lua │ ├── strings.lua │ ├── vararg.lua │ └── verybig.lua ├── lua-5.2-tests │ ├── all.lua │ ├── api.lua │ ├── attrib.lua │ ├── big.lua │ ├── bitwise.lua │ ├── calls.lua │ ├── checktable.lua │ ├── closure.lua │ ├── code.lua │ ├── constructs.lua │ ├── coroutine.lua │ ├── db.lua │ ├── errors.lua │ ├── events.lua │ ├── files.lua │ ├── gc.lua │ ├── goto.lua │ ├── libs │ │ ├── P1 │ │ │ └── .gitignore │ │ ├── lib1.c │ │ ├── lib11.c │ │ ├── lib2.c │ │ ├── lib21.c │ │ └── makefile │ ├── literals.lua │ ├── locals.lua │ ├── ltests │ │ ├── ltests.c │ │ └── ltests.h │ ├── main.lua │ ├── math.lua │ ├── nextvar.lua │ ├── pm.lua │ ├── sort.lua │ ├── strings.lua │ ├── vararg.lua │ └── verybig.lua ├── lua-5.3-tests │ ├── all.lua │ ├── api.lua │ ├── attrib.lua │ ├── big.lua │ ├── bitwise.lua │ ├── calls.lua │ ├── closure.lua │ ├── code.lua │ ├── constructs.lua │ ├── coroutine.lua │ ├── db.lua │ ├── errors.lua │ ├── events.lua │ ├── files.lua │ ├── gc.lua │ ├── goto.lua │ ├── libs │ │ ├── P1 │ │ │ └── .gitignore │ │ ├── lib1.c │ │ ├── lib11.c │ │ ├── lib2.c │ │ ├── lib21.c │ │ └── makefile │ ├── literals.lua │ ├── locals.lua │ ├── ltests │ │ ├── ltests.c │ │ └── ltests.h │ ├── main.lua │ ├── math.lua │ ├── nextvar.lua │ ├── pm.lua │ ├── sort.lua │ ├── strings.lua │ ├── tpack.lua │ ├── utf8.lua │ ├── vararg.lua │ └── verybig.lua ├── ok_declare │ ├── a_er.lua │ ├── a_ok.lua │ └── a_ok2.lua ├── other │ ├── _60000funs_simple.lua │ ├── _simple_logic.lua │ ├── constructs.lua │ ├── fortest.lua │ ├── fun.lua │ ├── function_compare.lua │ ├── getmop.lua │ ├── if_else.lua │ ├── if_else_if.lua │ ├── if_not_else.lua │ ├── local_and_set.lua │ ├── logic.lua │ ├── producelua.lua │ ├── readchunk.lua │ ├── serialize.lua │ ├── table.lua │ ├── test.lua │ ├── testall.lua │ ├── testindex.lua │ ├── testup.lua │ ├── txt.lua │ └── vararg.lua ├── tested │ ├── assign.lua │ ├── assign2.lua │ ├── for.lua │ ├── for_if.lua │ ├── if_for.lua │ ├── index.lua │ ├── setlist.lua │ ├── setlist2.lua │ ├── table_constructor.lua │ ├── table_formated.lua │ ├── varg_call.lua │ └── varg_func.lua ├── todo │ ├── ch4.lua │ ├── f.lua │ ├── funret.lua │ ├── ifelse.lua │ ├── ifelseif2.lua │ ├── more.lua │ └── vararg.lua ├── unluac-test │ ├── adjust01.lua │ ├── adjust02.lua │ ├── adjust03.lua │ ├── adjust04.lua │ ├── adjust05.lua │ ├── assign.lua │ ├── booleanassign01.lua │ ├── booleanassign02.lua │ ├── booleanassign03.lua │ ├── booleanassign04.lua │ ├── booleanassign05.lua │ ├── booleanassign06.lua │ ├── booleanassign07.lua │ ├── booleanassign08.lua │ ├── booleanassign09.lua │ ├── booleanassign10.lua │ ├── booleanexpression01.lua │ ├── booleanexpression02.lua │ ├── booleanexpression03.lua │ ├── booleanexpression04.lua │ ├── booleanexpression05.lua │ ├── booleanmultiassign01.lua │ ├── booleanselfassign01.lua │ ├── closure.lua │ ├── combinebexpression01.lua │ ├── combinebexpression02.lua │ ├── combinebexpression03.lua │ ├── combinebexpression04.lua │ ├── compareassign01.lua │ ├── compareexpression.lua │ ├── compareorder01.lua │ ├── compareorder02.lua │ ├── compareorder03.lua │ ├── compareorder04.lua │ ├── compareorder05.lua │ ├── complexassign01.lua │ ├── complexassign02.lua │ ├── complexassign03.lua │ ├── condition.lua │ ├── control01.lua │ ├── control02.lua │ ├── control03.lua │ ├── control04.lua │ ├── control05.lua │ ├── control06.lua │ ├── control07.lua │ ├── declare.lua │ ├── declare02.lua │ ├── declare03.lua │ ├── doend01.lua │ ├── doend02.lua │ ├── doend03.lua │ ├── doend04.lua │ ├── doend05.lua │ ├── ellipsis.lua │ ├── expression.lua │ ├── final01.lua │ ├── final02.lua │ ├── functioncall.lua │ ├── ifthen.lua │ ├── ifthenelse.lua │ ├── literal.lua │ ├── literallist.lua │ ├── localbooleanassign.lua │ ├── localfunction01.lua │ ├── localfunction02.lua │ ├── localfunction03.lua │ ├── localfunction04.lua │ ├── method01.lua │ ├── multiassign.lua │ ├── multiliteraltarget.lua │ ├── nestedif.lua │ ├── nestedif02.lua │ ├── repeat.lua │ ├── table01.lua │ ├── table02.lua │ └── while.lua └── while │ ├── if_while_break.lua │ ├── until.lua │ ├── while-if.lua │ ├── while.lua │ ├── while1-if-else-break.lua │ ├── while1-if-else.lua │ ├── while1-if.lua │ ├── while1-while.lua │ └── while1.lua ├── vcproj-5.1 ├── lua.vcproj ├── lua51.sln ├── luac.vcproj ├── luadec.vcproj ├── luadll.vcproj ├── lualib.vcproj ├── luaopswap.vcproj └── luareplace.vcproj ├── vcproj-5.2 ├── lua.vcproj ├── lua52.sln ├── luac.vcproj ├── luadec.vcproj ├── luadll.vcproj ├── lualib.vcproj ├── luaopswap.vcproj └── luareplace.vcproj └── vcproj-5.3 ├── lua.vcproj ├── lua53.sln ├── luac.vcproj ├── luadec.vcproj ├── luadll.vcproj ├── lualib.vcproj ├── luaopswap.vcproj └── luareplace.vcproj /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "LuaAssemblyTools"] 2 | path = LuaAssemblyTools 3 | url = https://github.com/mlnlover11/LuaAssemblyTools 4 | [submodule "ilua"] 5 | path = ilua 6 | url = https://github.com/ilua/ilua 7 | [submodule "memwatch"] 8 | path = memwatch 9 | url = https://github.com/viruscamp/memwatch 10 | [submodule "lua-5.1"] 11 | path = lua-5.1 12 | url = https://github.com/viruscamp/lua5 13 | branch = 5.1 14 | [submodule "lua-5.2"] 15 | path = lua-5.2 16 | url = https://github.com/viruscamp/lua5 17 | branch = 5.2 18 | [submodule "lua-5.3"] 19 | path = lua-5.3 20 | url = https://github.com/viruscamp/lua5 21 | branch = 5.3 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | compiler: 4 | - clang 5 | - gcc 6 | 7 | env: 8 | - LUAVER=5.1 9 | - LUAVER=5.2 10 | - LUAVER=5.3 11 | 12 | before_script: 13 | - cd lua-$LUAVER/src && make linux CC=$CC && cd ../../luadec 14 | 15 | script: 16 | - make CC=$CC LUAVER=$LUAVER 17 | -------------------------------------------------------------------------------- /ReadMe.md: -------------------------------------------------------------------------------- 1 | Overview 2 | ======== 3 | 4 | LuaDec is a Lua decompiler for lua 5.1 , and experimental for lua 5.2 and 5.3. 5 | 6 | It is based on Hisham Muhammad's luadec which targeted lua 5.0.x and LuaDec51 by Zsolt Sz. Sztupak. 7 | 8 | LuaDec is free software and uses the same license as the original LuaDec. 9 | 10 | 11 | Compiling 12 | --------- 13 | ``` 14 | git clone https://github.com/viruscamp/luadec 15 | cd luadec 16 | git submodule update --init lua-5.1 17 | cd lua-5.1 18 | make linux 19 | cd ../luadec 20 | make LUAVER=5.1 21 | ``` 22 | 23 | If you want to build it for lua 5.2 or 5.3 , just replace 5.1 above to 5.2 or 5.3. 24 | 25 | There are also project files for vc2008, tested for vc2008 and vc2013. 26 | Before compiling, make sure there are correct sources in lua-5.1 , lua-5.2 or lua-5.3. 27 | 28 | 29 | Usage 30 | ----- 31 | * decompile lua binary file: 32 | luadec abc.luac 33 | * decompile lua source file for testing and comparing: 34 | luadec abc.lua 35 | * disassemble lua source or binary 36 | luadec -dis abc.lua 37 | * -pn print nested functions structure, could be used by -fn 38 | ``` 39 | luadec -pn test.lua 40 | 0 41 | 0_0 42 | 0_0_0 43 | 0_1 44 | ``` 45 | * -f decompile only specific nested function 46 | luadec -f 0_1 test.lua 47 | * -ns donot process sub functions 48 | luadec -ns -f 0_1 test.lua 49 | * -fc perform a instruction-by-instruction compare for each function 50 | luadec -fc test.lua 51 | outputs: 52 | -- function check pass 0 53 | -- function check fail 0_0 : cannot compile 54 | -- function check fail 0_1 : different code size; sizecode org: 66, decompiled: 67, same: 47; 55 | 56 | There are some more options, usually for debug purposes, or for cases where the built in local guesser guesses wrong. 57 | Use -h to get a complete list of usable parameters 58 | 59 | 60 | Credits 61 | ------- 62 | 63 | Original by Hisham Muhammad (http://luadec.luaforge.net) 64 | 65 | Ongoing port to Lua 5.1 by Zsolt Sz. Sztupak (https://github.com/sztupy/luadec51/) 66 | 67 | The internals of Lua5.1 was learned from Kein-Hong Man's A No-Frills Introduction to Lua 5.1 VM Instructions 68 | -------------------------------------------------------------------------------- /bin/ChunkSpy-Test.bat: -------------------------------------------------------------------------------- 1 | set lua=%1 2 | set chunkspy=%2 3 | 4 | %lua% ..\ChunkSpy\%chunkspy%.lua --help 5 | pause 6 | %lua% ..\ChunkSpy\%chunkspy%.lua --test 7 | pause 8 | %lua% ..\ChunkSpy\%chunkspy%.lua --sample 9 | pause 10 | %lua% ..\ChunkSpy\%chunkspy%.lua --interact 11 | pause 12 | 13 | %lua% ..\ChunkSpy\%chunkspy%.lua --brief allopcodes.lua 14 | pause 15 | %lua% ..\ChunkSpy\%chunkspy%.lua --brief allopcodes.51.luac 16 | pause 17 | %lua% ..\ChunkSpy\%chunkspy%.lua --brief allopcodes.52.luac 18 | pause 19 | 20 | %lua% ..\ChunkSpy\%chunkspy%.lua --stats allopcodes.lua 21 | pause 22 | %lua% ..\ChunkSpy\%chunkspy%.lua --stats allopcodes.51.luac 23 | pause 24 | %lua% ..\ChunkSpy\%chunkspy%.lua --stats allopcodes.52.luac 25 | pause 26 | 27 | %lua% ..\ChunkSpy\%chunkspy%.lua allopcodes.lua 28 | pause 29 | %lua% ..\ChunkSpy\%chunkspy%.lua allopcodes.51.luac 30 | pause 31 | %lua% ..\ChunkSpy\%chunkspy%.lua allopcodes.52.luac 32 | pause 33 | 34 | %lua% ..\ChunkSpy\%chunkspy%.lua --run allopcodes.lua 35 | pause 36 | %lua% ..\ChunkSpy\%chunkspy%.lua --run allopcodes.51.luac 37 | pause 38 | %lua% ..\ChunkSpy\%chunkspy%.lua --run allopcodes.52.luac 39 | pause 40 | 41 | del allopcodes.rewrite.luac 42 | %lua% ..\ChunkSpy\%chunkspy%.lua -o allopcodes.rewrite.luac --rewrite local allopcodes.lua 43 | pause 44 | %lua% ..\ChunkSpy\%chunkspy%.lua -o allopcodes.rewrite.luac --rewrite local allopcodes.51.luac 45 | pause 46 | %lua% ..\ChunkSpy\%chunkspy%.lua -o allopcodes.rewrite.luac --rewrite local allopcodes.52.luac 47 | pause 48 | fc /a /b allopcodes.rewrite.luac allopcodes.51.luac 49 | pause 50 | fc /a /b allopcodes.rewrite.luac allopcodes.52.luac 51 | pause 52 | 53 | del allopcodes.rewrite.luac 54 | %lua% ..\ChunkSpy\%chunkspy%.lua -o allopcodes.rewrite.luac --rewrite "x86 standard" allopcodes.lua 55 | pause 56 | %lua% ..\ChunkSpy\%chunkspy%.lua -o allopcodes.rewrite.luac --rewrite "x86 standard" allopcodes.51.luac 57 | pause 58 | %lua% ..\ChunkSpy\%chunkspy%.lua -o allopcodes.rewrite.luac --rewrite "x86 standard" allopcodes.52.luac 59 | pause 60 | fc /a /b allopcodes.rewrite.luac allopcodes.51.luac 61 | pause 62 | fc /a /b allopcodes.rewrite.luac allopcodes.52.luac 63 | pause 64 | -------------------------------------------------------------------------------- /bin/ChunkSpy51.bat: -------------------------------------------------------------------------------- 1 | @lua51 ..\ChunkSpy\ChunkSpy51.lua --auto %1 %2 %3 %4 %5 %6 %7 %8 %9 2 | -------------------------------------------------------------------------------- /bin/ChunkSpy52.bat: -------------------------------------------------------------------------------- 1 | @lua52 ..\ChunkSpy\ChunkSpy52.lua --auto %1 %2 %3 %4 %5 %6 %7 %8 %9 2 | -------------------------------------------------------------------------------- /bin/ChunkSpy53.bat: -------------------------------------------------------------------------------- 1 | @lua53 ..\ChunkSpy\ChunkSpy53.lua --auto %1 %2 %3 %4 %5 %6 %7 %8 %9 2 | -------------------------------------------------------------------------------- /bin/allopcodes-5.1.lua: -------------------------------------------------------------------------------- 1 | -- allopcodes-5.1.lua 2 | local u1,u2,u3 3 | function f1(a1,a2,...) 4 | local l0 = a1; -- move 5 | local l1 = 1 -- loadk 6 | local l2 = true -- loadbool 7 | local l3 = nil -- loadnil 8 | local l4 = u1[g1] -- gettupval, getglobal, gettable 9 | g1 = l1 -- setglobal 10 | u2 = l2 -- setupval 11 | l3[l2] = l1 -- settable 12 | local l5 = { -- newtable 13 | l1, l2; -- move, setlist 14 | x = l2 -- settable 15 | } 16 | local l6 = l5:x() -- self, call 17 | local l7 = -((l0+l1-l2)*l3/l4%l5)^l6 -- add, sub, mul, div, mod, pow, unm 18 | local l8 = #(not l7) -- not, len 19 | local l9 = l7..l8 -- concat 20 | if l1==l2 and l2=255 50 | return f1() -- return, tailcall 51 | end 52 | -------------------------------------------------------------------------------- /bin/allopcodes-5.3.lua: -------------------------------------------------------------------------------- 1 | -- allopcodes-5.3.lua 2 | -- loadkx extraarg lacks 3 | local u1,u2,u3 4 | function f1(a1,a2,...) 5 | local l0 = a1; -- move 6 | local l1 = 1 -- loadk 7 | local l2 = true -- loadbool 8 | local l3 = nil -- loadnil 9 | local l4 = u1[l3] -- gettabup 10 | u1[l3] = l4 -- settabup 11 | l1 = g1 -- gettabup l1 = _ENV["g1"] 12 | g1 = l1 -- settabup _ENV["g1"] = l1 13 | l2 = u2 -- getupval 14 | u2 = l2 -- setupval 15 | l1 = l3[l2] -- gettable 16 | l3[l2] = l1 -- settable 17 | local l5 = { -- newtable 18 | l1, l2; -- move, setlist 19 | x = l2 -- settable 20 | } 21 | local l6 = l5:x() -- self, call 22 | local l7 = -((l0+l1-l2)*l3/l4%l5)^l6 -- add, sub, mul, div, mod, pow, unm 23 | local l8 = #(not l7) -- not, len 24 | local l9 = l7..l8 -- concat 25 | if l1==l2 and l2> l1) -- idiv band bor bxor shl shr bnot 42 | local l24 = 22136 -- numint 0x5678 43 | local l25 = 370.5 -- numflt 44 | local l26 = "".."abc" -- shrstr 45 | local l27 = [[ 46 | 12345678901234567890123456789012345678901234567890 47 | 12345678901234567890123456789012345678901234567890 48 | 12345678901234567890123456789012345678901234567890 49 | 12345678901234567890123456789012345678901234567890 50 | 12345678901234567890123456789012345678901234567890 51 | 12345678901234567890123456789012345678901234567890 52 | ]]-- lngstr >=255 53 | return f1() -- return, tailcall 54 | end 55 | -------------------------------------------------------------------------------- /bin/bin2c.lua: -------------------------------------------------------------------------------- 1 | local ipairs = ipairs 2 | local string_byte = string.byte 3 | local string_format = string.format 4 | local table_concat = table.concat 5 | 6 | local filename, varname = ... 7 | 8 | local f = assert(io.open(filename, "rb")) 9 | 10 | print("unsigned char "..varname.."[] = {") 11 | 12 | local len = 0 13 | local fline = f:read(16) 14 | while fline do 15 | local fline_len = #fline 16 | len = len + fline_len 17 | local t = { string_byte(fline, 1, fline_len) } 18 | for k, v in ipairs(t) do 19 | t[k] = string_format("0x%02x", v) 20 | end 21 | fline = f:read(16) 22 | if fline then 23 | print(" "..table_concat(t, ", ")..",") 24 | else 25 | print(" "..table_concat(t, ", ").."") 26 | end 27 | end 28 | 29 | print("};") 30 | print(string_format("unsigned int %s_len = %d;", varname, len)) 31 | 32 | f:close() 33 | -------------------------------------------------------------------------------- /bin/fun_check_count.lua: -------------------------------------------------------------------------------- 1 | local string_find = string.find 2 | 3 | local files, passed, failed, uncompilable = 0, 0, 0, 0 4 | 5 | local filename = ... 6 | local f = filename and assert(io.open(filename, "r")) or io.stdin 7 | for line in f:lines() do 8 | if string_find(line, '^%s*-- function check pass') then 9 | passed = passed + 1 10 | elseif string_find(line, '^%s*-- function check fail') then 11 | failed = failed + 1 12 | if string_find(line, '^%s*-- function check fail [%d_]+ : cannot compile') then 13 | uncompilable = uncompilable + 1 14 | end 15 | elseif string_find(line, '^%s*-- function check Command line') then 16 | files = files + 1 17 | end 18 | end 19 | f:close() 20 | 21 | local fmt = "files: %d, functions: %d, passed: %d, failed: %d, uncompilable: %d, pass rate: %.2f%%" 22 | print(fmt:format(files, passed + failed, passed, failed, uncompilable, 100*passed/(passed + failed))) 23 | -------------------------------------------------------------------------------- /bin/ilua.bat: -------------------------------------------------------------------------------- 1 | @lua ..\ilua\ilua.lua %1 %2 %3 %4 %5 %6 %7 %8 %9 2 | -------------------------------------------------------------------------------- /bin/issue41_gen_large_table.lua: -------------------------------------------------------------------------------- 1 | -- setlist c=0 when top>=25550 2 | -- when top==2^18-1, lua51 cannot compile, but lua52 53 generate code without loadkx 3 | -- loadkx and extraarg when top>=2^18 4 | 5 | print("local x={") 6 | 7 | local top = arg[1] or 2^18+1 8 | local count = 0 9 | for i = 0, top do 10 | io.stdout:write(i,",") 11 | count = count + 1 12 | if count == 20 then 13 | io.stdout:write("\n") 14 | count = 0 15 | end 16 | end 17 | if count ~= 0 then 18 | io.stdout:write("\n") 19 | end 20 | print("}") 21 | -------------------------------------------------------------------------------- /bin/lasmc.bat: -------------------------------------------------------------------------------- 1 | @lua LasmCompiler51.lua %1 %2 %3 %4 %5 %6 %7 %8 %9 2 | -------------------------------------------------------------------------------- /bin/lasmd.bat: -------------------------------------------------------------------------------- 1 | @lua Decompiler51.lua %1 %2 %3 %4 %5 %6 %7 %8 %9 2 | -------------------------------------------------------------------------------- /bin/test-long.bat: -------------------------------------------------------------------------------- 1 | @echo luadec long test 2 | 3 | del test_fc_error.txt test_fc_ns_error.txt test_fc_f_error.txt test_fc_s_error.txt 4 | del test_fc_error_c.txt test_fc_ns_error_c.txt test_fc_f_error_c.txt test_fc_s_error_c.txt 5 | del test_fc_summary.txt test_fc_ns_summary.txt test_fc_f_summary.txt test_fc_s_summary.txt 6 | del test_fc_summary_c.txt test_fc_ns_summary_c.txt test_fc_f_summary_c.txt test_fc_s_summary_c.txt 7 | 8 | for /r ..\test %%f in (*.lua) do @luadec -fc %%f 2>>test_fc_error.txt | findstr /r /c:"-- function check" >>test_fc_summary.txt 9 | for /r ..\test-compiled %%f in (*.lua) do @luadec -fc %%f 2>>test_fc_error_c.txt | findstr /r /c:"-- function check" >>test_fc_summary_c.txt 10 | 11 | for /r ..\test %%f in (*.lua) do @luadec -fc -ns %%f 2>>test_fc_ns_error.txt | findstr /r /c:"-- function check" >>test_fc_ns_summary.txt 12 | for /r ..\test-compiled %%f in (*.lua) do @luadec -fc -ns %%f 2>>test_fc_ns_error_c.txt | findstr /r /c:"-- function check" >>test_fc_ns_summary_c.txt 13 | 14 | for /r ..\test %%f in (*.lua) do @luadec -fc -f 0_3 %%f 2>>test_fc_f_error.txt | findstr /r /c:"-- function check" >>test_fc_f_summary.txt 15 | for /r ..\test-compiled %%f in (*.lua) do @luadec -fc -f 0_3 %%f 2>>test_fc_f_error_c.txt | findstr /r /c:"-- function check" >>test_fc_f_summary_c.txt 16 | 17 | @rem for /r ..\test %%f in (*.lua) do @luadec -fc -s %%f 2>>test_fc_s_error.txt | findstr /r /c:"-- function check" >>test_fc_s_summary.txt 18 | @rem for /r ..\test-compiled %%f in (*.lua) do @luadec -fc -s %%f 2>>test_fc_s_error_c.txt | findstr /r /c:"-- function check" >>test_fc_s_summary_c.txt 19 | 20 | 21 | del test_dis_error.txt 22 | 23 | @(echo luadec -dis)>>test_dis_error.txt 24 | for /r ..\test %%f in (*.lua) do @luadec -dis %%f 2>>test_dis_error.txt 1>nul 25 | for /r ..\test-compiled %%f in (*.lua) do @luadec -dis %%f 2>>test_dis_error.txt 1>nul 26 | 27 | @(echo.)>>test_dis_error.txt 28 | @(echo luadec -dis -ns)>>test_dis_error.txt 29 | for /r ..\test %%f in (*.lua) do @luadec -dis -ns %%f 2>>test_dis_error.txt 1>nul 30 | for /r ..\test-compiled %%f in (*.lua) do @luadec -dis -ns %%f 2>>test_dis_error.txt 1>nul 31 | 32 | @(echo.)>>test_dis_error.txt 33 | @(echo luadec -dis -fn 0_3)>>test_dis_error.txt 34 | for /r ..\test %%f in (*.lua) do @luadec -dis -f 0_3 %%f 2>>test_dis_error.txt 1>nul 35 | for /r ..\test-compiled %%f in (*.lua) do @luadec -dis -f 0_3 %%f 2>>test_dis_error.txt 1>nul 36 | 37 | 38 | lua fun_check_count.lua test_fc_summary.txt 39 | lua fun_check_count.lua test_fc_summary_c.txt 40 | @rem lua fun_check_count.lua test_fc_s_summary.txt 41 | @rem lua fun_check_count.lua test_fc_s_summary_c.txt 42 | -------------------------------------------------------------------------------- /luadec/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua decompiler 2 | 3 | LUAVER=5.1 4 | LUASRC=../lua-$(LUAVER)/src 5 | LIBDIR=$(LUASRC) 6 | BINDIR=../bin 7 | 8 | LUA= $(LUASRC)/lua 9 | LUAC= $(LUASRC)/luac 10 | BIN2C = $(LUA) $(BINDIR)/bin2c.lua 11 | 12 | DEV_NULL= /dev/null 13 | CP= cp -f 14 | RM= rm -f 15 | 16 | CC= gcc 17 | CFLAGS= -O2 -Wall -DSRCVERSION=\"$(SRCVERSION)\" $(INCS) $(MYCFLAGS) 18 | LDFLAGS= $(MYLDFLAGS) 19 | AR= ar rcu 20 | RANLIB= ranlib 21 | LIBS= -lm $(MYLIBS) 22 | 23 | ifeq ($(wildcard /dev/null),) 24 | DEV_NULL= NUL 25 | RM= cmd //c del //f //s //q 26 | endif 27 | 28 | SRCVERSION=UNKNOWN 29 | SVN_STATUS:=$(shell svn info 1>$(DEV_NULL) 2>$(DEV_NULL); echo $$?) 30 | ifeq ($(SVN_STATUS),0) 31 | SRCVERSION:=$(shell svnversion -q -n .) 32 | endif 33 | GIT_STATUS:=$(shell git log -n 1 --format=format:%h 1>$(DEV_NULL) 2>$(DEV_NULL); echo $$?) 34 | ifeq ($(GIT_STATUS),0) 35 | SRCVERSION:=$(shell git log -n 1 --format=format:%h) 36 | endif 37 | 38 | MYCFLAGS= 39 | MYLDFLAGS= 40 | MYLIBS= 41 | MYOBJS= 42 | 43 | INCS= -I$(LUASRC) 44 | OBJS= guess.o luadec.o decompile.o disassemble.o proto.o StringBuffer.o structs.o statement.o macro-array.o expression.o 45 | SRCS= guess.c luadec.c decompile.c disassemble.c proto.c StringBuffer.c structs.c statement.c macro-array.c expression.c 46 | 47 | T= luadec 48 | 49 | all: $T luareplace luaopswap 50 | 51 | $T: $(OBJS) $(MYOBJS) $(LIBDIR)/liblua.a 52 | $(CC) -o $@ $(LDFLAGS) $^ $(LIBS) 53 | 54 | debug: 55 | $(MAKE) all MYCFLAGS="-g -DDEBUG -D_DEBUG" 56 | 57 | memwatch: 58 | $(MAKE) all MYCFLAGS="-g -DDEBUG -D_DEBUG -DMEMCHECK_MEMWATCH -I../memwatch/" MYOBJS="memwatch.o" 59 | 60 | memwatch.o: ../memwatch/memwatch.c ../memwatch/memwatch.h 61 | $(CC) -o $@ -c $(CFLAGS) $(INCS) ../memwatch/memwatch.c 62 | 63 | $(LIBDIR)/liblua.a: 64 | cd $(LUASRC); $(MAKE) 65 | 66 | luareplace.o: luareplace.c 67 | luareplace: luareplace.o $(LIBDIR)/liblua.a 68 | $(CC) -o $@ $(LDFLAGS) $^ $(LIBS) 69 | 70 | allopcodes_lua.h: $(BINDIR)/allopcodes-$(LUAVER).lua 71 | $(BIN2C) $(BINDIR)/allopcodes-$(LUAVER).lua allopcodes_lua > allopcodes_lua.h 72 | allopcodes.luac: $(BINDIR)/allopcodes-$(LUAVER).lua 73 | $(LUAC) -o allopcodes.luac $(BINDIR)/allopcodes-$(LUAVER).lua 74 | allopcodes_luac.h: allopcodes.luac 75 | $(BIN2C) allopcodes.luac allopcodes_luac > allopcodes_luac.h 76 | 77 | LUNDUMP:= 78 | ifeq ($(LUAVER),5.1) 79 | LUNDUMP:=lundump-5.1.o 80 | endif 81 | lundump-5.1.o: lundump-5.1.c 82 | luaopswap.o: luaopswap.c allopcodes_lua.h allopcodes_luac.h 83 | luaopswap: luaopswap.o $(LUNDUMP) $(LIBDIR)/liblua.a 84 | $(CC) -o $@ $(LDFLAGS) $^ $(LIBS) 85 | 86 | clean: 87 | $(RM) *.o *.exe 88 | $(RM) allopcodes* 89 | -------------------------------------------------------------------------------- /luadec/StringBuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef LUADEC_STRINGBUFFER_H 2 | #define LUADEC_STRINGBUFFER_H 3 | 4 | #include 5 | #include 6 | 7 | #define STRINGBUFFER_BLOCK 256 8 | 9 | typedef struct StringBuffer_ StringBuffer; 10 | struct StringBuffer_ { 11 | char* buffer; 12 | int bufferSize; 13 | int usedSize; 14 | }; 15 | 16 | #define StringBuffer_strlen(self) ((self)->usedSize) 17 | 18 | #define StringBuffer_firstChar(self) ((self)->buffer[0]) 19 | 20 | #define StringBuffer_lastChar(self) ((self)->buffer[(self)->usedSize - 1]) 21 | 22 | StringBuffer* StringBuffer_newBySize(int size); 23 | 24 | StringBuffer* StringBuffer_new(const char* data); 25 | 26 | void StringBuffer_delete(StringBuffer* self); 27 | 28 | void StringBuffer_makeRoom(StringBuffer* self, int neededSize); 29 | 30 | void StringBuffer_addChar(StringBuffer* self, char ch); 31 | 32 | void StringBuffer_add(StringBuffer* self, const char* str); 33 | 34 | void StringBuffer_prepend(StringBuffer* self, const char* str); 35 | 36 | void StringBuffer_set(StringBuffer* self, const char* str); 37 | 38 | void StringBuffer_addAll(StringBuffer* self, int n, ...); 39 | 40 | #ifdef __GNUC__ 41 | #define PRINTF_FUNCTION __attribute__ ((format (printf, 2, 3))) 42 | #else 43 | #define PRINTF_FUNCTION 44 | #endif 45 | 46 | void StringBuffer_printf(StringBuffer* self, char* format, ...) PRINTF_FUNCTION; 47 | 48 | void StringBuffer_addPrintf(StringBuffer* self, char* format, ...) PRINTF_FUNCTION; 49 | 50 | // get a copy of StringBuffer.buffer 51 | char* StringBuffer_getCopy(StringBuffer* self); 52 | 53 | // transfer the ownership of self->buffer to return, leave a empty StringBuffer 54 | char* StringBuffer_getBuffer(StringBuffer* self); 55 | 56 | // self will get the ownership of data 57 | void StringBuffer_setBuffer(StringBuffer* self, char* data); 58 | 59 | // return self->buffer , you should use it readonly 60 | const char* StringBuffer_getRef(StringBuffer* self); 61 | 62 | void StringBuffer_prune(StringBuffer* self); 63 | 64 | #endif // #ifndef LUADEC_STRINGBUFFER_H 65 | -------------------------------------------------------------------------------- /luadec/common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef LUADEC_COMMON_H 4 | #define LUADEC_COMMON_H 5 | 6 | #ifdef _DEBUG 7 | 8 | #if defined MEMCHECK_VLD 9 | #include 10 | #include 11 | #elif defined MEMCHECK_MEMWATCH 12 | #define MEMWATCH 13 | #define MW_STDIO 14 | #include 15 | #include "memwatch.h" 16 | #endif 17 | 18 | #endif // #ifdef _DEBUG 19 | 20 | #define MACRO_STR_RAW(tok) #tok 21 | #define MACRO_STR(tok) MACRO_STR_RAW(tok) 22 | 23 | #ifndef cast 24 | #define cast(t,exp) ((t)(exp)) 25 | #endif // #ifndef cast 26 | 27 | #ifndef NULL 28 | #define NULL ((void *)0) 29 | #endif // #ifndef NULL 30 | 31 | #endif // #ifndef LUADEC_COMMON_H 32 | -------------------------------------------------------------------------------- /luadec/decompile.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/luadec/decompile.c -------------------------------------------------------------------------------- /luadec/disassemble.h: -------------------------------------------------------------------------------- 1 | #ifndef LUADEC_DISASSEMBLE_H 2 | #define LUADEC_DISASSEMBLE_H 3 | 4 | #include "lua.h" 5 | #include "lobject.h" 6 | 7 | #define CC(r) (ISK((r)) ? 'K' : 'R') 8 | #define CV(r) (ISK((r)) ? INDEXK(r) : r) 9 | 10 | #define RK(r) (RegOrConst(f, r)) 11 | 12 | #define MAXCONSTSIZE 1024 13 | 14 | void luadec_disassemble(Proto* fwork, int dflag, const char* name); 15 | 16 | void luadec_disassembleSubFunction(Proto* f, int dflag, const char* funcnumstr); 17 | 18 | char* RegOrConst(const Proto* f, int r); 19 | 20 | #endif // #ifndef LUADEC_DISASSEMBLE_H 21 | -------------------------------------------------------------------------------- /luadec/expression.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "lopcodes.h" 9 | 10 | #include "lua-compat.h" 11 | #include "structs.h" 12 | #include "StringBuffer.h" 13 | 14 | #include "expression.h" 15 | 16 | Expression* MakeExpression(ExpressionType type, int reg, int pc, int idx, OpCode op) { 17 | Expression* exp = calloc(1, sizeof(Expression)); 18 | exp->type = type; 19 | exp->reg = reg; 20 | exp->pc = pc; 21 | exp->idx = idx; 22 | exp->op = op; 23 | exp->left = NULL; 24 | exp->right = NULL; 25 | exp->args = NULL; 26 | return exp; 27 | } 28 | 29 | Expression* MakeConstValExpression(int reg, int pc, int idx, OpCode op) { 30 | Expression* exp = MakeExpression(CONST_VAL, reg, pc, idx, op); 31 | return exp; 32 | } 33 | 34 | Expression* MakeLocalVarExpression(int reg, int pc, int idx) { 35 | Expression* exp = MakeExpression(LOCAL_VAR, reg, pc, idx, -1); 36 | return exp; 37 | } 38 | 39 | Expression* MakeGlobalVarExpression(int reg, int pc, int idx, OpCode op) { 40 | Expression* exp = MakeExpression(GLOBAL_VAR, reg, pc, idx, op); 41 | return exp; 42 | } 43 | 44 | Expression* MakeUpvalVarExpression(int reg, int pc, int idx, OpCode op) { 45 | Expression* exp = MakeExpression(UPVAL_VAR, reg, pc, idx, op); 46 | return exp; 47 | } 48 | 49 | Expression* MakeVarargVarExpression(int reg, int pc) { 50 | Expression* exp = MakeExpression(VARARG_VAR, reg, pc, -1, OP_VARARG); 51 | return exp; 52 | } 53 | 54 | Expression* MakeFuncDefExpression(int reg, int pc, int idx) { 55 | Expression* exp = MakeExpression(FUNC_DEF, reg, pc, idx, OP_CLOSURE); 56 | return exp; 57 | } 58 | 59 | Expression* MakeTableDefExpression(int reg, int pc) { 60 | Expression* exp = MakeExpression(TABLE_DEF, reg, pc, -1, OP_NEWTABLE); 61 | return exp; 62 | } 63 | 64 | Expression* MakeTableRefExpression(int reg, int pc, int idx, OpCode op) { 65 | Expression* exp = MakeExpression(TABLE_REF, reg, pc, idx, op); 66 | return exp; 67 | } 68 | 69 | Expression* MakeFuncCallExpression(int reg, int pc, OpCode op, Expression* func) { 70 | Expression* exp = MakeExpression(FUNC_CALL, reg, pc, -1, op); 71 | exp->left = func; 72 | exp->args = NewList(); 73 | return exp; 74 | } 75 | 76 | Expression* MakeUnaryExpression(int reg, int pc, OpCode op, Expression* sub) { 77 | Expression* exp = MakeExpression(UNARY_EXP, reg, pc, -1, op); 78 | exp->left = sub; 79 | return exp; 80 | } 81 | 82 | Expression* MakeBinaryExpression(int reg, int pc, OpCode op, Expression* left, Expression* right) { 83 | Expression* exp = MakeExpression(BINARY_EXP, reg, pc, -1, op); 84 | exp->left = left; 85 | exp->right = right; 86 | return exp; 87 | } 88 | 89 | void PrintExpression(Expression* exp, StringBuffer* buff, int indent) { 90 | } 91 | 92 | void ClearExpression(Expression* exp, void* dummy) { 93 | Expression* left = exp->left; 94 | Expression* right = exp->right; 95 | List* args = exp->args; 96 | exp->left = NULL; 97 | exp->right = NULL; 98 | exp->args = NULL; 99 | if (left) { 100 | DeleteExpression(left); 101 | } 102 | if (right) { 103 | DeleteExpression(right); 104 | } 105 | if (args) { 106 | ClearList(args, (ListItemFn)ClearExpression); 107 | free(args); 108 | } 109 | } 110 | 111 | void DeleteExpression(Expression* exp) { 112 | ClearExpression(exp, NULL); 113 | free(exp); 114 | } 115 | -------------------------------------------------------------------------------- /luadec/expression.h: -------------------------------------------------------------------------------- 1 | #ifndef LUADEC_EXPRESSION_H 2 | #define LUADEC_EXPRESSION_H 3 | 4 | #include "lopcodes.h" 5 | 6 | #include "lua-compat.h" 7 | #include "structs.h" 8 | #include "StringBuffer.h" 9 | 10 | typedef enum ExpressionType_ ExpressionType; 11 | enum ExpressionType_ { 12 | CONST_VAL, 13 | 14 | LOCAL_VAR, 15 | GLOBAL_VAR, 16 | UPVAL_VAR, 17 | VARARG_VAR, 18 | 19 | FUNC_DEF, 20 | TABLE_DEF, 21 | 22 | TABLE_REF, 23 | 24 | FUNC_CALL, 25 | 26 | UNARY_EXP, 27 | BINARY_EXP 28 | }; 29 | 30 | typedef struct Expression_ Expression; 31 | struct Expression_ { 32 | ExpressionType type; 33 | OpCode op; 34 | int reg; 35 | int pc; 36 | int idx; 37 | Expression* left; 38 | Expression* right; 39 | List* args; 40 | }; 41 | 42 | Expression* MakeConstValExpression(int reg, int pc, int idx, OpCode op); 43 | 44 | Expression* MakeLocalVarExpression(int reg, int pc, int idx); 45 | Expression* MakeGlobalVarExpression(int reg, int pc, int idx, OpCode op); 46 | Expression* MakeUpvalVarExpression(int reg, int pc, int idx, OpCode op); 47 | Expression* MakeVarargVarExpression(int reg, int pc); 48 | 49 | Expression* MakeFuncDefExpression(int reg, int pc, int idx); 50 | Expression* MakeTableDefExpression(int reg, int pc); 51 | 52 | Expression* MakeTableRefExpression(int reg, int pc, int idx, OpCode op); 53 | 54 | Expression* MakeFuncCallExpression(int reg, int pc, OpCode op, Expression* func); 55 | 56 | Expression* MakeUnaryExpression(int reg, int pc, OpCode op, Expression* sub); 57 | Expression* MakeBinaryExpression(int reg, int pc, OpCode op, Expression* left, Expression* right); 58 | 59 | 60 | void PrintExpression(Expression* exp, StringBuffer* buff, int indent); 61 | 62 | void ClearExpression(Expression* exp, void* dummy); 63 | void DeleteExpression(Expression* exp); 64 | 65 | #endif // #ifndef LUADEC_EXPRESSION_H -------------------------------------------------------------------------------- /luadec/gen-allopcodes-h.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | set OUTDIR=%1 3 | set LUAFILE=%2 4 | echo copying %LUAFILE% 5 | copy /y ..\bin\%LUAFILE% allopcodes.lua 6 | echo generating allopcodes.luac 7 | %OUTDIR%\luac -o allopcodes.luac allopcodes.lua 8 | echo generating allopcodes_lua.h 9 | %OUTDIR%\lua ..\bin\bin2c.lua allopcodes.lua allopcodes_lua > allopcodes_lua.h 10 | echo generating allopcodes_luac.h 11 | %OUTDIR%\lua ..\bin\bin2c.lua allopcodes.luac allopcodes_luac > allopcodes_luac.h 12 | @echo on 13 | -------------------------------------------------------------------------------- /luadec/gen-git-srcversion.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | if not defined TERM (set TERM=msys) 3 | echo generating srcversion.h using "git log -n 1 --format=format:%%%%h" 4 | git log -n 1 --format=format:%%h%%n 5 | (echo #ifndef LUADEC_SRCVERSION_H) > srcversion.h 6 | (echo #define LUADEC_SRCVERSION_H) >> srcversion.h 7 | (echo.) >> srcversion.h 8 | (echo|set /p=#define SRCVERSION ^") >> srcversion.h 9 | git log -n 1 --format=format:%%h >> srcversion.h 10 | (echo ^") >> srcversion.h 11 | (echo.) >> srcversion.h 12 | (echo #endif // #ifndef LUADEC_SRCVERSION_H) >> srcversion.h 13 | @echo on 14 | -------------------------------------------------------------------------------- /luadec/gen-svn-srcversion.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo generating srcversion.h using "svnversion -n ." 3 | svnversion -n . 4 | (echo #ifndef LUADEC_SRCVERSION_H) > srcversion.h 5 | (echo #define LUADEC_SRCVERSION_H) >> srcversion.h 6 | (echo.) >> srcversion.h 7 | (echo|set /p=#define SRCVERSION ^") >> srcversion.h 8 | svnversion -n . >> srcversion.h 9 | (echo ^") >> srcversion.h 10 | (echo.) >> srcversion.h 11 | (echo #endif // #ifndef LUADEC_SRCVERSION_H) >> srcversion.h 12 | @echo on 13 | -------------------------------------------------------------------------------- /luadec/lua-compat.h: -------------------------------------------------------------------------------- 1 | // should be included after lua*.h 2 | #ifndef LUADEC_LUA_COMPAT_H 3 | #define LUADEC_LUA_COMPAT_H 4 | 5 | #include "lua.h" 6 | 7 | #if LUA_VERSION_NUM == 501 8 | #define luadec_freearray(L, b, n, t) luaM_freearray(L, b, n, t) 9 | 10 | #define UPVAL_TYPE TString* 11 | #define NUPS(f) (f->nups) 12 | #define UPVAL_NAME(f, r) (f->upvalues[r]) 13 | 14 | #define LUADEC_TFORLOOP OP_TFORLOOP 15 | #define FUNC_BLOCK_END(f) (f->sizecode - 1) 16 | 17 | // Lua 5.1 #define LUA_COMPAT_VARARG : is_vararg = 0 2 3 7, 2 is main, 3 and 7 has another parament arg 18 | // Lua 5.1 #undef LUA_COMPAT_VARARG : is_vararg = 0 2, 2 is main or which use ..., never use arg 19 | #define NEED_ARG(f) (((f->is_vararg == 3) || (f->is_vararg == 7))?1:0) 20 | #endif 21 | #if LUA_VERSION_NUM == 501 || LUA_VERSION_NUM == 502 22 | #define LUA_STRLEN(ts) ((ts)->tsv.len) 23 | #endif 24 | #if LUA_VERSION_NUM == 502 || LUA_VERSION_NUM == 503 25 | #define lua_open() luaL_newstate() 26 | #define luadec_freearray(L, b, n, t) luaM_freearray(L, b, n) 27 | 28 | #define UPVAL_TYPE Upvaldesc 29 | #define NUPS(f) (f->sizeupvalues) 30 | #define UPVAL_NAME(f, r) (f->upvalues[r].name) 31 | 32 | #define LUADEC_TFORLOOP OP_TFORCALL 33 | #define FUNC_BLOCK_END(f) (f->sizecode) 34 | 35 | // Lua >= 5.2 : is_vararg = 0 1 , never use parament arg, but main has a global arg 36 | #define NEED_ARG(f) 0 37 | #endif 38 | #if LUA_VERSION_NUM == 503 39 | #define rawtsvalue(o) tsvalue(o) 40 | 41 | #ifdef tsslen 42 | #define LUA_STRLEN(ts) tsslen(ts) 43 | #else 44 | #define LUA_STRLEN(ts) ((ts)->len) 45 | #endif 46 | 47 | #define MAXREGS 250 48 | #define MAXSTACK MAXREGS 49 | #endif 50 | 51 | #endif // #ifndef LUADEC_LUA_COMPAT_H 52 | -------------------------------------------------------------------------------- /luadec/macro-array.c: -------------------------------------------------------------------------------- 1 | #include "lobject.h" 2 | 3 | #define T int 4 | #define TArray_IMPLEMENT 5 | #include "macro-array.h" 6 | #undef T 7 | 8 | #define T LocVar 9 | #define TArray_IMPLEMENT 10 | #include "macro-array.h" 11 | #undef T 12 | -------------------------------------------------------------------------------- /luadec/macro-array.h: -------------------------------------------------------------------------------- 1 | #ifndef T 2 | #error You must define T before include macro_array.h 3 | #endif 4 | 5 | #include 6 | #include 7 | 8 | #define _CAT2(x,y) x##y 9 | #define CAT2(x,y) _CAT2(x,y) 10 | 11 | #define TArray CAT2(T,Array) 12 | #define TArray_ CAT2(T,Array_) 13 | 14 | typedef struct TArray_ TArray; 15 | struct TArray_ { 16 | int capacity; 17 | int size; 18 | T* values; 19 | }; 20 | 21 | #define TArray_Init CAT2(T,Array_Init) 22 | extern void TArray_Init(TArray* ia, int init_capacity); 23 | 24 | #define TArray_Clear CAT2(T,Array_Clear) 25 | extern void TArray_Clear(TArray* ia); 26 | 27 | #define TArray_Push CAT2(T,Array_Push) 28 | extern void TArray_Push(TArray* ia, T value); 29 | 30 | #define TArray_Size CAT2(T,Array_Size) 31 | extern int TArray_Size(TArray* ia); 32 | 33 | #define TArray_Pop CAT2(T,Array_Pop) 34 | extern T TArray_Pop(TArray* ia); 35 | 36 | #define TArray_Peek CAT2(T,Array_Peek) 37 | extern T TArray_Peek(TArray* ia); 38 | 39 | #define TArray_Get CAT2(T,Array_Get) 40 | extern T TArray_Get(TArray* ia, int idx); 41 | 42 | #define TArray_Set CAT2(T,Array_Set) 43 | extern void TArray_Set(TArray* ia, int idx, T value); 44 | 45 | 46 | #ifdef TArray_IMPLEMENT 47 | 48 | void TArray_Init(TArray* ia, int init_capacity) { 49 | ia->capacity = init_capacity; 50 | ia->size = 0; 51 | ia->values = (T*)calloc(init_capacity, sizeof(T)); 52 | } 53 | 54 | void TArray_Clear(TArray* ia) { 55 | ia->capacity = 0; 56 | ia->size = 0; 57 | free(ia->values); 58 | ia->values = (void*)0; 59 | } 60 | 61 | void TArray_Push(TArray* ia, T value) { 62 | if (ia->size >= ia->capacity) { 63 | ia->capacity = ia->capacity * 2; 64 | ia->values = (T*)realloc(ia->values, (ia->capacity) * sizeof(T)); 65 | } 66 | ia->values[ia->size] = value; 67 | ia->size++; 68 | } 69 | 70 | int TArray_Size(TArray* ia) { 71 | return ia->size; 72 | } 73 | 74 | T TArray_Pop(TArray* ia) { 75 | assert(ia->size > 0); 76 | ia->size--; 77 | return ia->values[ia->size]; 78 | } 79 | 80 | T TArray_Peek(TArray* ia) { 81 | assert(ia->size > 0); 82 | return ia->values[ia->size - 1]; 83 | } 84 | 85 | T TArray_Get(TArray* ia, int idx) { 86 | assert(idx < ia->size); 87 | return ia->values[idx]; 88 | } 89 | 90 | void TArray_Set(TArray* ia, int idx, T value) { 91 | assert(idx < ia->size); 92 | ia->values[idx] = value; 93 | } 94 | 95 | #undef TArray_IMPLEMENT 96 | #endif // TArray_IMPLEMENT 97 | 98 | #undef TArray 99 | #undef TArray_ 100 | #undef TArray_Init 101 | #undef TArray_Clear 102 | #undef TArray_Push 103 | #undef TArray_Size 104 | #undef TArray_Pop 105 | #undef TArray_Peek 106 | #undef TArray_Get 107 | #undef TArray_Set 108 | -------------------------------------------------------------------------------- /luadec/proto.h: -------------------------------------------------------------------------------- 1 | #ifndef LUADEC_PROTO_H 2 | #define LUADEC_PROTO_H 3 | 4 | #include "ldebug.h" 5 | #include "lobject.h" 6 | #include "lopcodes.h" 7 | #include "lundump.h" 8 | 9 | #define ASCII 437 10 | #define GB2312 20936 11 | #define GBK 936 12 | #define GB18030 54936 13 | #define BIG5 950 14 | #define UTF8 65001 15 | 16 | #define ENCODINGS "ASCII GB2312 GBK GB18030 BIG5 UTF8" 17 | 18 | #define GLOBAL(r) ((char*)svalue(&f->k[r])) 19 | #define opstr(o) ((o)==OP_EQ?"==":(o)==OP_LE?"<=":(o)==OP_LT?"<":(((o)==OP_TEST)||((o)==OP_TESTSET))?NULL:"?") // Lua5.1 specific 20 | #define invopstr(o) ((o)==OP_EQ?"~=":(o)==OP_LE?">":(o)==OP_LT?">=":(((o)==OP_TEST)||((o)==OP_TESTSET))?"not":"?") // Lua5.1 specific 21 | #define IsMain(f) ((f)==glproto) 22 | 23 | extern const char* operators[]; 24 | 25 | extern int priorities[]; 26 | 27 | extern int string_encoding; 28 | 29 | typedef struct Inst_ Inst; 30 | struct Inst_ { 31 | OpCode op; 32 | int a; 33 | int b; 34 | int c; 35 | int bx; 36 | int sbx; 37 | #if LUA_VERSION_NUM == 502 || LUA_VERSION_NUM == 503 38 | int ax; 39 | #endif 40 | }; 41 | 42 | Inst extractInstruction(Instruction i); 43 | Instruction assembleInstruction(Inst inst); 44 | 45 | void InitOperators(); 46 | 47 | int getEncoding(const char* src); 48 | 49 | char* DecompileString(const TValue* o); 50 | 51 | char* DecompileConstant(const Proto* f, int i); 52 | 53 | #endif // #ifndef LUADEC_PROTO_H 54 | -------------------------------------------------------------------------------- /luadec/srcversion.h.template: -------------------------------------------------------------------------------- 1 | #ifndef LUADEC_SRCVERSION_H 2 | #define LUADEC_SRCVERSION_H 3 | 4 | #define SRCVERSION "$WCREV$" 5 | 6 | #endif // #ifndef LUADEC_SRCVERSION_H 7 | -------------------------------------------------------------------------------- /luadec/statement.h: -------------------------------------------------------------------------------- 1 | #ifndef LUADEC_STATEMENT_H 2 | #define LUADEC_STATEMENT_H 3 | 4 | // Abstract syntax tree, Statements tree 5 | 6 | #include "StringBuffer.h" 7 | #include "structs.h" 8 | 9 | typedef enum StatementType_ StatementType; 10 | enum StatementType_ { 11 | SIMPLE_STMT, 12 | BREAK_STMT, 13 | RETURN_STMT, 14 | FUNCTION_STMT, 15 | DO_STMT, 16 | WHILE_STMT, 17 | REPEAT_STMT, 18 | FORLOOP_STMT, 19 | TFORLOOP_STMT, 20 | IF_STMT, 21 | IF_THEN_STMT, 22 | IF_ELSE_STMT, 23 | JMP_DEST_STMT // virtual statement, mark for JMP destination, some of the statements will be printed as label in 5.2 24 | }; 25 | 26 | extern const char* const stmttype[]; 27 | 28 | typedef struct AstStatement_ AstStatement; 29 | struct AstStatement_ { 30 | ListItem super; 31 | AstStatement* parent; 32 | StatementType type; 33 | char* code; 34 | List* sub; 35 | int line; 36 | int sub_print_count; 37 | int comment_print_count; 38 | }; 39 | 40 | AstStatement* MakeStatement(StatementType type, char* code); 41 | AstStatement* MakeSimpleStatement(char* code); 42 | AstStatement* MakeBlockStatement(StatementType type, char* code); 43 | AstStatement* MakeIfStatement(char* test); 44 | 45 | #define ThenStmt(ifstmt) cast(AstStatement*, (ifstmt)->sub->head) 46 | #define ElseStmt(ifstmt) cast(AstStatement*, (ifstmt)->sub->tail) 47 | #define ThenStart(ifstmt) (cast(AstStatement*, (ifstmt)->sub->head)->line) 48 | #define ElseStart(ifstmt) (cast(AstStatement*, (ifstmt)->sub->tail)->line) 49 | 50 | void ClearAstStatement(AstStatement* stmt, void* dummy); 51 | void DeleteAstStatement(AstStatement* stmt); 52 | 53 | void PrintIndent(StringBuffer* buff, int indent); 54 | void PrintAstStatement(AstStatement* stmt, StringBuffer* buff, int indent); 55 | void PrintAstSub(AstStatement* blockstmt, StringBuffer* buff, int indent); 56 | 57 | void AddToStatement(AstStatement* stmt, AstStatement* sub); 58 | 59 | #endif // #ifndef LUADEC_STATEMENT_H 60 | -------------------------------------------------------------------------------- /luadec/structs.h: -------------------------------------------------------------------------------- 1 | #ifndef LUADEC_STRUCTS_H 2 | #define LUADEC_STRUCTS_H 3 | 4 | /* 5 | ** List is a doubly-linked list 6 | */ 7 | typedef struct ListItem_ ListItem; 8 | struct ListItem_ { 9 | ListItem* next; 10 | ListItem* prev; 11 | }; 12 | 13 | typedef struct List_ List; 14 | struct List_ { 15 | ListItem* head; 16 | ListItem* tail; 17 | int size; 18 | }; 19 | 20 | typedef void (*ListItemFn)(ListItem*, void*); 21 | typedef int (*ListItemCmpFn)(ListItem*, const void*); 22 | 23 | List* NewList(); 24 | void InitList(List* list); 25 | void AddToList(List* list, ListItem* item); 26 | void AddToListHead(List* list, ListItem* item); 27 | ListItem* FirstItem(List* list); 28 | ListItem* LastItem(List* list); 29 | ListItem* PopFromList(List* list); 30 | void LoopList(List* list, ListItemFn fn, void* param); 31 | void ClearList(List* list, ListItemFn fn); 32 | ListItem* FindFromListHead(List* list, ListItemCmpFn cmp, const void* sample); 33 | ListItem* FindFromListTail(List* list, ListItemCmpFn cmp, const void* sample); 34 | ListItem* RemoveFromList(List* list, ListItem* item); 35 | int AddAllAfterListItem(List* list, ListItem* pos, ListItem* item); 36 | int AddAllBeforeListItem(List* list, ListItem* pos, ListItem* item); 37 | 38 | /* 39 | ** IntSet is a Set that contains int 40 | */ 41 | typedef struct IntSet_ IntSet; 42 | struct IntSet_ { 43 | List list; 44 | int mayRepeat; 45 | }; 46 | 47 | typedef struct IntSetItem_ IntSetItem; 48 | struct IntSetItem_ { 49 | ListItem super; 50 | int value; 51 | }; 52 | 53 | #define SET_SIZE(s) ((s)->list.size) 54 | #define SET_IS_EMPTY(s) ((s)->list.size == 0) 55 | 56 | IntSet* NewIntSet(int mayRepeat); 57 | void InitIntSet(IntSet* set, int mayRepeat); 58 | void DeleteIntSet(IntSet* set); 59 | int AddToSet(IntSet* set, int a); 60 | int PeekSet(IntSet* set, int a); 61 | int PopSet(IntSet* set); 62 | int RemoveFromSet(IntSet* set, int a); 63 | 64 | /* 65 | ** a Stack that use List 66 | */ 67 | typedef struct VarListItem_ VarListItem; 68 | struct VarListItem_ { 69 | ListItem super; 70 | char* dest; 71 | char* src; 72 | int reg; 73 | }; 74 | 75 | void AddToVarList(List* stack, char* dest, char* src, int reg); 76 | void ClearVarListItem(VarListItem* item, void* dummy); 77 | 78 | #endif // #ifndef LUADEC_STRUCTS_H 79 | -------------------------------------------------------------------------------- /test-compiled/lua-5.1/JX3_BF_Base_BigFoot.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/JX3_BF_Base_BigFoot.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/JX3_BF_ChannelsSimulator.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/JX3_BF_ChannelsSimulator.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/JX3_BF_InfoBox.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/JX3_BF_InfoBox.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/JX3_BF_QuestPlus.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/JX3_BF_QuestPlus.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/JX3_BF_Quest_Data.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/JX3_BF_Quest_Data.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/JX3_Xu_MacroFHX_Main.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/JX3_Xu_MacroFHX_Main.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/c01_daisy01.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/c01_daisy01.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/config.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/config.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/cont.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/cont.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/cont_game.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/cont_game.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/crystal.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/crystal.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/game.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/game.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/help_reload.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/help_reload.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/invite.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/invite.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/kpi.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/kpi.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/main.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/main.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/modstatus.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/modstatus.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/modstatus1.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/modstatus1.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/powerup.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/powerup.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/stage.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/stage.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/status.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/status.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/status4.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/status4.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/defense_witches/title.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/defense_witches/title.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/dialer_md5_encrypt_data.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/dialer_md5_encrypt_data.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/gcode1_db_m.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/gcode1_db_m.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/gcode7_cave.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/gcode7_cave.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/gcode9_WeightStation.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/gcode9_WeightStation.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/pangu_formula_action_formula_c.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/pangu_formula_action_formula_c.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/pangu_formula_gossip_lingshou.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/pangu_formula_gossip_lingshou.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/popup_hint.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/popup_hint.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/xunlei/Button.xml.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/xunlei/Button.xml.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/xunlei/CheckBox.xml.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/xunlei/CheckBox.xml.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/xunlei/DownloaderAssistantWnd.xml.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/xunlei/DownloaderAssistantWnd.xml.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/xunlei/DownloaderHelper.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/xunlei/DownloaderHelper.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/xunlei/DownloaderMainWnd.xml.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/xunlei/DownloaderMainWnd.xml.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/xunlei/DownloaderMainWnd727.xml.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/xunlei/DownloaderMainWnd727.xml.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/xunlei/DownloaderMessageBox.xml.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/xunlei/DownloaderMessageBox.xml.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/xunlei/ImageButton.xml.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/xunlei/ImageButton.xml.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/xunlei/Progress.xml.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/xunlei/Progress.xml.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/xunlei/Root.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/xunlei/Root.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/xunlei/TextLink.xml.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/xunlei/TextLink.xml.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/xunlei/checkEnv.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/xunlei/checkEnv.lua -------------------------------------------------------------------------------- /test-compiled/lua-5.1/xunlei/onload.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test-compiled/lua-5.1/xunlei/onload.lua -------------------------------------------------------------------------------- /test/0512/if.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | 3 | --while a > 0 do 4 | print(a) 5 | if b > 0 then 6 | print(c) 7 | --break 8 | end 9 | --end 10 | 11 | print(c) -------------------------------------------------------------------------------- /test/0512/repeat-for.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | 3 | repeat 4 | for i = 1,100,5 do 5 | a = a + i 6 | end 7 | until false -------------------------------------------------------------------------------- /test/0512/repeat-repeat.lua: -------------------------------------------------------------------------------- 1 | local a, b, c = nil, nil, nil 2 | repeat 3 | repeat 4 | repeat 5 | print(a) 6 | until a > 0 7 | do break end 8 | until b > 0 9 | c = a + b 10 | until d > 0 -------------------------------------------------------------------------------- /test/0512/repeat-until.lua: -------------------------------------------------------------------------------- 1 | local a,b 2 | repeat 3 | if a>0 then 4 | break 5 | end 6 | print(a) 7 | until b<0 -------------------------------------------------------------------------------- /test/0512/repeat.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | 3 | repeat 4 | print(a) 5 | if b > 0 then 6 | print(c) 7 | end 8 | until a > 0 -------------------------------------------------------------------------------- /test/0512/repeat4.lua: -------------------------------------------------------------------------------- 1 | local function a1() 2 | local a,b,c 3 | repeat 4 | repeat 5 | print(a) 6 | until c > 0 7 | afunc() 8 | until false 9 | end 10 | 11 | local function a2() 12 | local a,b,c 13 | repeat 14 | print(a) 15 | if c > 0 then 16 | afunc() 17 | end 18 | until false 19 | end 20 | 21 | 22 | local function a3() 23 | local a,b,c 24 | repeat 25 | repeat 26 | print(a) 27 | until c > 0 28 | afunc() 29 | until a > 0 30 | end 31 | 32 | local function a4() 33 | local a,b,c 34 | repeat 35 | print(a) 36 | if c > 0 then 37 | afunc() 38 | end 39 | until a > 0 40 | end -------------------------------------------------------------------------------- /test/0512/upvalue-list.lua: -------------------------------------------------------------------------------- 1 | local up 2 | 3 | local function a() 4 | up = {2,3,4} 5 | local x = 3 6 | local z = function() 7 | return up, x 8 | end 9 | return z 10 | end 11 | 12 | local function b() 13 | end -------------------------------------------------------------------------------- /test/0512/while-error.lua: -------------------------------------------------------------------------------- 1 | local i, cBits, cPos = 0, 0, 1 2 | --local i, cBits, cPos 3 | while i < 30 do 4 | while cBits < 8 do 5 | cPos = cPos + 1 6 | end 7 | while cBits >= 8 do 8 | i = i + 1 9 | end 10 | end 11 | return v 12 | -------------------------------------------------------------------------------- /test/0512/while-error2.lua: -------------------------------------------------------------------------------- 1 | --local i, cBits, cPos = 0, 0, 1 2 | local i, cBits, cPos 3 | while i < 30 do 4 | while cBits < 8 do 5 | cPos = cPos + 1 6 | end 7 | while cBits >= 8 do 8 | i = i + 1 9 | end 10 | end 11 | return v 12 | -------------------------------------------------------------------------------- /test/0512/while.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | 3 | while a > 0 do 4 | while b > 2 do 5 | c=c+1 --print(b) 6 | end 7 | while b <= 2 do 8 | c=c-1 --print(c) 9 | end 10 | end 11 | return a 12 | 13 | -------------------------------------------------------------------------------- /test/0512/while1-while1-error.lua: -------------------------------------------------------------------------------- 1 | local a, b, c = nil, nil, nil 2 | repeat 3 | repeat 4 | repeat 5 | print(a) 6 | until c > 0 7 | do break end 8 | until false 9 | c = a + b 10 | until false -------------------------------------------------------------------------------- /test/0512/while1-while1.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | while 1 do 3 | while 1 do 4 | print(a) 5 | if c > 0 then 6 | break 7 | end 8 | end 9 | c = a + b 10 | end -------------------------------------------------------------------------------- /test/0512/while2-error.lua: -------------------------------------------------------------------------------- 1 | local a, b, c 2 | 3 | repeat 4 | repeat 5 | print(a) 6 | until b > 0 7 | print(c) 8 | until a>0 9 | 10 | print(c) -------------------------------------------------------------------------------- /test/0512/while2.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | 3 | repeat 4 | print(a) 5 | if b > 0 then 6 | print(c) 7 | --break 8 | end 9 | until a>0 10 | 11 | print(c) -------------------------------------------------------------------------------- /test/0512/while3.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | 3 | while a > 0 and b > 0 do 4 | print(c) 5 | end 6 | -------------------------------------------------------------------------------- /test/0512/while4.lua: -------------------------------------------------------------------------------- 1 | local function a1() 2 | local a,b,c 3 | while 1 do 4 | print(a) 5 | if c > 0 then 6 | break 7 | end 8 | end 9 | end 10 | 11 | local function a2() 12 | local a,b,c 13 | while a > 0 do 14 | print(a) 15 | if c > 0 then 16 | break 17 | end 18 | end 19 | end -------------------------------------------------------------------------------- /test/0512/while5.lua: -------------------------------------------------------------------------------- 1 | local function a1() 2 | local a,b,c 3 | while 1 do 4 | repeat 5 | print(a) 6 | until c > 0 7 | do break end 8 | end 9 | end 10 | 11 | local function a2() 12 | local a,b,c 13 | while 1 do 14 | print(a) 15 | if c > 0 then 16 | break 17 | end 18 | end 19 | end 20 | 21 | local function a3() 22 | local a,b,c 23 | repeat 24 | print(a) 25 | until c > 0 26 | end -------------------------------------------------------------------------------- /test/0512/while6.lua: -------------------------------------------------------------------------------- 1 | local function a1() 2 | local a,b,c 3 | while 1 do 4 | repeat 5 | print(a) 6 | until c > 0 7 | print(b) 8 | end 9 | end -------------------------------------------------------------------------------- /test/20130707/_logic_leaks.lua: -------------------------------------------------------------------------------- 1 | local a,b,c,d,e,f,g 2 | local w,x,y,z 3 | 4 | --w = c or a == b --0 5 | 6 | --x = a == b and c --0 7 | 8 | y = a > b or c --2 9 | --[[ 10 | z = a < b and c and d --2 11 | 12 | w = a == b and c and d and e --2 13 | 14 | x = a == b and c and d or e --0 15 | --]] 16 | -------------------------------------------------------------------------------- /test/20130707/_nestif.lua: -------------------------------------------------------------------------------- 1 | local a,b 2 | 3 | if a >= 0 then 4 | if b >= 0 then 5 | b = 1 6 | else 7 | b = 2 8 | end 9 | end -------------------------------------------------------------------------------- /test/20130707/_repeat_repeat.lua: -------------------------------------------------------------------------------- 1 | local a,b,c; 2 | repeat 3 | repeat 4 | a = a+1 5 | until a > 4 6 | a=a+3 7 | until a > 5 -------------------------------------------------------------------------------- /test/20130707/_while.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | function f1() 3 | local a,b; 4 | --ok 5 | while a and b do 6 | f() 7 | end 8 | --[1] test 0 0 ; if R0 then to [3] 9 | --[2] jmp 5 ; to [8] 10 | --[3] test 1 0 ; if R1 then to [5] 11 | --[4] jmp 3 ; to [8] 12 | --[5] getglobal 2 0 ; R2 := f 13 | --[6] call 2 1 1 ; R2() 14 | --[7] jmp -7 ; to [1] 15 | --[8] return 0 1 ; return 16 | end 17 | --]] 18 | 19 | function f2() 20 | local a,b; 21 | --error 22 | while a do 23 | if b then 24 | f() 25 | end 26 | end 27 | --[1] test 0 0 ; if R0 then to [3] 28 | --[2] jmp 5 ; to [8] 29 | --[3] test 1 0 ; if R1 then to [5] 30 | --[4] jmp -4 ; to [1] 31 | --[5] getglobal 2 0 ; R2 := f 32 | --[6] call 2 1 1 ; R2() 33 | --[7] jmp -7 ; to [1] 34 | --[8] return 0 1 ; return 35 | end 36 | 37 | --[[ 38 | function f3() 39 | local a,b; 40 | --error 41 | while a do 42 | while b do 43 | f() 44 | end 45 | end 46 | --[1] test 0 0 ; if R0 then to [3] 47 | --[2] jmp 6 ; to [9] 48 | --[3] test 1 0 ; if R1 then to [5] 49 | --[4] jmp -4 ; to [1] 50 | --[5] getglobal 2 0 ; R2 := f 51 | --[6] call 2 1 1 ; R2() 52 | --[7] jmp -5 ; to [3] 53 | --[8] jmp -8 ; to [1] 54 | --[9] return 0 1 ; return 55 | end 56 | --]] -------------------------------------------------------------------------------- /test/20130707/_while_if.lua: -------------------------------------------------------------------------------- 1 | local a,b,c; 2 | while 1 do 3 | if(a) then 4 | b=3 5 | else 6 | --b=4 7 | break; 8 | end 9 | b=b+3 10 | end 11 | 12 | -- 0 [-]: TEST R0 0 ; if R0 then PC := 2 else PC := 6 13 | -- 1 [-]: JMP 6 ; PC := 6 14 | -- 2 [-]: LOADK R1 K0 ; R1 := 3 15 | -- 3 [-]: JMP 0 ; PC := 0 16 | -- 4 [-]: JMP 6 ; PC := 6 17 | -- 5 [-]: JMP 0 ; PC := 0 18 | -- 6 [-]: RETURN R0 1 ; return 19 | -------------------------------------------------------------------------------- /test/error_nested_if/doreturnend.lua: -------------------------------------------------------------------------------- 1 | if a then 2 | else 3 | if b then 4 | c=0 5 | end 6 | end 7 | --[[ 8 | -- Decompiled using luadec 2.2 GBK R5bf00c7 9 | if a then 10 | 11 | -- DECOMPILER ERROR: 2 unprocessed JMP targets 12 | end 13 | --]] 14 | -------------------------------------------------------------------------------- /test/error_nested_if/doreturnend2.lua: -------------------------------------------------------------------------------- 1 | local function x() 2 | if a then 3 | else 4 | if b then 5 | c=0 6 | end 7 | end 8 | end 9 | 10 | local function x() 11 | if not a then 12 | if b then 13 | c=0 14 | end 15 | end 16 | end -------------------------------------------------------------------------------- /test/error_nested_if/doreturnend3.lua: -------------------------------------------------------------------------------- 1 | local function x() 2 | if a then 3 | else 4 | if b then 5 | c=0 6 | end 7 | end 8 | print(a) 9 | end 10 | 11 | --[[ 12 | -- Decompiled using luadec 2.2 GBK R5bf00c7 13 | 14 | local x = function() 15 | if a then 16 | do return end 17 | end 18 | if b then 19 | c = 0 20 | end 21 | print(a) 22 | end 23 | ]]-- -------------------------------------------------------------------------------- /test/error_nested_if/if1.lua: -------------------------------------------------------------------------------- 1 | local a,b,c,d,e 2 | 3 | if a then 4 | if not b or c then 5 | e=102 6 | end 7 | else 8 | if d then 9 | e=102 10 | end 11 | end 12 | 13 | --[[ 14 | -- Decompiled using luadec 2.2 GBK R5bf00c7 15 | 16 | local a, b, c, d, e = nil 17 | if a and (not b or c) then 18 | e = 102 19 | end 20 | 21 | -- DECOMPILER ERROR: 2 unprocessed JMP targets 22 | ]]-- 23 | -------------------------------------------------------------------------------- /test/error_nested_if/if2.lua: -------------------------------------------------------------------------------- 1 | if a == b then 2 | print(a) 3 | if c then 4 | print(c) 5 | end 6 | else 7 | local hnd = d 8 | if hnd then 9 | print(d) 10 | end 11 | end -------------------------------------------------------------------------------- /test/error_nested_if/logic/if.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | local p1,p2,p3,p4 3 | 4 | --1001,error 5 | if a then 6 | if b then 7 | p1() 8 | end 9 | else 10 | p3() 11 | end 12 | 13 | --[[ 14 | -- Decompiled using luadec 2.2 GBK R5bf00c7 15 | 16 | local a, b, c, p1, p2, p3, p4 = nil 17 | if a and b then 18 | p1() 19 | end 20 | 21 | -- DECOMPILER ERROR: 2 unprocessed JMP targets 22 | --]] 23 | -------------------------------------------------------------------------------- /test/error_nested_if/logic/if2.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | local p1,p2,p3,p4 3 | 4 | --1100 5 | if a then 6 | if b then 7 | p1() 8 | else 9 | p2() 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /test/error_nested_if/logic/if_all.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | local p1,p2,p3,p4 3 | 4 | -- 0100 5 | if a then 6 | p1() 7 | end 8 | 9 | -- 1000 10 | if a then 11 | if b then 12 | p1() 13 | end 14 | end 15 | 16 | --1100 17 | if a then 18 | if b then 19 | p1() 20 | else 21 | p2() 22 | end 23 | end 24 | 25 | --1010, error 26 | if a then 27 | if b then 28 | p1() 29 | end 30 | else 31 | if c then 32 | p3() 33 | end 34 | end 35 | 36 | --0110 37 | if a then 38 | p1() 39 | else 40 | if c then 41 | p3() 42 | end 43 | end 44 | 45 | --1001,error 46 | if a then 47 | if b then 48 | p1() 49 | end 50 | else 51 | p3() 52 | end 53 | 54 | --0101 55 | if a then 56 | p1() 57 | else 58 | p3() 59 | end 60 | 61 | --1110 62 | if a then 63 | if b then 64 | p1() 65 | else 66 | p2() 67 | end 68 | else 69 | if c then 70 | p3() 71 | end 72 | end 73 | 74 | --1101 75 | if a then 76 | if b then 77 | p1() 78 | else 79 | p2() 80 | end 81 | else 82 | p3() 83 | end 84 | 85 | --1011,error 86 | if a then 87 | if b then 88 | p1() 89 | end 90 | else 91 | if c then 92 | p3() 93 | else 94 | p4() 95 | end 96 | end 97 | 98 | --0111 99 | if a then 100 | p1() 101 | else 102 | if c then 103 | p3() 104 | else 105 | p4() 106 | end 107 | end 108 | 109 | --1111 110 | if a then 111 | if b then 112 | p1() 113 | else 114 | p2() 115 | end 116 | else 117 | if c then 118 | p3() 119 | else 120 | p4() 121 | end 122 | end -------------------------------------------------------------------------------- /test/error_nested_if/logic/if_error.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | local p1,p2,p3,p4 3 | 4 | --1010, error 5 | if a then 6 | if b then 7 | p1() 8 | end 9 | else 10 | if c then 11 | p3() 12 | end 13 | end 14 | 15 | --1001,error 16 | if a then 17 | if b then 18 | p1() 19 | end 20 | else 21 | p3() 22 | end 23 | 24 | --1011,error 25 | if a then 26 | if b then 27 | p1() 28 | end 29 | else 30 | if c then 31 | p3() 32 | else 33 | p4() 34 | end 35 | end -------------------------------------------------------------------------------- /test/error_nested_if/logic/logic.lua: -------------------------------------------------------------------------------- 1 | --local a=true 2 | --local b="a" 3 | --local c= b and 0 or 3 4 | local d= (b and a) or ((not c) and ( a or not b)) 5 | --print(b) 6 | 7 | --[[ 8 | -- Decompiled using luadec 2.2 GBK R5bf00c7 9 | 10 | local a = true 11 | local b = "a" 12 | local c = b and 0 or 3 13 | -- DECOMPILER ERROR: unhandled construct in 'MakeBoolean' 14 | 15 | -- DECOMPILER ERROR: unhandled construct in 'MakeBoolean' 16 | 17 | do 18 | local d = (not b or not a) and c 19 | -- DECOMPILER ERROR: 2 unprocessed JMP targets 20 | end 21 | --]] -------------------------------------------------------------------------------- /test/issues/issue13_direct_call.lua: -------------------------------------------------------------------------------- 1 | ( 2 | function() 3 | print("abc") 4 | end 5 | )() 6 | ;-- must output this 7 | ( 8 | function(a) 9 | print(type(a)) 10 | end 11 | )(function() 12 | print("abe") 13 | end) 14 | 15 | 16 | -- may not decompile 17 | local a = (function() print(1) end)+1 18 | 19 | ((function() print(1) end)+(function() print(2) end))() 20 | ; 21 | (1+(function() print(1) end)+2)() 22 | ; 23 | 24 | local b=f; 25 | ((function() print(1) end)+(function() print(2) end))() 26 | -------------------------------------------------------------------------------- /test/issues/issue15_fn_upvalue.lua: -------------------------------------------------------------------------------- 1 | local a, b 2 | 3 | function f() 4 | a,b=nil 5 | return false 6 | end; 7 | -------------------------------------------------------------------------------- /test/issues/issue17_self_call.lua: -------------------------------------------------------------------------------- 1 | -- OP_GETTABLE MakeIndex( DOT ) 2 | local x = (1+a).f4 3 | x = ({0,1}).a 4 | x = ({2,3,4}+5)[6] 5 | 6 | -- OP_SETTABLE MakeIndex( DOT ) 7 | ;(1+a).f3 = x 8 | --;({0,1}).a = x 9 | ;({2,3,4}+5)[6] = x 10 | 11 | -- OP_CALL 12 | _a22_2_a() 13 | a() 14 | a.f3() 15 | ;(1+a)(s) 16 | ;(function(f) print(type(f)) end)(3) 17 | 18 | --OP_SELF MakeIndex( SELF ) 19 | a:f() 20 | a:f3() 21 | ;(2+a):f3() 22 | -------------------------------------------------------------------------------- /test/issues/issue22_exp_settable.lua: -------------------------------------------------------------------------------- 1 | -- OP_SETTABLE MakeIndex( DOT ) 2 | -- DECOMPILER ERROR: Confused about usage of registers! 3 | (1+a).f3 = x 4 | -- DECOMPILER ERROR: Confused about usage of registers! 5 | ;({2,3,4}+5)[6] =x 6 | -- DECOMPILER ERROR: Overwrote pending register. 7 | ;({0,1}).a = x 8 | local y =4 -- need to output last statement with error 9 | -- local y = {0, 1; a = x} 10 | -------------------------------------------------------------------------------- /test/issues/issue23_cannot_jmp_out_else.lua: -------------------------------------------------------------------------------- 1 | local a,b,c,f 2 | 3 | function ok1() 4 | local a,b,c,f 5 | --ok 6 | if b==1 then 7 | c = 11 8 | elseif b==2 then 9 | c = 12 10 | else 11 | c = 13 12 | end 13 | print(f) 14 | if b==4 then 15 | c = 14 16 | end 17 | end 18 | 19 | function error1() 20 | local a,b,c,f 21 | --ok 22 | if b==1 then 23 | c = 11 24 | elseif b==2 then 25 | c = 12 26 | else 27 | c = 13 28 | end 29 | --print(f) 30 | if b==4 then 31 | c = 14 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /test/issues/issue24_while_if.lua: -------------------------------------------------------------------------------- 1 | local a,b; 2 | 3 | while a and b do 4 | f() 5 | end 6 | 7 | while a do 8 | if b then 9 | f() 10 | end 11 | end 12 | 13 | while a do 14 | while b do 15 | f() 16 | end 17 | end -------------------------------------------------------------------------------- /test/issues/issue27_and_or_or.lua: -------------------------------------------------------------------------------- 1 | -- Command line: -fc -fn 0_10 E:\cbprojects\luadec\angrybirds_lua\scripts\menus\level_end.lua 2 | 3 | Decompiled_0_10 = function (p) 4 | local a,b,c,d 5 | if ((a and b) or c or d) then 6 | p = 3 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/issues/issue28_lt_le_const.lua: -------------------------------------------------------------------------------- 1 | function lt_const(a,b,c) 2 | b = a>3 3 | b = 3=a) 6 | end 7 | 8 | function lt_if(a,b,c) 9 | if a>3 then 10 | b() 11 | end 12 | if not (a<=3) then 13 | c() 14 | end 15 | end 16 | 17 | function eq_const(a,b,c) 18 | b = a==3 19 | b = 3==a 20 | end 21 | 22 | function lt_function(a,b,c) 23 | a = b()>c() 24 | a = c()=b()) 27 | end 28 | -------------------------------------------------------------------------------- /test/issues/issue29_vararg.lua: -------------------------------------------------------------------------------- 1 | -- 5.1 main always is_vararg=2 2 | -- 5.2 main always is_vararg=1 3 | local a; 4 | 5 | (function() 6 | -- 5.2 don't has arg 7 | for k,v in ipairs(_G.arg) do 8 | print(v) 9 | end 10 | end)() 11 | 12 | for k,v in ipairs({...}) do 13 | print(v) 14 | end 15 | 16 | -- 5.2 don't has arg 17 | for k,v in ipairs(arg) do 18 | print(v) 19 | end 20 | 21 | -- is_vararg=0 22 | function f0() 23 | local x=arg 24 | end 25 | 26 | -- 5.1 is_vararg=7 27 | -- 5.2 is_vararg=1 28 | function f1(...) 29 | local x=arg 30 | end 31 | 32 | -- 5.1 is_vararg=3, not use arg, but put arg as param 33 | -- 5.2 is_vararg=1 34 | function f2(...) 35 | local x=... 36 | end 37 | 38 | -- 5.1 is_vararg=3 39 | -- 5.2 is_vararg=1 40 | function f3(...) 41 | local x=arg 42 | local y=... 43 | end 44 | 45 | -- 5.1 is_vararg=3 46 | -- 5.2 is_vararg=1 47 | function f4(x, ...) 48 | local x=arg 49 | local y=... 50 | end 51 | -------------------------------------------------------------------------------- /test/issues/issue30_local_reuse.lua: -------------------------------------------------------------------------------- 1 | for i = 1, 10 do 2 | local a,b,c,d = i,i+1,i+2; 3 | print(a); 4 | end 5 | local c=... 6 | local b,a=3,4; 7 | print(a) 8 | 9 | for i = 1, 10 do 10 | local x,y,z 11 | f[i] = function() x=x+1; print(y); z=i; end 12 | end 13 | 14 | do 15 | local a1 = 0 16 | print(a1) 17 | end 18 | local b1 = 1 19 | 20 | local t = {a,b,c} 21 | -------------------------------------------------------------------------------- /test/issues/issue32_global_or_to_if.lua: -------------------------------------------------------------------------------- 1 | function a0 (b) 2 | c = c or {} 3 | return b 4 | end 5 | 6 | function a1 (b) 7 | if not c then 8 | c = {} 9 | end 10 | return b 11 | end -------------------------------------------------------------------------------- /test/issues/issue33_if_if.lua: -------------------------------------------------------------------------------- 1 | local a,b,c,d,e 2 | 3 | if a then 4 | b() 5 | if c then 6 | d() 7 | end 8 | end 9 | e() 10 | -------------------------------------------------------------------------------- /test/issues/issue42_function_local_scope.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | 3 | do 4 | local x = 3 5 | end 6 | 7 | do 8 | local x 9 | x = a(b) + c 10 | end 11 | 12 | do 13 | local x = a(b) + c 14 | end 15 | 16 | do 17 | local x 18 | x = a(b) + c 19 | function z() 20 | return x 21 | end 22 | end 23 | 24 | function z(a1,a2) 25 | local a3 26 | a3 = 4 + 5 27 | end 28 | 29 | function z2(a1,a2) 30 | local a3 = 3 31 | end 32 | 33 | function z3(a1,a2) 34 | local a3 = 3 35 | return a3 36 | end 37 | 38 | function z4(a1,a2) 39 | local a3 40 | do 41 | local a4 42 | end 43 | return a1 44 | end 45 | 46 | function z5(a1,a2) 47 | local a3 48 | do 49 | local a4 50 | a3 = a4 51 | end 52 | return a1 53 | end -------------------------------------------------------------------------------- /test/issues/issue42_local_scope.lua: -------------------------------------------------------------------------------- 1 | 2 | do 3 | local function x() 4 | return x 5 | end 6 | do 7 | local function y() 8 | return y 9 | end 10 | end 11 | end 12 | 13 | do 14 | local x = 3 15 | do 16 | local y = 4 17 | end 18 | end 19 | 20 | local test 21 | 22 | if test then 23 | local function z() return test,z; end 24 | -- insert jmp for close 25 | end 26 | 27 | if test then 28 | local function z() return test,z; end 29 | -- insert jmp for close 30 | else -- this jmp is still here, but will be skipped when excuting 31 | local function z() return test,z; end 32 | -- insert jmp for close 33 | end 34 | 35 | repeat 36 | local z = 2 37 | until test and z 38 | 39 | repeat 40 | local function z() return test,z; end 41 | until test and z 42 | -- generate 2 close/jmp for 5.1 43 | 44 | repeat 45 | local function z() return z; end 46 | until false 47 | -- generate 2 close/jmp for 5.1 48 | 49 | repeat 50 | local z = 3 51 | until true -- generate nothing 52 | 53 | repeat 54 | local function z() return z; end 55 | until true 56 | -- generate 2 close/jmp for 5.1 57 | 58 | while test do 59 | local function z() return test,z; end 60 | -- generate close here 61 | end 62 | 63 | while true do 64 | local function z() return z; end 65 | -- generate close here 66 | end 67 | 68 | -- 3 scopes 69 | -- (for generator), (for state), (for control) 70 | -- i 71 | -- z 72 | for i = 1,4 do 73 | local function z() return i,z; end 74 | -- generate 2 close here, the first for z, the second for i 75 | end 76 | 77 | -- 3 scopes 78 | -- (for generator), (for state), (for control) 79 | -- k,v 80 | -- z 81 | for k,v in ipairs(gt) do 82 | local function z() return k,z; end 83 | -- generate 2 close here, the first for z, the second for i 84 | end 85 | 86 | return 3 -------------------------------------------------------------------------------- /test/issues/issue43_local_func_as_upval.lua: -------------------------------------------------------------------------------- 1 | do 2 | local z=function() return 1 end 3 | end 4 | 5 | do 6 | local function z() return 1 end 7 | end 8 | 9 | do 10 | local z=function() return z end 11 | end 12 | 13 | do 14 | local function z() return z end 15 | end 16 | -------------------------------------------------------------------------------- /test/issues/issue4_jmp_loadbool.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/issues/issue4_jmp_loadbool.lua -------------------------------------------------------------------------------- /test/issues/issue4_jmp_loadbool_all.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/issues/issue4_jmp_loadbool_all.lua -------------------------------------------------------------------------------- /test/loop_structure/4while1.lua: -------------------------------------------------------------------------------- 1 | local a,b,c,d,e,f,g 2 | 3 | while 1 do 4 | a() 5 | 6 | while 1 do 7 | b() 8 | end 9 | 10 | f() 11 | 12 | while 1 do 13 | c() 14 | while 1 do 15 | d() 16 | end 17 | e() 18 | end 19 | 20 | g() 21 | end -------------------------------------------------------------------------------- /test/loop_structure/complex_while.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | while (a > 0 or b>0) and c>0 do 3 | print(a) 4 | if a+b > 0 then 5 | break 6 | end 7 | print(b) 8 | end 9 | -------------------------------------------------------------------------------- /test/loop_structure/complex_while2.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | while (a > 0 or b>0) and c>0 do 3 | print(a) 4 | break; 5 | end -------------------------------------------------------------------------------- /test/loop_structure/for.lua: -------------------------------------------------------------------------------- 1 | for i = 1, 10 do 2 | print(i) 3 | end 4 | -------------------------------------------------------------------------------- /test/loop_structure/repeat-for.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | repeat 3 | for i = 1, 10 do 4 | print(i) 5 | end 6 | until a>0 -------------------------------------------------------------------------------- /test/loop_structure/repeat-while.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | 3 | repeat 4 | while (a > 0 or b>0) and c>0 do 5 | if a+b>0 then 6 | break; 7 | end 8 | end 9 | until a>0 -------------------------------------------------------------------------------- /test/loop_structure/repeat.lua: -------------------------------------------------------------------------------- 1 | local a 2 | repeat 3 | print(a) 4 | until a > 0 -------------------------------------------------------------------------------- /test/loop_structure/tfor.lua: -------------------------------------------------------------------------------- 1 | for k,v in pairs(a) do 2 | print(k,v) 3 | end 4 | -------------------------------------------------------------------------------- /test/loop_structure/until1.lua: -------------------------------------------------------------------------------- 1 | local a 2 | repeat 3 | a() 4 | until false 5 | -------------------------------------------------------------------------------- /test/loop_structure/while-while.lua: -------------------------------------------------------------------------------- 1 | local a, b 2 | while a > 0 do 3 | print(a) 4 | while b > 0 do 5 | print(b) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/loop_structure/while.lua: -------------------------------------------------------------------------------- 1 | local a 2 | while a > 0 do 3 | print(a) 4 | end 5 | -------------------------------------------------------------------------------- /test/loop_structure/while1-if.lua: -------------------------------------------------------------------------------- 1 | local a,b,c,f 2 | 3 | while 1 do 4 | f(b) 5 | if c then 6 | f(a) 7 | end 8 | end -------------------------------------------------------------------------------- /test/loop_structure/while1-until.lua: -------------------------------------------------------------------------------- 1 | local a,b,c,f 2 | 3 | while 1 do 4 | repeat 5 | f(b) 6 | until c 7 | f(a) 8 | end -------------------------------------------------------------------------------- /test/loop_structure/while1-while1.lua: -------------------------------------------------------------------------------- 1 | local a,b,c,f 2 | 3 | while 1 do 4 | f(a) 5 | end 6 | 7 | while 1 do 8 | f(b) 9 | end -------------------------------------------------------------------------------- /test/loop_structure/while1.lua: -------------------------------------------------------------------------------- 1 | local a 2 | while 1 do 3 | a() 4 | end -------------------------------------------------------------------------------- /test/lua-5.1-test/README: -------------------------------------------------------------------------------- 1 | These are simple tests for Lua. Some of them contain useful code. 2 | They are meant to be run to make sure Lua is built correctly and also 3 | to be read, to see how Lua programs look. 4 | 5 | Here is a one-line summary of each program: 6 | 7 | bisect.lua bisection method for solving non-linear equations 8 | cf.lua temperature conversion table (celsius to farenheit) 9 | echo.lua echo command line arguments 10 | env.lua environment variables as automatic global variables 11 | factorial.lua factorial without recursion 12 | fib.lua fibonacci function with cache 13 | fibfor.lua fibonacci numbers with coroutines and generators 14 | globals.lua report global variable usage 15 | hello.lua the first program in every language 16 | life.lua Conway's Game of Life 17 | luac.lua bare-bones luac 18 | printf.lua an implementation of printf 19 | readonly.lua make global variables readonly 20 | sieve.lua the sieve of of Eratosthenes programmed with coroutines 21 | sort.lua two implementations of a sort function 22 | table.lua make table, grouping all data for the same item 23 | trace-calls.lua trace calls 24 | trace-globals.lua trace assigments to global variables 25 | xd.lua hex dump 26 | 27 | -------------------------------------------------------------------------------- /test/lua-5.1-test/bisect.lua: -------------------------------------------------------------------------------- 1 | -- bisection method for solving non-linear equations 2 | 3 | delta=1e-6 -- tolerance 4 | 5 | function bisect(f,a,b,fa,fb) 6 | local c=(a+b)/2 7 | io.write(n," c=",c," a=",a," b=",b,"\n") 8 | if c==a or c==b or math.abs(a-b)y end) 58 | show("after reverse selection sort",x) 59 | qsort(x,1,n,function (x,y) return x>> ",string.rep(" ",level)) 9 | if t~=nil and t.currentline>=0 then io.write(t.short_src,":",t.currentline," ") end 10 | t=debug.getinfo(2) 11 | if event=="call" then 12 | level=level+1 13 | else 14 | level=level-1 if level<0 then level=0 end 15 | end 16 | if t.what=="main" then 17 | if event=="call" then 18 | io.write("begin ",t.short_src) 19 | else 20 | io.write("end ",t.short_src) 21 | end 22 | elseif t.what=="Lua" then 23 | -- table.foreach(t,print) 24 | io.write(event," ",t.name or "(Lua)"," <",t.linedefined,":",t.short_src,">") 25 | else 26 | io.write(event," ",t.name or "(C)"," [",t.what,"] ") 27 | end 28 | io.write("\n") 29 | end 30 | 31 | debug.sethook(hook,"cr") 32 | level=0 33 | -------------------------------------------------------------------------------- /test/lua-5.1-test/trace-globals.lua: -------------------------------------------------------------------------------- 1 | -- trace assigments to global variables 2 | 3 | do 4 | -- a tostring that quotes strings. note the use of the original tostring. 5 | local _tostring=tostring 6 | local tostring=function(a) 7 | if type(a)=="string" then 8 | return string.format("%q",a) 9 | else 10 | return _tostring(a) 11 | end 12 | end 13 | 14 | local log=function (name,old,new) 15 | local t=debug.getinfo(3,"Sl") 16 | local line=t.currentline 17 | io.write(t.short_src) 18 | if line>=0 then io.write(":",line) end 19 | io.write(": ",name," is now ",tostring(new)," (was ",tostring(old),")","\n") 20 | end 21 | 22 | local g={} 23 | local set=function (t,name,value) 24 | log(name,g[name],value) 25 | g[name]=value 26 | end 27 | setmetatable(getfenv(),{__index=g,__newindex=set}) 28 | end 29 | 30 | -- an example 31 | 32 | a=1 33 | b=2 34 | a=10 35 | b=20 36 | b=nil 37 | b=200 38 | print(a,b,c) 39 | -------------------------------------------------------------------------------- /test/lua-5.1-test/xd.lua: -------------------------------------------------------------------------------- 1 | -- hex dump 2 | -- usage: lua xd.lua < file 3 | 4 | local offset=0 5 | while true do 6 | local s=io.read(16) 7 | if s==nil then return end 8 | io.write(string.format("%08X ",offset)) 9 | string.gsub(s,"(.)", 10 | function (c) io.write(string.format("%02X ",string.byte(c))) end) 11 | io.write(string.rep(" ",3*(16-string.len(s)))) 12 | io.write(" ",string.gsub(s,"%c","."),"\n") 13 | offset=offset+16 14 | end 15 | -------------------------------------------------------------------------------- /test/lua-5.1-tests/README: -------------------------------------------------------------------------------- 1 | This tarball contains the official test scripts for Lua 5.1. 2 | Unlike Lua itself, these tests do not aim portability, small footprint, 3 | or easy of use. (Their main goal is to try to crash Lua.) They are not 4 | intended for general use. You are wellcome to use them, but expect to 5 | have to "dirt your hands". 6 | 7 | The tarball should expand in the following contents: 8 | - several .lua scripts with the tests 9 | - a main "all.lua" Lua script that invokes all the other scripts 10 | - a subdirectory "libs" with an empty subdirectory "libs/P1", 11 | to be used by the scripts 12 | - a subdirectory "etc" with some extra files 13 | 14 | To run the tests, do as follows: 15 | 16 | - go to the test directory 17 | 18 | - set LUA_PATH to "?;./?.lua" (or, better yet, set LUA_PATH to "./?.lua;;" 19 | and LUA_INIT to "package.path = '?;'..package.path") 20 | 21 | - run "lua all.lua" 22 | 23 | 24 | -------------------------------------------- 25 | Internal tests 26 | -------------------------------------------- 27 | 28 | Some tests need a special library, "testC", that gives access to 29 | several internal structures in Lua. 30 | This library is only available when Lua is compiled in debug mode. 31 | The scripts automatically detect its absence and skip those tests. 32 | 33 | If you want to run these tests, move etc/ltests.c and etc/ltests.h to 34 | the directory with the source Lua files, and recompile Lua with 35 | the option -DLUA_USER_H='"ltests.h"' (or its equivalent to define 36 | LUA_USER_H as the string "ltests.h", including the quotes). This 37 | option not only adds the testC library, but it adds several other 38 | internal tests as well. After the recompilation, run the tests 39 | as before. 40 | 41 | 42 | -------------------------------------------------------------------------------- /test/lua-5.1-tests/all.lua: -------------------------------------------------------------------------------- 1 | #!../lua 2 | 3 | math.randomseed(0) 4 | 5 | collectgarbage("setstepmul", 180) 6 | collectgarbage("setpause", 190) 7 | 8 | 9 | --[=[ 10 | example of a long [comment], 11 | [[spanning several [lines]]] 12 | 13 | ]=] 14 | 15 | print("current path:\n " .. string.gsub(package.path, ";", "\n ")) 16 | 17 | 18 | local msgs = {} 19 | function Message (m) 20 | print(m) 21 | msgs[#msgs+1] = string.sub(m, 3, -3) 22 | end 23 | 24 | 25 | local c = os.clock() 26 | 27 | assert(os.setlocale"C") 28 | 29 | local T,print,gcinfo,format,write,assert,type = 30 | T,print,gcinfo,string.format,io.write,assert,type 31 | 32 | local function formatmem (m) 33 | if m < 1024 then return m 34 | else 35 | m = m/1024 - m/1024%1 36 | if m < 1024 then return m.."K" 37 | else 38 | m = m/1024 - m/1024%1 39 | return m.."M" 40 | end 41 | end 42 | end 43 | 44 | local showmem = function () 45 | if not T then 46 | print(format(" ---- total memory: %s ----\n", formatmem(gcinfo()))) 47 | else 48 | T.checkmemory() 49 | local a,b,c = T.totalmem() 50 | local d,e = gcinfo() 51 | print(format( 52 | "\n ---- total memory: %s (%dK), max use: %s, blocks: %d\n", 53 | formatmem(a), d, formatmem(c), b)) 54 | end 55 | end 56 | 57 | 58 | -- 59 | -- redefine dofile to run files through dump/undump 60 | -- 61 | dofile = function (n) 62 | showmem() 63 | local f = assert(loadfile(n)) 64 | local b = string.dump(f) 65 | f = assert(loadstring(b)) 66 | return f() 67 | end 68 | 69 | dofile('main.lua') 70 | 71 | do 72 | local u = newproxy(true) 73 | local newproxy, stderr = newproxy, io.stderr 74 | getmetatable(u).__gc = function (o) 75 | stderr:write'.' 76 | newproxy(o) 77 | end 78 | end 79 | 80 | local f = assert(loadfile('gc.lua')) 81 | f() 82 | dofile('db.lua') 83 | assert(dofile('calls.lua') == deep and deep) 84 | dofile('strings.lua') 85 | dofile('literals.lua') 86 | assert(dofile('attrib.lua') == 27) 87 | assert(dofile('locals.lua') == 5) 88 | dofile('constructs.lua') 89 | dofile('code.lua') 90 | do 91 | local f = coroutine.wrap(assert(loadfile('big.lua'))) 92 | assert(f() == 'b') 93 | assert(f() == 'a') 94 | end 95 | dofile('nextvar.lua') 96 | dofile('pm.lua') 97 | dofile('api.lua') 98 | assert(dofile('events.lua') == 12) 99 | dofile('vararg.lua') 100 | dofile('closure.lua') 101 | dofile('errors.lua') 102 | dofile('math.lua') 103 | dofile('sort.lua') 104 | assert(dofile('verybig.lua') == 10); collectgarbage() 105 | dofile('files.lua') 106 | 107 | if #msgs > 0 then 108 | print("\ntests not performed:") 109 | for i=1,#msgs do 110 | print(msgs[i]) 111 | end 112 | print() 113 | end 114 | 115 | print("final OK !!!") 116 | print('cleaning all!!!!') 117 | 118 | debug.sethook(function (a) assert(type(a) == 'string') end, "cr") 119 | 120 | local _G, collectgarbage, showmem, print, format, clock = 121 | _G, collectgarbage, showmem, print, format, os.clock 122 | 123 | local a={} 124 | for n in pairs(_G) do a[n] = 1 end 125 | a.tostring = nil 126 | a.___Glob = nil 127 | for n in pairs(a) do _G[n] = nil end 128 | 129 | a = nil 130 | collectgarbage() 131 | collectgarbage() 132 | collectgarbage() 133 | collectgarbage() 134 | collectgarbage() 135 | collectgarbage();showmem() 136 | 137 | print(format("\n\ntotal time: %.2f\n", clock()-c)) 138 | -------------------------------------------------------------------------------- /test/lua-5.1-tests/checktable.lua: -------------------------------------------------------------------------------- 1 | 2 | assert(rawget(_G, "stat") == nil) -- module not loaded before 3 | 4 | if T == nil then 5 | stat = function () print"`querytab' nao ativo" end 6 | return 7 | end 8 | 9 | 10 | function checktable (t) 11 | local asize, hsize, ff = T.querytab(t) 12 | local l = {} 13 | for i=0,hsize-1 do 14 | local key,val,next = T.querytab(t, i + asize) 15 | if key == nil then 16 | assert(l[i] == nil and val==nil and next==nil) 17 | elseif key == "" then 18 | assert(val==nil) 19 | else 20 | assert(t[key] == val) 21 | local mp = T.hash(key, t) 22 | if l[i] then 23 | assert(l[i] == mp) 24 | elseif mp ~= i then 25 | l[i] = mp 26 | else -- list head 27 | l[mp] = {mp} -- first element 28 | while next do 29 | assert(ff <= next and next < hsize) 30 | if l[next] then assert(l[next] == mp) else l[next] = mp end 31 | table.insert(l[mp], next) 32 | key,val,next = T.querytab(t, next) 33 | assert(key) 34 | end 35 | end 36 | end 37 | end 38 | l.asize = asize; l.hsize = hsize; l.ff = ff 39 | return l 40 | end 41 | 42 | function mostra (t) 43 | local asize, hsize, ff = T.querytab(t) 44 | print(asize, hsize, ff) 45 | print'------' 46 | for i=0,asize-1 do 47 | local _, v = T.querytab(t, i) 48 | print(string.format("[%d] -", i), v) 49 | end 50 | print'------' 51 | for i=0,hsize-1 do 52 | print(i, T.querytab(t, i+asize)) 53 | end 54 | print'-------------' 55 | end 56 | 57 | function stat (t) 58 | t = checktable(t) 59 | local nelem, nlist = 0, 0 60 | local maxlist = {} 61 | for i=0,t.hsize-1 do 62 | if type(t[i]) == 'table' then 63 | local n = table.getn(t[i]) 64 | nlist = nlist+1 65 | nelem = nelem + n 66 | if not maxlist[n] then maxlist[n] = 0 end 67 | maxlist[n] = maxlist[n]+1 68 | end 69 | end 70 | print(string.format("hsize=%d elements=%d load=%.2f med.len=%.2f (asize=%d)", 71 | t.hsize, nelem, nelem/t.hsize, nelem/nlist, t.asize)) 72 | for i=1,table.getn(maxlist) do 73 | local n = maxlist[i] or 0 74 | print(string.format("%5d %10d %.2f%%", i, n, n*100/nlist)) 75 | end 76 | end 77 | 78 | -------------------------------------------------------------------------------- /test/lua-5.1-tests/code.lua: -------------------------------------------------------------------------------- 1 | 2 | if T==nil then 3 | (Message or print)('\a\n >>> testC not active: skipping opcode tests <<<\n\a') 4 | return 5 | end 6 | print "testing code generation and optimizations" 7 | 8 | 9 | -- this code gave an error for the code checker 10 | do 11 | local function f (a) 12 | for k,v,w in a do end 13 | end 14 | end 15 | 16 | 17 | function check (f, ...) 18 | local c = T.listcode(f) 19 | for i=1, arg.n do 20 | -- print(arg[i], c[i]) 21 | assert(string.find(c[i], '- '..arg[i]..' *%d')) 22 | end 23 | assert(c[arg.n+2] == nil) 24 | end 25 | 26 | 27 | function checkequal (a, b) 28 | a = T.listcode(a) 29 | b = T.listcode(b) 30 | for i = 1, table.getn(a) do 31 | a[i] = string.gsub(a[i], '%b()', '') -- remove line number 32 | b[i] = string.gsub(b[i], '%b()', '') -- remove line number 33 | assert(a[i] == b[i]) 34 | end 35 | end 36 | 37 | 38 | -- some basic instructions 39 | check(function () 40 | (function () end){f()} 41 | end, 'CLOSURE', 'NEWTABLE', 'GETGLOBAL', 'CALL', 'SETLIST', 'CALL', 'RETURN') 42 | 43 | 44 | -- sequence of LOADNILs 45 | check(function () 46 | local a,b,c 47 | local d; local e; 48 | a = nil; d=nil 49 | end, 'RETURN') 50 | 51 | 52 | -- single return 53 | check (function (a,b,c) return a end, 'RETURN') 54 | 55 | 56 | -- infinite loops 57 | check(function () while true do local a = -1 end end, 58 | 'LOADK', 'JMP', 'RETURN') 59 | 60 | check(function () while 1 do local a = -1 end end, 61 | 'LOADK', 'JMP', 'RETURN') 62 | 63 | check(function () repeat local x = 1 until false end, 64 | 'LOADK', 'JMP', 'RETURN') 65 | 66 | check(function () repeat local x until nil end, 67 | 'LOADNIL', 'JMP', 'RETURN') 68 | 69 | check(function () repeat local x = 1 until true end, 70 | 'LOADK', 'RETURN') 71 | 72 | 73 | -- concat optimization 74 | check(function (a,b,c,d) return a..b..c..d end, 75 | 'MOVE', 'MOVE', 'MOVE', 'MOVE', 'CONCAT', 'RETURN') 76 | 77 | -- not 78 | check(function () return not not nil end, 'LOADBOOL', 'RETURN') 79 | check(function () return not not false end, 'LOADBOOL', 'RETURN') 80 | check(function () return not not true end, 'LOADBOOL', 'RETURN') 81 | check(function () return not not 1 end, 'LOADBOOL', 'RETURN') 82 | 83 | -- direct access to locals 84 | check(function () 85 | local a,b,c,d 86 | a = b*2 87 | c[4], a[b] = -((a + d/-20.5 - a[b]) ^ a.x), b 88 | end, 89 | 'MUL', 90 | 'DIV', 'ADD', 'GETTABLE', 'SUB', 'GETTABLE', 'POW', 91 | 'UNM', 'SETTABLE', 'SETTABLE', 'RETURN') 92 | 93 | 94 | -- direct access to constants 95 | check(function () 96 | local a,b 97 | a.x = 0 98 | a.x = b 99 | a[b] = 'y' 100 | a = 1 - a 101 | b = 1/a 102 | b = 5+4 103 | a[true] = false 104 | end, 105 | 'SETTABLE', 'SETTABLE', 'SETTABLE', 'SUB', 'DIV', 'LOADK', 106 | 'SETTABLE', 'RETURN') 107 | 108 | local function f () return -((2^8 + -(-1)) % 8)/2 * 4 - 3 end 109 | 110 | check(f, 'LOADK', 'RETURN') 111 | assert(f() == -5) 112 | 113 | check(function () 114 | local a,b,c 115 | b[c], a = c, b 116 | b[a], a = c, b 117 | a, b = c, a 118 | a = a 119 | end, 120 | 'MOVE', 'MOVE', 'SETTABLE', 121 | 'MOVE', 'MOVE', 'MOVE', 'SETTABLE', 122 | 'MOVE', 'MOVE', 'MOVE', 123 | -- no code for a = a 124 | 'RETURN') 125 | 126 | 127 | -- x == nil , x ~= nil 128 | checkequal(function () if (a==nil) then a=1 end; if a~=nil then a=1 end end, 129 | function () if (a==9) then a=1 end; if a~=9 then a=1 end end) 130 | 131 | check(function () if a==nil then a=1 end end, 132 | 'GETGLOBAL', 'EQ', 'JMP', 'LOADK', 'SETGLOBAL', 'RETURN') 133 | 134 | -- de morgan 135 | checkequal(function () local a; if not (a or b) then b=a end end, 136 | function () local a; if (not a and not b) then b=a end end) 137 | 138 | checkequal(function (l) local a; return 0 <= a and a <= l end, 139 | function (l) local a; return not (not(a >= 0) or not(a <= l)) end) 140 | 141 | 142 | print 'OK' 143 | 144 | -------------------------------------------------------------------------------- /test/lua-5.1-tests/db.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.1-tests/db.lua -------------------------------------------------------------------------------- /test/lua-5.1-tests/etc/ltests.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltests.h,v 2.17 2005/12/27 17:12:00 roberto Exp $ 3 | ** Internal Header for Debugging of the Lua Implementation 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltests_h 8 | #define ltests_h 9 | 10 | 11 | #include 12 | 13 | 14 | #define LUA_DEBUG 15 | 16 | #undef NDEBUG 17 | #include 18 | #define lua_assert(c) assert(c) 19 | 20 | 21 | /* to avoid warnings, and to make sure value is really unused */ 22 | #define UNUSED(x) (x=0, (void)(x)) 23 | 24 | 25 | /* memory allocator control variables */ 26 | typedef struct Memcontrol { 27 | unsigned long numblocks; 28 | unsigned long total; 29 | unsigned long maxmem; 30 | unsigned long memlimit; 31 | } Memcontrol; 32 | 33 | LUAI_DATA Memcontrol memcontrol; 34 | 35 | 36 | /* 37 | ** generic variable for debug tricks 38 | */ 39 | LUAI_DATA int Trick; 40 | 41 | 42 | void *debug_realloc (void *ud, void *block, size_t osize, size_t nsize); 43 | 44 | #ifdef lua_c 45 | #define luaL_newstate() lua_newstate(debug_realloc, &memcontrol) 46 | #endif 47 | 48 | 49 | typedef struct CallInfo *pCallInfo; 50 | 51 | int lua_checkmemory (lua_State *L); 52 | int lua_checkpc (lua_State *L, pCallInfo ci); 53 | 54 | 55 | /* test for lock/unlock */ 56 | #undef luai_userstateopen 57 | #undef luai_userstatethread 58 | #undef lua_lock 59 | #undef lua_unlock 60 | #undef LUAI_EXTRASPACE 61 | 62 | struct L_EXTRA { int lock; int *plock; }; 63 | #define LUAI_EXTRASPACE sizeof(struct L_EXTRA) 64 | #define getlock(l) (cast(struct L_EXTRA *, l) - 1) 65 | #define luai_userstateopen(l) \ 66 | (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock)) 67 | #define luai_userstatethread(l,l1) (getlock(l1)->plock = getlock(l)->plock) 68 | #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0) 69 | #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0) 70 | 71 | 72 | int luaB_opentests (lua_State *L); 73 | 74 | #ifdef lua_c 75 | #define luaL_openlibs(L) { (luaL_openlibs)(L); luaB_opentests(L); } 76 | #endif 77 | 78 | 79 | 80 | /* real main will be defined at `ltests.c' */ 81 | int l_main (int argc, char *argv[]); 82 | #define main l_main 83 | 84 | 85 | 86 | /* change some sizes to give some bugs a chance */ 87 | 88 | #undef LUAL_BUFFERSIZE 89 | #define LUAL_BUFFERSIZE 27 90 | #define MINSTRTABSIZE 2 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /test/lua-5.1-tests/files.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.1-tests/files.lua -------------------------------------------------------------------------------- /test/lua-5.1-tests/libs/P1/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /test/lua-5.1-tests/literals.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.1-tests/literals.lua -------------------------------------------------------------------------------- /test/lua-5.1-tests/locals.lua: -------------------------------------------------------------------------------- 1 | print('testing local variables plus some extra stuff') 2 | 3 | do 4 | local i = 10 5 | do local i = 100; assert(i==100) end 6 | do local i = 1000; assert(i==1000) end 7 | assert(i == 10) 8 | if i ~= 10 then 9 | local i = 20 10 | else 11 | local i = 30 12 | assert(i == 30) 13 | end 14 | end 15 | 16 | 17 | 18 | f = nil 19 | 20 | local f 21 | x = 1 22 | 23 | a = nil 24 | loadstring('local a = {}')() 25 | assert(type(a) ~= 'table') 26 | 27 | function f (a) 28 | local _1, _2, _3, _4, _5 29 | local _6, _7, _8, _9, _10 30 | local x = 3 31 | local b = a 32 | local c,d = a,b 33 | if (d == b) then 34 | local x = 'q' 35 | x = b 36 | assert(x == 2) 37 | else 38 | assert(nil) 39 | end 40 | assert(x == 3) 41 | local f = 10 42 | end 43 | 44 | local b=10 45 | local a; repeat local b; a,b=1,2; assert(a+1==b); until a+b==3 46 | 47 | 48 | assert(x == 1) 49 | 50 | f(2) 51 | assert(type(f) == 'function') 52 | 53 | 54 | -- testing globals ;-) 55 | do 56 | local f = {} 57 | local _G = _G 58 | for i=1,10 do f[i] = function (x) A=A+1; return A, _G.getfenv(x) end end 59 | A=10; assert(f[1]() == 11) 60 | for i=1,10 do assert(setfenv(f[i], {A=i}) == f[i]) end 61 | assert(f[3]() == 4 and A == 11) 62 | local a,b = f[8](1) 63 | assert(b.A == 9) 64 | a,b = f[8](0) 65 | assert(b.A == 11) -- `real' global 66 | local g 67 | local function f () assert(setfenv(2, {a='10'}) == g) end 68 | g = function () f(); _G.assert(_G.getfenv(1).a == '10') end 69 | g(); assert(getfenv(g).a == '10') 70 | end 71 | 72 | -- test for global table of loaded chunks 73 | local function foo (s) 74 | return loadstring(s) 75 | end 76 | 77 | assert(getfenv(foo("")) == _G) 78 | local a = {loadstring = loadstring} 79 | setfenv(foo, a) 80 | assert(getfenv(foo("")) == _G) 81 | setfenv(0, a) -- change global environment 82 | assert(getfenv(foo("")) == a) 83 | setfenv(0, _G) 84 | 85 | 86 | -- testing limits for special instructions 87 | 88 | local a 89 | local p = 4 90 | for i=2,31 do 91 | for j=-3,3 do 92 | assert(loadstring(string.format([[local a=%s;a=a+ 93 | %s; 94 | assert(a 95 | ==2^%s)]], j, p-j, i))) () 96 | assert(loadstring(string.format([[local a=%s; 97 | a=a-%s; 98 | assert(a==-2^%s)]], -j, p-j, i))) () 99 | assert(loadstring(string.format([[local a,b=0,%s; 100 | a=b-%s; 101 | assert(a==-2^%s)]], -j, p-j, i))) () 102 | end 103 | p =2*p 104 | end 105 | 106 | print'+' 107 | 108 | 109 | if rawget(_G, "querytab") then 110 | -- testing clearing of dead elements from tables 111 | collectgarbage("stop") -- stop GC 112 | local a = {[{}] = 4, [3] = 0, alo = 1, 113 | a1234567890123456789012345678901234567890 = 10} 114 | 115 | local t = querytab(a) 116 | 117 | for k,_ in pairs(a) do a[k] = nil end 118 | collectgarbage() -- restore GC and collect dead fiels in `a' 119 | for i=0,t-1 do 120 | local k = querytab(a, i) 121 | assert(k == nil or type(k) == 'number' or k == 'alo') 122 | end 123 | end 124 | 125 | print('OK') 126 | 127 | return 5,f 128 | -------------------------------------------------------------------------------- /test/lua-5.1-tests/main.lua: -------------------------------------------------------------------------------- 1 | # testing special comment on first line 2 | 3 | print ("testing lua.c options") 4 | 5 | assert(os.execute() ~= 0) -- machine has a system command 6 | 7 | prog = os.tmpname() 8 | otherprog = os.tmpname() 9 | out = os.tmpname() 10 | 11 | do 12 | local i = 0 13 | while arg[i] do i=i-1 end 14 | progname = '"'..arg[i+1]..'"' 15 | end 16 | print(progname) 17 | 18 | local prepfile = function (s, p) 19 | p = p or prog 20 | io.output(p) 21 | io.write(s) 22 | assert(io.close()) 23 | end 24 | 25 | function checkout (s) 26 | io.input(out) 27 | local t = io.read("*a") 28 | io.input():close() 29 | assert(os.remove(out)) 30 | if s ~= t then print(string.format("'%s' - '%s'\n", s, t)) end 31 | assert(s == t) 32 | return t 33 | end 34 | 35 | function auxrun (...) 36 | local s = string.format(...) 37 | s = string.gsub(s, "lua", progname, 1) 38 | return os.execute(s) 39 | end 40 | 41 | function RUN (...) 42 | assert(auxrun(...) == 0) 43 | end 44 | 45 | function NoRun (...) 46 | print("\n(the next error is expected by the test)") 47 | assert(auxrun(...) ~= 0) 48 | end 49 | 50 | -- test 2 files 51 | prepfile("print(1); a=2") 52 | prepfile("print(a)", otherprog) 53 | RUN("lua -l %s -l%s -lstring -l io %s > %s", prog, otherprog, otherprog, out) 54 | checkout("1\n2\n2\n") 55 | 56 | local a = [[ 57 | assert(table.getn(arg) == 3 and arg[1] == 'a' and 58 | arg[2] == 'b' and arg[3] == 'c') 59 | assert(arg[-1] == '--' and arg[-2] == "-e " and arg[-3] == %s) 60 | assert(arg[4] == nil and arg[-4] == nil) 61 | local a, b, c = ... 62 | assert(... == 'a' and a == 'a' and b == 'b' and c == 'c') 63 | ]] 64 | a = string.format(a, progname) 65 | prepfile(a) 66 | RUN('lua "-e " -- %s a b c', prog) 67 | 68 | prepfile"assert(arg==nil)" 69 | prepfile("assert(arg)", otherprog) 70 | RUN("lua -l%s - < %s", prog, otherprog) 71 | 72 | prepfile"" 73 | RUN("lua - < %s > %s", prog, out) 74 | checkout("") 75 | 76 | -- test many arguments 77 | prepfile[[print(({...})[30])]] 78 | RUN("lua %s %s > %s", prog, string.rep(" a", 30), out) 79 | checkout("a\n") 80 | 81 | RUN([[lua "-eprint(1)" -ea=3 -e "print(a)" > %s]], out) 82 | checkout("1\n3\n") 83 | 84 | prepfile[[ 85 | print( 86 | 1, a 87 | ) 88 | ]] 89 | RUN("lua - < %s > %s", prog, out) 90 | checkout("1\tnil\n") 91 | 92 | prepfile[[ 93 | = (6*2-6) -- === 94 | a 95 | = 10 96 | print(a) 97 | = a]] 98 | RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) 99 | checkout("6\n10\n10\n\n") 100 | 101 | prepfile("a = [[b\nc\nd\ne]]\n=a") 102 | print(prog) 103 | RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) 104 | checkout("b\nc\nd\ne\n\n") 105 | 106 | prompt = "alo" 107 | prepfile[[ -- 108 | a = 2 109 | ]] 110 | RUN([[lua "-e_PROMPT='%s'" -i < %s > %s]], prompt, prog, out) 111 | checkout(string.rep(prompt, 3).."\n") 112 | 113 | s = [=[ -- 114 | function f ( x ) 115 | local a = [[ 116 | xuxu 117 | ]] 118 | local b = "\ 119 | xuxu\n" 120 | if x == 11 then return 1 , 2 end --[[ test multiple returns ]] 121 | return x + 1 122 | --\\ 123 | end 124 | =( f( 10 ) ) 125 | assert( a == b ) 126 | =f( 11 ) ]=] 127 | s = string.gsub(s, ' ', '\n\n') 128 | prepfile(s) 129 | RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) 130 | checkout("11\n1\t2\n\n") 131 | 132 | prepfile[[#comment in 1st line without \n at the end]] 133 | RUN("lua %s", prog) 134 | 135 | prepfile("#comment with a binary file\n"..string.dump(loadstring("print(1)"))) 136 | RUN("lua %s > %s", prog, out) 137 | checkout("1\n") 138 | 139 | prepfile("#comment with a binary file\r\n"..string.dump(loadstring("print(1)"))) 140 | RUN("lua %s > %s", prog, out) 141 | checkout("1\n") 142 | 143 | -- close Lua with an open file 144 | prepfile(string.format([[io.output(%q); io.write('alo')]], out)) 145 | RUN("lua %s", prog) 146 | checkout('alo') 147 | 148 | assert(os.remove(prog)) 149 | assert(os.remove(otherprog)) 150 | assert(not os.remove(out)) 151 | 152 | RUN("lua -v") 153 | 154 | NoRun("lua -h") 155 | NoRun("lua -e") 156 | NoRun("lua -e a") 157 | NoRun("lua -f") 158 | 159 | print("OK") 160 | -------------------------------------------------------------------------------- /test/lua-5.1-tests/pm.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.1-tests/pm.lua -------------------------------------------------------------------------------- /test/lua-5.1-tests/sort.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.1-tests/sort.lua -------------------------------------------------------------------------------- /test/lua-5.1-tests/strings.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.1-tests/strings.lua -------------------------------------------------------------------------------- /test/lua-5.1-tests/vararg.lua: -------------------------------------------------------------------------------- 1 | print('testing vararg') 2 | 3 | _G.arg = nil 4 | 5 | function f(a, ...) 6 | assert(type(arg) == 'table') 7 | assert(type(arg.n) == 'number') 8 | for i=1,arg.n do assert(a[i]==arg[i]) end 9 | return arg.n 10 | end 11 | 12 | function c12 (...) 13 | assert(arg == nil) 14 | local x = {...}; x.n = table.getn(x) 15 | local res = (x.n==2 and x[1] == 1 and x[2] == 2) 16 | if res then res = 55 end 17 | return res, 2 18 | end 19 | 20 | function vararg (...) return arg end 21 | 22 | local call = function (f, args) return f(unpack(args, 1, args.n)) end 23 | 24 | assert(f() == 0) 25 | assert(f({1,2,3}, 1, 2, 3) == 3) 26 | assert(f({"alo", nil, 45, f, nil}, "alo", nil, 45, f, nil) == 5) 27 | 28 | assert(c12(1,2)==55) 29 | a,b = assert(call(c12, {1,2})) 30 | assert(a == 55 and b == 2) 31 | a = call(c12, {1,2;n=2}) 32 | assert(a == 55 and b == 2) 33 | a = call(c12, {1,2;n=1}) 34 | assert(not a) 35 | assert(c12(1,2,3) == false) 36 | local a = vararg(call(next, {_G,nil;n=2})) 37 | local b,c = next(_G) 38 | assert(a[1] == b and a[2] == c and a.n == 2) 39 | a = vararg(call(call, {c12, {1,2}})) 40 | assert(a.n == 2 and a[1] == 55 and a[2] == 2) 41 | a = call(print, {'+'}) 42 | assert(a == nil) 43 | 44 | local t = {1, 10} 45 | function t:f (...) return self[arg[1]]+arg.n end 46 | assert(t:f(1,4) == 3 and t:f(2) == 11) 47 | print('+') 48 | 49 | lim = 20 50 | local i, a = 1, {} 51 | while i <= lim do a[i] = i+0.3; i=i+1 end 52 | 53 | function f(a, b, c, d, ...) 54 | local more = {...} 55 | assert(a == 1.3 and more[1] == 5.3 and 56 | more[lim-4] == lim+0.3 and not more[lim-3]) 57 | end 58 | 59 | function g(a,b,c) 60 | assert(a == 1.3 and b == 2.3 and c == 3.3) 61 | end 62 | 63 | call(f, a) 64 | call(g, a) 65 | 66 | a = {} 67 | i = 1 68 | while i <= lim do a[i] = i; i=i+1 end 69 | assert(call(math.max, a) == lim) 70 | 71 | print("+") 72 | 73 | 74 | -- new-style varargs 75 | 76 | function oneless (a, ...) return ... end 77 | 78 | function f (n, a, ...) 79 | local b 80 | assert(arg == nil) 81 | if n == 0 then 82 | local b, c, d = ... 83 | return a, b, c, d, oneless(oneless(oneless(...))) 84 | else 85 | n, b, a = n-1, ..., a 86 | assert(b == ...) 87 | return f(n, a, ...) 88 | end 89 | end 90 | 91 | a,b,c,d,e = assert(f(10,5,4,3,2,1)) 92 | assert(a==5 and b==4 and c==3 and d==2 and e==1) 93 | 94 | a,b,c,d,e = f(4) 95 | assert(a==nil and b==nil and c==nil and d==nil and e==nil) 96 | 97 | 98 | -- varargs for main chunks 99 | f = loadstring[[ return {...} ]] 100 | x = f(2,3) 101 | assert(x[1] == 2 and x[2] == 3 and x[3] == nil) 102 | 103 | 104 | f = loadstring[[ 105 | local x = {...} 106 | for i=1,select('#', ...) do assert(x[i] == select(i, ...)) end 107 | assert(x[select('#', ...)+1] == nil) 108 | return true 109 | ]] 110 | 111 | assert(f("a", "b", nil, {}, assert)) 112 | assert(f()) 113 | 114 | a = {select(3, unpack{10,20,30,40})} 115 | assert(table.getn(a) == 2 and a[1] == 30 and a[2] == 40) 116 | a = {select(1)} 117 | assert(next(a) == nil) 118 | a = {select(-1, 3, 5, 7)} 119 | assert(a[1] == 7 and a[2] == nil) 120 | a = {select(-2, 3, 5, 7)} 121 | assert(a[1] == 5 and a[2] == 7 and a[3] == nil) 122 | pcall(select, 10000) 123 | pcall(select, -10000) 124 | 125 | print('OK') 126 | 127 | -------------------------------------------------------------------------------- /test/lua-5.1-tests/verybig.lua: -------------------------------------------------------------------------------- 1 | if rawget(_G, "_soft") then return 10 end 2 | 3 | print "testing large programs (>64k)" 4 | 5 | -- template to create a very big test file 6 | prog = [[$ 7 | 8 | local a,b 9 | 10 | b = {$1$ 11 | b30009 = 65534, 12 | b30010 = 65535, 13 | b30011 = 65536, 14 | b30012 = 65537, 15 | b30013 = 16777214, 16 | b30014 = 16777215, 17 | b30015 = 16777216, 18 | b30016 = 16777217, 19 | b30017 = 4294967294, 20 | b30018 = 4294967295, 21 | b30019 = 4294967296, 22 | b30020 = 4294967297, 23 | b30021 = -65534, 24 | b30022 = -65535, 25 | b30023 = -65536, 26 | b30024 = -4294967297, 27 | b30025 = 15012.5, 28 | $2$ 29 | }; 30 | 31 | assert(b.a50008 == 25004 and b["a11"] == 5.5) 32 | assert(b.a33007 == 16503.5 and b.a50009 == 25004.5) 33 | assert(b["b"..30024] == -4294967297) 34 | 35 | function b:xxx (a,b) return a+b end 36 | assert(b:xxx(10, 12) == 22) -- pushself with non-constant index 37 | b.xxx = nil 38 | 39 | s = 0; n=0 40 | for a,b in pairs(b) do s=s+b; n=n+1 end 41 | assert(s==13977183656.5 and n==70001) 42 | 43 | require "checktable" 44 | stat(b) 45 | 46 | a = nil; b = nil 47 | print'+' 48 | 49 | function f(x) b=x end 50 | 51 | a = f{$3$} or 10 52 | 53 | assert(a==10) 54 | assert(b[1] == "a10" and b[2] == 5 and b[table.getn(b)-1] == "a50009") 55 | 56 | 57 | function xxxx (x) return b[x] end 58 | 59 | assert(xxxx(3) == "a11") 60 | 61 | a = nil; b=nil 62 | xxxx = nil 63 | 64 | return 10 65 | 66 | ]] 67 | 68 | -- functions to fill in the $n$ 69 | F = { 70 | function () -- $1$ 71 | for i=10,50009 do 72 | io.write('a', i, ' = ', 5+((i-10)/2), ',\n') 73 | end 74 | end, 75 | 76 | function () -- $2$ 77 | for i=30026,50009 do 78 | io.write('b', i, ' = ', 15013+((i-30026)/2), ',\n') 79 | end 80 | end, 81 | 82 | function () -- $3$ 83 | for i=10,50009 do 84 | io.write('"a', i, '", ', 5+((i-10)/2), ',\n') 85 | end 86 | end, 87 | } 88 | 89 | file = os.tmpname() 90 | io.output(file) 91 | for s in string.gmatch(prog, "$([^$]+)") do 92 | local n = tonumber(s) 93 | if not n then io.write(s) else F[n]() end 94 | end 95 | io.close() 96 | result = dofile(file) 97 | assert(os.remove(file)) 98 | print'OK' 99 | return result 100 | 101 | -------------------------------------------------------------------------------- /test/lua-5.2-tests/big.lua: -------------------------------------------------------------------------------- 1 | if _soft then 2 | return 'a' 3 | end 4 | 5 | print "testing large tables" 6 | 7 | local debug = require"debug" 8 | 9 | local lim = 2^18 + 1000 10 | local prog = { "local y = {0" } 11 | for i = 1, lim do prog[#prog + 1] = i end 12 | prog[#prog + 1] = "}\n" 13 | prog[#prog + 1] = "X = y\n" 14 | prog[#prog + 1] = ("assert(X[%d] == %d)"):format(lim - 1, lim - 2) 15 | prog[#prog + 1] = "return 0" 16 | prog = table.concat(prog, ";") 17 | 18 | local env = {string = string, assert = assert} 19 | local f = assert(load(prog, nil, nil, env)) 20 | 21 | f() 22 | assert(env.X[lim] == lim - 1 and env.X[lim + 1] == lim) 23 | for k in pairs(env) do env[k] = nil end 24 | 25 | -- yields during accesses larger than K (in RK) 26 | setmetatable(env, { 27 | __index = function (t, n) coroutine.yield('g'); return _G[n] end, 28 | __newindex = function (t, n, v) coroutine.yield('s'); _G[n] = v end, 29 | }) 30 | 31 | X = nil 32 | co = coroutine.wrap(f) 33 | assert(co() == 's') 34 | assert(co() == 'g') 35 | assert(co() == 'g') 36 | assert(co() == 0) 37 | 38 | assert(X[lim] == lim - 1 and X[lim + 1] == lim) 39 | 40 | -- errors in accesses larger than K (in RK) 41 | getmetatable(env).__index = function () end 42 | getmetatable(env).__newindex = function () end 43 | local e, m = pcall(f) 44 | assert(not e and m:find("global 'X'")) 45 | 46 | -- errors in metamethods 47 | getmetatable(env).__newindex = function () error("hi") end 48 | local e, m = xpcall(f, debug.traceback) 49 | assert(not e and m:find("'__newindex'")) 50 | 51 | f, X = nil 52 | 53 | coroutine.yield'b' 54 | 55 | if not _no32 then -- { 56 | 57 | print "testing string length overflow" 58 | 59 | local repstrings = 192 -- number of strings to be concatenated 60 | local ssize = math.ceil(2^32 / repstrings) + 1 -- size of each string 61 | 62 | assert(repstrings * ssize > 2^32) -- this should be larger than maximum size_t 63 | 64 | local longs = string.rep("\0", ssize) -- create one long string 65 | 66 | -- create function to concatentate 'repstrings' copies of its argument 67 | local rep = assert(load( 68 | "local a = ...; return " .. string.rep("a", repstrings, ".."))) 69 | 70 | local a, b = pcall(rep, longs) -- call that function 71 | 72 | -- it should fail without creating string (result would be too large) 73 | assert(not a and string.find(b, "overflow")) 74 | 75 | end -- } 76 | 77 | print'OK' 78 | 79 | return 'a' 80 | -------------------------------------------------------------------------------- /test/lua-5.2-tests/checktable.lua: -------------------------------------------------------------------------------- 1 | 2 | assert(rawget(_G, "stat") == nil) -- module not loaded before 3 | 4 | if T == nil then 5 | stat = function () print"`querytab' not active" end 6 | return 7 | end 8 | 9 | 10 | function checktable (t) 11 | local asize, hsize, ff = T.querytab(t) 12 | local l = {} 13 | for i=0,hsize-1 do 14 | local key,val,next = T.querytab(t, i + asize) 15 | if key == nil then 16 | assert(l[i] == nil and val==nil and next==nil) 17 | elseif key == "" then 18 | assert(val==nil) 19 | else 20 | assert(t[key] == val) 21 | local mp = T.hash(key, t) 22 | if l[i] then 23 | assert(l[i] == mp) 24 | elseif mp ~= i then 25 | l[i] = mp 26 | else -- list head 27 | l[mp] = {mp} -- first element 28 | while next do 29 | assert(ff <= next and next < hsize) 30 | if l[next] then assert(l[next] == mp) else l[next] = mp end 31 | table.insert(l[mp], next) 32 | key,val,next = T.querytab(t, next) 33 | assert(key) 34 | end 35 | end 36 | end 37 | end 38 | l.asize = asize; l.hsize = hsize; l.ff = ff 39 | return l 40 | end 41 | 42 | function mostra (t) 43 | local asize, hsize, ff = T.querytab(t) 44 | print(asize, hsize, ff) 45 | print'------' 46 | for i=0,asize-1 do 47 | local _, v = T.querytab(t, i) 48 | print(string.format("[%d] -", i), v) 49 | end 50 | print'------' 51 | for i=0,hsize-1 do 52 | print(i, T.querytab(t, i+asize)) 53 | end 54 | print'-------------' 55 | end 56 | 57 | function stat (t) 58 | t = checktable(t) 59 | local nelem, nlist = 0, 0 60 | local maxlist = {} 61 | for i=0,t.hsize-1 do 62 | if type(t[i]) == 'table' then 63 | local n = table.getn(t[i]) 64 | nlist = nlist+1 65 | nelem = nelem + n 66 | if not maxlist[n] then maxlist[n] = 0 end 67 | maxlist[n] = maxlist[n]+1 68 | end 69 | end 70 | print(string.format("hsize=%d elements=%d load=%.2f med.len=%.2f (asize=%d)", 71 | t.hsize, nelem, nelem/t.hsize, nelem/nlist, t.asize)) 72 | for i=1,table.getn(maxlist) do 73 | local n = maxlist[i] or 0 74 | print(string.format("%5d %10d %.2f%%", i, n, n*100/nlist)) 75 | end 76 | end 77 | 78 | -------------------------------------------------------------------------------- /test/lua-5.2-tests/db.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.2-tests/db.lua -------------------------------------------------------------------------------- /test/lua-5.2-tests/files.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.2-tests/files.lua -------------------------------------------------------------------------------- /test/lua-5.2-tests/libs/P1/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /test/lua-5.2-tests/libs/lib1.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** compile with 3 | ** Linux: gcc -Wall -O2 -I.. -ansi -shared -o lib1.so lib1.c 4 | ** Mac OS X: export MACOSX_DEPLOYMENT_TARGET=10.3 5 | ** gcc -bundle -undefined dynamic_lookup -Wall -O2 -o lib1.so lib1.c 6 | */ 7 | 8 | 9 | #include "lua.h" 10 | #include "lauxlib.h" 11 | 12 | static int id (lua_State *L) { 13 | return lua_gettop(L); 14 | } 15 | 16 | 17 | static const struct luaL_Reg funcs[] = { 18 | {"id", id}, 19 | {NULL, NULL} 20 | }; 21 | 22 | 23 | /* function used by lib11.c */ 24 | int lib1_export (lua_State *L) { 25 | lua_pushstring(L, "exported"); 26 | return 1; 27 | } 28 | 29 | 30 | int onefunction (lua_State *L) { 31 | lua_settop(L, 2); 32 | lua_pushvalue(L, 1); 33 | return 2; 34 | } 35 | 36 | 37 | int anotherfunc (lua_State *L) { 38 | lua_pushfstring(L, "%f%f\n", lua_tonumber(L, 1), lua_tonumber(L, 2)); 39 | return 1; 40 | } 41 | 42 | 43 | int luaopen_lib1_sub (lua_State *L) { 44 | lua_setglobal(L, "y"); 45 | lua_setglobal(L, "x"); 46 | luaL_newlib(L, funcs); 47 | return 1; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /test/lua-5.2-tests/libs/lib11.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** compile with 3 | ** Linux: gcc -Wall -O2 -I.. -ansi -shared -o lib1.so lib1.c 4 | ** Mac OS X: export MACOSX_DEPLOYMENT_TARGET=10.3 5 | ** gcc -bundle -undefined dynamic_lookup -Wall -O2 -o lib1.so lib1.c 6 | */ 7 | 8 | 9 | #include "lua.h" 10 | 11 | /* function from lib1.c */ 12 | int lib1_export (lua_State *L); 13 | 14 | int luaopen_lib11 (lua_State *L) { 15 | return lib1_export(L); 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /test/lua-5.2-tests/libs/lib2.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** compile with 3 | ** gcc -Wall -O2 -I.. -ansi -shared -o lib1.so lib1.c 4 | */ 5 | 6 | 7 | #include "lua.h" 8 | #include "lauxlib.h" 9 | 10 | static int id (lua_State *L) { 11 | return lua_gettop(L); 12 | } 13 | 14 | 15 | static const struct luaL_Reg funcs[] = { 16 | {"id", id}, 17 | {NULL, NULL} 18 | }; 19 | 20 | 21 | int luaopen_lib2 (lua_State *L) { 22 | lua_settop(L, 2); 23 | lua_setglobal(L, "y"); /* y gets 2nd parameter */ 24 | lua_setglobal(L, "x"); /* x gets 1st parameter */ 25 | luaL_newlib(L, funcs); 26 | return 1; 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /test/lua-5.2-tests/libs/lib21.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** compile with 3 | ** Linux: gcc -Wall -O2 -I.. -ansi -shared -o lib1.so lib1.c 4 | ** Mac OS X: export MACOSX_DEPLOYMENT_TARGET=10.3 5 | ** gcc -bundle -undefined dynamic_lookup -Wall -O2 -o lib1.so lib1.c 6 | */ 7 | 8 | 9 | #include "lua.h" 10 | 11 | 12 | int luaopen_lib2 (lua_State *L); 13 | 14 | int luaopen_lib21 (lua_State *L) { 15 | return luaopen_lib2(L); 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /test/lua-5.2-tests/libs/makefile: -------------------------------------------------------------------------------- 1 | # change this variable to point to the directory with Lua headers 2 | # of the version being tested 3 | LUA_DIR = ../.. 4 | 5 | CC = gcc 6 | 7 | # compilation should generate Dynamic-Link Libraries 8 | CFLAGS = -Wall -O2 -I$(LUA_DIR) -ansi -fpic -shared 9 | 10 | # libraries used by the tests 11 | all: lib1.so lib11.so lib2.so lib21.so v-lib2.so 12 | 13 | lib1.so: lib1.c 14 | $(CC) $(CFLAGS) -o lib1.so lib1.c 15 | 16 | lib11.so: lib11.c 17 | $(CC) $(CFLAGS) -o lib11.so lib11.c 18 | 19 | lib2.so: lib2.c 20 | $(CC) $(CFLAGS) -o lib2.so lib2.c 21 | 22 | lib21.so: lib21.c 23 | $(CC) $(CFLAGS) -o lib21.so lib21.c 24 | 25 | v-lib2.so: lib2.so 26 | mv lib2.so ./v-lib2.so 27 | -------------------------------------------------------------------------------- /test/lua-5.2-tests/literals.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.2-tests/literals.lua -------------------------------------------------------------------------------- /test/lua-5.2-tests/locals.lua: -------------------------------------------------------------------------------- 1 | print('testing local variables and environments') 2 | 3 | local debug = require"debug" 4 | 5 | 6 | -- bug in 5.1: 7 | 8 | local function f(x) x = nil; return x end 9 | assert(f(10) == nil) 10 | 11 | local function f() local x; return x end 12 | assert(f(10) == nil) 13 | 14 | local function f(x) x = nil; local y; return x, y end 15 | assert(f(10) == nil and select(2, f(20)) == nil) 16 | 17 | do 18 | local i = 10 19 | do local i = 100; assert(i==100) end 20 | do local i = 1000; assert(i==1000) end 21 | assert(i == 10) 22 | if i ~= 10 then 23 | local i = 20 24 | else 25 | local i = 30 26 | assert(i == 30) 27 | end 28 | end 29 | 30 | 31 | 32 | f = nil 33 | 34 | local f 35 | x = 1 36 | 37 | a = nil 38 | load('local a = {}')() 39 | assert(a == nil) 40 | 41 | function f (a) 42 | local _1, _2, _3, _4, _5 43 | local _6, _7, _8, _9, _10 44 | local x = 3 45 | local b = a 46 | local c,d = a,b 47 | if (d == b) then 48 | local x = 'q' 49 | x = b 50 | assert(x == 2) 51 | else 52 | assert(nil) 53 | end 54 | assert(x == 3) 55 | local f = 10 56 | end 57 | 58 | local b=10 59 | local a; repeat local b; a,b=1,2; assert(a+1==b); until a+b==3 60 | 61 | 62 | assert(x == 1) 63 | 64 | f(2) 65 | assert(type(f) == 'function') 66 | 67 | 68 | local function getenv (f) 69 | local a,b = debug.getupvalue(f, 1) 70 | assert(a == '_ENV') 71 | return b 72 | end 73 | 74 | -- test for global table of loaded chunks 75 | assert(getenv(load"a=3") == _G) 76 | local c = {}; local f = load("a = 3", nil, nil, c) 77 | assert(getenv(f) == c) 78 | assert(c.a == nil) 79 | f() 80 | assert(c.a == 3) 81 | 82 | -- testing limits for special instructions 83 | 84 | if not _soft then 85 | local a 86 | local p = 4 87 | for i=2,31 do 88 | for j=-3,3 do 89 | assert(load(string.format([[local a=%s; 90 | a=a+%s; 91 | assert(a ==2^%s)]], j, p-j, i))) () 92 | assert(load(string.format([[local a=%s; 93 | a=a-%s; 94 | assert(a==-2^%s)]], -j, p-j, i))) () 95 | assert(load(string.format([[local a,b=0,%s; 96 | a=b-%s; 97 | assert(a==-2^%s)]], -j, p-j, i))) () 98 | end 99 | p =2*p 100 | end 101 | end 102 | 103 | print'+' 104 | 105 | 106 | if rawget(_G, "querytab") then 107 | -- testing clearing of dead elements from tables 108 | collectgarbage("stop") -- stop GC 109 | local a = {[{}] = 4, [3] = 0, alo = 1, 110 | a1234567890123456789012345678901234567890 = 10} 111 | 112 | local t = querytab(a) 113 | 114 | for k,_ in pairs(a) do a[k] = nil end 115 | collectgarbage() -- restore GC and collect dead fiels in `a' 116 | for i=0,t-1 do 117 | local k = querytab(a, i) 118 | assert(k == nil or type(k) == 'number' or k == 'alo') 119 | end 120 | end 121 | 122 | 123 | -- testing lexical environments 124 | 125 | assert(_ENV == _G) 126 | 127 | do local _ENV = (function (...) return ... end)(_G, dummy) 128 | 129 | do local _ENV = {assert=assert}; assert(true) end 130 | mt = {_G = _G} 131 | local foo,x 132 | do local _ENV = mt 133 | function foo (x) 134 | A = x 135 | do local _ENV = _G; A = 1000 end 136 | return function (x) return A .. x end 137 | end 138 | end 139 | assert(getenv(foo) == mt) 140 | x = foo('hi'); assert(mt.A == 'hi' and A == 1000) 141 | assert(x('*') == mt.A .. '*') 142 | 143 | do local _ENV = {assert=assert, A=10}; 144 | do local _ENV = {assert=assert, A=20}; 145 | assert(A==20);x=A 146 | end 147 | assert(A==10 and x==20) 148 | end 149 | assert(x==20) 150 | 151 | 152 | print('OK') 153 | 154 | return 5,f 155 | 156 | end 157 | 158 | -------------------------------------------------------------------------------- /test/lua-5.2-tests/ltests/ltests.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltests.h,v 2.33 2010/07/28 15:51:59 roberto Exp $ 3 | ** Internal Header for Debugging of the Lua Implementation 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltests_h 8 | #define ltests_h 9 | 10 | 11 | #include 12 | 13 | /* do not use compatibility macros in Lua code */ 14 | #undef LUA_COMPAT_API 15 | 16 | #define LUA_DEBUG 17 | 18 | #undef NDEBUG 19 | #include 20 | #define lua_assert(c) assert(c) 21 | 22 | 23 | /* to avoid warnings, and to make sure value is really unused */ 24 | #define UNUSED(x) (x=0, (void)(x)) 25 | 26 | 27 | /* memory allocator control variables */ 28 | typedef struct Memcontrol { 29 | unsigned long numblocks; 30 | unsigned long total; 31 | unsigned long maxmem; 32 | unsigned long memlimit; 33 | unsigned long objcount[LUA_NUMTAGS]; 34 | } Memcontrol; 35 | 36 | extern Memcontrol l_memcontrol; 37 | 38 | 39 | /* 40 | ** generic variable for debug tricks 41 | */ 42 | extern void *l_Trick; 43 | 44 | 45 | void *debug_realloc (void *ud, void *block, size_t osize, size_t nsize); 46 | 47 | 48 | typedef struct CallInfo *pCallInfo; 49 | 50 | int lua_checkmemory (lua_State *L); 51 | 52 | 53 | /* test for lock/unlock */ 54 | #undef luai_userstateopen 55 | #undef luai_userstatethread 56 | #undef lua_lock 57 | #undef lua_unlock 58 | 59 | struct L_EXTRA { int lock; int *plock; }; 60 | #define LUAI_EXTRASPACE sizeof(struct L_EXTRA) 61 | #define getlock(l) (cast(struct L_EXTRA *, l) - 1) 62 | #define luai_userstateopen(l) \ 63 | (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock)) 64 | #define luai_userstatethread(l,l1) (getlock(l1)->plock = getlock(l)->plock) 65 | #define luai_userstatefree(l,l1) \ 66 | lua_assert(getlock(l)->plock == getlock(l1)->plock) 67 | #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0) 68 | #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0) 69 | 70 | 71 | int luaB_opentests (lua_State *L); 72 | 73 | 74 | #if defined(lua_c) 75 | #define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol) 76 | #define luaL_openlibs(L) \ 77 | { (luaL_openlibs)(L); luaL_requiref(L, "T", luaB_opentests, 1); } 78 | #endif 79 | 80 | 81 | 82 | /* change some sizes to give some bugs a chance */ 83 | 84 | #undef LUAL_BUFFERSIZE 85 | #define LUAL_BUFFERSIZE 23 86 | #define MINSTRTABSIZE 2 87 | 88 | 89 | #undef LUAI_USER_ALIGNMENT_T 90 | #define LUAI_USER_ALIGNMENT_T union { char b[32]; } 91 | 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /test/lua-5.2-tests/pm.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.2-tests/pm.lua -------------------------------------------------------------------------------- /test/lua-5.2-tests/sort.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.2-tests/sort.lua -------------------------------------------------------------------------------- /test/lua-5.2-tests/strings.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.2-tests/strings.lua -------------------------------------------------------------------------------- /test/lua-5.2-tests/vararg.lua: -------------------------------------------------------------------------------- 1 | print('testing vararg') 2 | 3 | _G.arg = nil 4 | 5 | function f(a, ...) 6 | local arg = {n = select('#', ...), ...} 7 | for i=1,arg.n do assert(a[i]==arg[i]) end 8 | return arg.n 9 | end 10 | 11 | function c12 (...) 12 | assert(arg == nil) 13 | local x = {...}; x.n = #x 14 | local res = (x.n==2 and x[1] == 1 and x[2] == 2) 15 | if res then res = 55 end 16 | return res, 2 17 | end 18 | 19 | function vararg (...) return {n = select('#', ...), ...} end 20 | 21 | local call = function (f, args) return f(table.unpack(args, 1, args.n)) end 22 | 23 | assert(f() == 0) 24 | assert(f({1,2,3}, 1, 2, 3) == 3) 25 | assert(f({"alo", nil, 45, f, nil}, "alo", nil, 45, f, nil) == 5) 26 | 27 | assert(c12(1,2)==55) 28 | a,b = assert(call(c12, {1,2})) 29 | assert(a == 55 and b == 2) 30 | a = call(c12, {1,2;n=2}) 31 | assert(a == 55 and b == 2) 32 | a = call(c12, {1,2;n=1}) 33 | assert(not a) 34 | assert(c12(1,2,3) == false) 35 | local a = vararg(call(next, {_G,nil;n=2})) 36 | local b,c = next(_G) 37 | assert(a[1] == b and a[2] == c and a.n == 2) 38 | a = vararg(call(call, {c12, {1,2}})) 39 | assert(a.n == 2 and a[1] == 55 and a[2] == 2) 40 | a = call(print, {'+'}) 41 | assert(a == nil) 42 | 43 | local t = {1, 10} 44 | function t:f (...) local arg = {...}; return self[...]+#arg end 45 | assert(t:f(1,4) == 3 and t:f(2) == 11) 46 | print('+') 47 | 48 | lim = 20 49 | local i, a = 1, {} 50 | while i <= lim do a[i] = i+0.3; i=i+1 end 51 | 52 | function f(a, b, c, d, ...) 53 | local more = {...} 54 | assert(a == 1.3 and more[1] == 5.3 and 55 | more[lim-4] == lim+0.3 and not more[lim-3]) 56 | end 57 | 58 | function g(a,b,c) 59 | assert(a == 1.3 and b == 2.3 and c == 3.3) 60 | end 61 | 62 | call(f, a) 63 | call(g, a) 64 | 65 | a = {} 66 | i = 1 67 | while i <= lim do a[i] = i; i=i+1 end 68 | assert(call(math.max, a) == lim) 69 | 70 | print("+") 71 | 72 | 73 | -- new-style varargs 74 | 75 | function oneless (a, ...) return ... end 76 | 77 | function f (n, a, ...) 78 | local b 79 | assert(arg == nil) 80 | if n == 0 then 81 | local b, c, d = ... 82 | return a, b, c, d, oneless(oneless(oneless(...))) 83 | else 84 | n, b, a = n-1, ..., a 85 | assert(b == ...) 86 | return f(n, a, ...) 87 | end 88 | end 89 | 90 | a,b,c,d,e = assert(f(10,5,4,3,2,1)) 91 | assert(a==5 and b==4 and c==3 and d==2 and e==1) 92 | 93 | a,b,c,d,e = f(4) 94 | assert(a==nil and b==nil and c==nil and d==nil and e==nil) 95 | 96 | 97 | -- varargs for main chunks 98 | f = load[[ return {...} ]] 99 | x = f(2,3) 100 | assert(x[1] == 2 and x[2] == 3 and x[3] == nil) 101 | 102 | 103 | f = load[[ 104 | local x = {...} 105 | for i=1,select('#', ...) do assert(x[i] == select(i, ...)) end 106 | assert(x[select('#', ...)+1] == nil) 107 | return true 108 | ]] 109 | 110 | assert(f("a", "b", nil, {}, assert)) 111 | assert(f()) 112 | 113 | a = {select(3, table.unpack{10,20,30,40})} 114 | assert(#a == 2 and a[1] == 30 and a[2] == 40) 115 | a = {select(1)} 116 | assert(next(a) == nil) 117 | a = {select(-1, 3, 5, 7)} 118 | assert(a[1] == 7 and a[2] == nil) 119 | a = {select(-2, 3, 5, 7)} 120 | assert(a[1] == 5 and a[2] == 7 and a[3] == nil) 121 | pcall(select, 10000) 122 | pcall(select, -10000) 123 | 124 | print('OK') 125 | 126 | -------------------------------------------------------------------------------- /test/lua-5.2-tests/verybig.lua: -------------------------------------------------------------------------------- 1 | print "testing RK" 2 | 3 | -- testing opcodes with RK arguments larger than K limit 4 | local function foo () 5 | local dummy = { 6 | -- fill first 256 entries in table of constants 7 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 8 | 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 9 | 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 10 | 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 11 | 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 12 | 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 13 | 97, 98, 99, 100, 101, 102, 103, 104, 14 | 105, 106, 107, 108, 109, 110, 111, 112, 15 | 113, 114, 115, 116, 117, 118, 119, 120, 16 | 121, 122, 123, 124, 125, 126, 127, 128, 17 | 129, 130, 131, 132, 133, 134, 135, 136, 18 | 137, 138, 139, 140, 141, 142, 143, 144, 19 | 145, 146, 147, 148, 149, 150, 151, 152, 20 | 153, 154, 155, 156, 157, 158, 159, 160, 21 | 161, 162, 163, 164, 165, 166, 167, 168, 22 | 169, 170, 171, 172, 173, 174, 175, 176, 23 | 177, 178, 179, 180, 181, 182, 183, 184, 24 | 185, 186, 187, 188, 189, 190, 191, 192, 25 | 193, 194, 195, 196, 197, 198, 199, 200, 26 | 201, 202, 203, 204, 205, 206, 207, 208, 27 | 209, 210, 211, 212, 213, 214, 215, 216, 28 | 217, 218, 219, 220, 221, 222, 223, 224, 29 | 225, 226, 227, 228, 229, 230, 231, 232, 30 | 233, 234, 235, 236, 237, 238, 239, 240, 31 | 241, 242, 243, 244, 245, 246, 247, 248, 32 | 249, 250, 251, 252, 253, 254, 255, 256, 33 | } 34 | assert(24.5 + 0.6 == 25.1) 35 | local t = {foo = function (self, x) return x + self.x end, x = 10} 36 | t.t = t 37 | assert(t:foo(1.5) == 11.5) 38 | assert(t.t:foo(0.5) == 10.5) -- bug in 5.2 alpha 39 | assert(24.3 == 24.3) 40 | assert((function () return t.x end)() == 10) 41 | end 42 | 43 | 44 | foo() 45 | foo = nil 46 | 47 | if _soft then return 10 end 48 | 49 | print "testing large programs (>64k)" 50 | 51 | -- template to create a very big test file 52 | prog = [[$ 53 | 54 | local a,b 55 | 56 | b = {$1$ 57 | b30009 = 65534, 58 | b30010 = 65535, 59 | b30011 = 65536, 60 | b30012 = 65537, 61 | b30013 = 16777214, 62 | b30014 = 16777215, 63 | b30015 = 16777216, 64 | b30016 = 16777217, 65 | b30017 = 4294967294, 66 | b30018 = 4294967295, 67 | b30019 = 4294967296, 68 | b30020 = 4294967297, 69 | b30021 = -65534, 70 | b30022 = -65535, 71 | b30023 = -65536, 72 | b30024 = -4294967297, 73 | b30025 = 15012.5, 74 | $2$ 75 | }; 76 | 77 | assert(b.a50008 == 25004 and b["a11"] == 5.5) 78 | assert(b.a33007 == 16503.5 and b.a50009 == 25004.5) 79 | assert(b["b"..30024] == -4294967297) 80 | 81 | function b:xxx (a,b) return a+b end 82 | assert(b:xxx(10, 12) == 22) -- pushself with non-constant index 83 | b.xxx = nil 84 | 85 | s = 0; n=0 86 | for a,b in pairs(b) do s=s+b; n=n+1 end 87 | assert(s==13977183656.5 and n==70001) 88 | 89 | 90 | a = nil; b = nil 91 | print'+' 92 | 93 | function f(x) b=x end 94 | 95 | a = f{$3$} or 10 96 | 97 | assert(a==10) 98 | assert(b[1] == "a10" and b[2] == 5 and b[#b-1] == "a50009") 99 | 100 | 101 | function xxxx (x) return b[x] end 102 | 103 | assert(xxxx(3) == "a11") 104 | 105 | a = nil; b=nil 106 | xxxx = nil 107 | 108 | return 10 109 | 110 | ]] 111 | 112 | -- functions to fill in the $n$ 113 | F = { 114 | function () -- $1$ 115 | for i=10,50009 do 116 | io.write('a', i, ' = ', 5+((i-10)/2), ',\n') 117 | end 118 | end, 119 | 120 | function () -- $2$ 121 | for i=30026,50009 do 122 | io.write('b', i, ' = ', 15013+((i-30026)/2), ',\n') 123 | end 124 | end, 125 | 126 | function () -- $3$ 127 | for i=10,50009 do 128 | io.write('"a', i, '", ', 5+((i-10)/2), ',\n') 129 | end 130 | end, 131 | } 132 | 133 | file = os.tmpname() 134 | io.output(file) 135 | for s in string.gmatch(prog, "$([^$]+)") do 136 | local n = tonumber(s) 137 | if not n then io.write(s) else F[n]() end 138 | end 139 | io.close() 140 | result = dofile(file) 141 | assert(os.remove(file)) 142 | print'OK' 143 | return result 144 | 145 | -------------------------------------------------------------------------------- /test/lua-5.3-tests/big.lua: -------------------------------------------------------------------------------- 1 | -- $Id: big.lua,v 1.31 2014/12/26 17:20:53 roberto Exp $ 2 | 3 | if _soft then 4 | return 'a' 5 | end 6 | 7 | print "testing large tables" 8 | 9 | local debug = require"debug" 10 | 11 | local lim = 2^18 + 1000 12 | local prog = { "local y = {0" } 13 | for i = 1, lim do prog[#prog + 1] = i end 14 | prog[#prog + 1] = "}\n" 15 | prog[#prog + 1] = "X = y\n" 16 | prog[#prog + 1] = ("assert(X[%d] == %d)"):format(lim - 1, lim - 2) 17 | prog[#prog + 1] = "return 0" 18 | prog = table.concat(prog, ";") 19 | 20 | local env = {string = string, assert = assert} 21 | local f = assert(load(prog, nil, nil, env)) 22 | 23 | f() 24 | assert(env.X[lim] == lim - 1 and env.X[lim + 1] == lim) 25 | for k in pairs(env) do env[k] = nil end 26 | 27 | -- yields during accesses larger than K (in RK) 28 | setmetatable(env, { 29 | __index = function (t, n) coroutine.yield('g'); return _G[n] end, 30 | __newindex = function (t, n, v) coroutine.yield('s'); _G[n] = v end, 31 | }) 32 | 33 | X = nil 34 | co = coroutine.wrap(f) 35 | assert(co() == 's') 36 | assert(co() == 'g') 37 | assert(co() == 'g') 38 | assert(co() == 0) 39 | 40 | assert(X[lim] == lim - 1 and X[lim + 1] == lim) 41 | 42 | -- errors in accesses larger than K (in RK) 43 | getmetatable(env).__index = function () end 44 | getmetatable(env).__newindex = function () end 45 | local e, m = pcall(f) 46 | assert(not e and m:find("global 'X'")) 47 | 48 | -- errors in metamethods 49 | getmetatable(env).__newindex = function () error("hi") end 50 | local e, m = xpcall(f, debug.traceback) 51 | assert(not e and m:find("'__newindex'")) 52 | 53 | f, X = nil 54 | 55 | coroutine.yield'b' 56 | 57 | if 2^32 == 0 then -- (small integers) { 58 | 59 | print "testing string length overflow" 60 | 61 | local repstrings = 192 -- number of strings to be concatenated 62 | local ssize = math.ceil(2.0^32 / repstrings) + 1 -- size of each string 63 | 64 | assert(repstrings * ssize > 2.0^32) -- it should be larger than maximum size 65 | 66 | local longs = string.rep("\0", ssize) -- create one long string 67 | 68 | -- create function to concatentate 'repstrings' copies of its argument 69 | local rep = assert(load( 70 | "local a = ...; return " .. string.rep("a", repstrings, ".."))) 71 | 72 | local a, b = pcall(rep, longs) -- call that function 73 | 74 | -- it should fail without creating string (result would be too large) 75 | assert(not a and string.find(b, "overflow")) 76 | 77 | end -- } 78 | 79 | print'OK' 80 | 81 | return 'a' 82 | -------------------------------------------------------------------------------- /test/lua-5.3-tests/db.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.3-tests/db.lua -------------------------------------------------------------------------------- /test/lua-5.3-tests/files.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.3-tests/files.lua -------------------------------------------------------------------------------- /test/lua-5.3-tests/libs/P1/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /test/lua-5.3-tests/libs/lib1.c: -------------------------------------------------------------------------------- 1 | #include "lua.h" 2 | #include "lauxlib.h" 3 | 4 | static int id (lua_State *L) { 5 | return lua_gettop(L); 6 | } 7 | 8 | 9 | static const struct luaL_Reg funcs[] = { 10 | {"id", id}, 11 | {NULL, NULL} 12 | }; 13 | 14 | 15 | /* function used by lib11.c */ 16 | LUAMOD_API int lib1_export (lua_State *L) { 17 | lua_pushstring(L, "exported"); 18 | return 1; 19 | } 20 | 21 | 22 | LUAMOD_API int onefunction (lua_State *L) { 23 | luaL_checkversion(L); 24 | lua_settop(L, 2); 25 | lua_pushvalue(L, 1); 26 | return 2; 27 | } 28 | 29 | 30 | LUAMOD_API int anotherfunc (lua_State *L) { 31 | luaL_checkversion(L); 32 | lua_pushfstring(L, "%d%%%d\n", (int)lua_tointeger(L, 1), 33 | (int)lua_tointeger(L, 2)); 34 | return 1; 35 | } 36 | 37 | 38 | LUAMOD_API int luaopen_lib1_sub (lua_State *L) { 39 | lua_setglobal(L, "y"); /* 2nd arg: extra value (file name) */ 40 | lua_setglobal(L, "x"); /* 1st arg: module name */ 41 | luaL_newlib(L, funcs); 42 | return 1; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /test/lua-5.3-tests/libs/lib11.c: -------------------------------------------------------------------------------- 1 | #include "lua.h" 2 | 3 | /* function from lib1.c */ 4 | int lib1_export (lua_State *L); 5 | 6 | LUAMOD_API int luaopen_lib11 (lua_State *L) { 7 | return lib1_export(L); 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/lua-5.3-tests/libs/lib2.c: -------------------------------------------------------------------------------- 1 | #include "lua.h" 2 | #include "lauxlib.h" 3 | 4 | static int id (lua_State *L) { 5 | return lua_gettop(L); 6 | } 7 | 8 | 9 | static const struct luaL_Reg funcs[] = { 10 | {"id", id}, 11 | {NULL, NULL} 12 | }; 13 | 14 | 15 | LUAMOD_API int luaopen_lib2 (lua_State *L) { 16 | lua_settop(L, 2); 17 | lua_setglobal(L, "y"); /* y gets 2nd parameter */ 18 | lua_setglobal(L, "x"); /* x gets 1st parameter */ 19 | luaL_newlib(L, funcs); 20 | return 1; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/lua-5.3-tests/libs/lib21.c: -------------------------------------------------------------------------------- 1 | #include "lua.h" 2 | 3 | 4 | int luaopen_lib2 (lua_State *L); 5 | 6 | LUAMOD_API int luaopen_lib21 (lua_State *L) { 7 | return luaopen_lib2(L); 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/lua-5.3-tests/libs/makefile: -------------------------------------------------------------------------------- 1 | # change this variable to point to the directory with Lua headers 2 | # of the version being tested 3 | LUA_DIR = ../.. 4 | 5 | CC = gcc 6 | 7 | # compilation should generate Dynamic-Link Libraries 8 | CFLAGS = -Wall -std=gnu99 -O2 -I$(LUA_DIR) -fpic -shared 9 | 10 | # libraries used by the tests 11 | all: lib1.so lib11.so lib2.so lib21.so lib2-v2.so 12 | 13 | lib1.so: lib1.c 14 | $(CC) $(CFLAGS) -o lib1.so lib1.c 15 | 16 | lib11.so: lib11.c 17 | $(CC) $(CFLAGS) -o lib11.so lib11.c 18 | 19 | lib2.so: lib2.c 20 | $(CC) $(CFLAGS) -o lib2.so lib2.c 21 | 22 | lib21.so: lib21.c 23 | $(CC) $(CFLAGS) -o lib21.so lib21.c 24 | 25 | lib2-v2.so: lib2.so 26 | mv lib2.so ./lib2-v2.so 27 | -------------------------------------------------------------------------------- /test/lua-5.3-tests/locals.lua: -------------------------------------------------------------------------------- 1 | -- $Id: locals.lua,v 1.35 2014/12/26 17:20:53 roberto Exp $ 2 | 3 | print('testing local variables and environments') 4 | 5 | local debug = require"debug" 6 | 7 | 8 | -- bug in 5.1: 9 | 10 | local function f(x) x = nil; return x end 11 | assert(f(10) == nil) 12 | 13 | local function f() local x; return x end 14 | assert(f(10) == nil) 15 | 16 | local function f(x) x = nil; local y; return x, y end 17 | assert(f(10) == nil and select(2, f(20)) == nil) 18 | 19 | do 20 | local i = 10 21 | do local i = 100; assert(i==100) end 22 | do local i = 1000; assert(i==1000) end 23 | assert(i == 10) 24 | if i ~= 10 then 25 | local i = 20 26 | else 27 | local i = 30 28 | assert(i == 30) 29 | end 30 | end 31 | 32 | 33 | 34 | f = nil 35 | 36 | local f 37 | x = 1 38 | 39 | a = nil 40 | load('local a = {}')() 41 | assert(a == nil) 42 | 43 | function f (a) 44 | local _1, _2, _3, _4, _5 45 | local _6, _7, _8, _9, _10 46 | local x = 3 47 | local b = a 48 | local c,d = a,b 49 | if (d == b) then 50 | local x = 'q' 51 | x = b 52 | assert(x == 2) 53 | else 54 | assert(nil) 55 | end 56 | assert(x == 3) 57 | local f = 10 58 | end 59 | 60 | local b=10 61 | local a; repeat local b; a,b=1,2; assert(a+1==b); until a+b==3 62 | 63 | 64 | assert(x == 1) 65 | 66 | f(2) 67 | assert(type(f) == 'function') 68 | 69 | 70 | local function getenv (f) 71 | local a,b = debug.getupvalue(f, 1) 72 | assert(a == '_ENV') 73 | return b 74 | end 75 | 76 | -- test for global table of loaded chunks 77 | assert(getenv(load"a=3") == _G) 78 | local c = {}; local f = load("a = 3", nil, nil, c) 79 | assert(getenv(f) == c) 80 | assert(c.a == nil) 81 | f() 82 | assert(c.a == 3) 83 | 84 | -- old test for limits for special instructions (now just a generic test) 85 | do 86 | local i = 2 87 | local p = 4 -- p == 2^i 88 | repeat 89 | for j=-3,3 do 90 | assert(load(string.format([[local a=%s; 91 | a=a+%s; 92 | assert(a ==2^%s)]], j, p-j, i))) () 93 | assert(load(string.format([[local a=%s; 94 | a=a-%s; 95 | assert(a==-2^%s)]], -j, p-j, i))) () 96 | assert(load(string.format([[local a,b=0,%s; 97 | a=b-%s; 98 | assert(a==-2^%s)]], -j, p-j, i))) () 99 | end 100 | p = 2 * p; i = i + 1 101 | until p <= 0 102 | end 103 | 104 | print'+' 105 | 106 | 107 | if rawget(_G, "querytab") then 108 | -- testing clearing of dead elements from tables 109 | collectgarbage("stop") -- stop GC 110 | local a = {[{}] = 4, [3] = 0, alo = 1, 111 | a1234567890123456789012345678901234567890 = 10} 112 | 113 | local t = querytab(a) 114 | 115 | for k,_ in pairs(a) do a[k] = nil end 116 | collectgarbage() -- restore GC and collect dead fiels in `a' 117 | for i=0,t-1 do 118 | local k = querytab(a, i) 119 | assert(k == nil or type(k) == 'number' or k == 'alo') 120 | end 121 | end 122 | 123 | 124 | -- testing lexical environments 125 | 126 | assert(_ENV == _G) 127 | 128 | do 129 | local dummy 130 | local _ENV = (function (...) return ... end)(_G, dummy) -- { 131 | 132 | do local _ENV = {assert=assert}; assert(true) end 133 | mt = {_G = _G} 134 | local foo,x 135 | A = false -- "declare" A 136 | do local _ENV = mt 137 | function foo (x) 138 | A = x 139 | do local _ENV = _G; A = 1000 end 140 | return function (x) return A .. x end 141 | end 142 | end 143 | assert(getenv(foo) == mt) 144 | x = foo('hi'); assert(mt.A == 'hi' and A == 1000) 145 | assert(x('*') == mt.A .. '*') 146 | 147 | do local _ENV = {assert=assert, A=10}; 148 | do local _ENV = {assert=assert, A=20}; 149 | assert(A==20);x=A 150 | end 151 | assert(A==10 and x==20) 152 | end 153 | assert(x==20) 154 | 155 | 156 | print('OK') 157 | 158 | return 5,f 159 | 160 | end -- } 161 | 162 | -------------------------------------------------------------------------------- /test/lua-5.3-tests/ltests/ltests.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltests.h,v 2.47 2014/12/26 14:44:44 roberto Exp $ 3 | ** Internal Header for Debugging of the Lua Implementation 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltests_h 8 | #define ltests_h 9 | 10 | 11 | #include 12 | 13 | /* test Lua with no compatibility code */ 14 | #undef LUA_COMPAT_MATHLIB 15 | #undef LUA_COMPAT_IPAIRS 16 | #undef LUA_COMPAT_BITLIB 17 | #undef LUA_COMPAT_APIINTCASTS 18 | #undef LUA_COMPAT_FLOATSTRING 19 | #undef LUA_COMPAT_UNPACK 20 | #undef LUA_COMPAT_LOADERS 21 | #undef LUA_COMPAT_LOG10 22 | #undef LUA_COMPAT_LOADSTRING 23 | #undef LUA_COMPAT_MAXN 24 | #undef LUA_COMPAT_MODULE 25 | 26 | 27 | #define LUA_DEBUG 28 | 29 | 30 | /* turn on assertions */ 31 | #undef NDEBUG 32 | #include 33 | #define lua_assert(c) assert(c) 34 | 35 | 36 | /* to avoid warnings, and to make sure value is really unused */ 37 | #define UNUSED(x) (x=0, (void)(x)) 38 | 39 | 40 | /* memory-allocator control variables */ 41 | typedef struct Memcontrol { 42 | unsigned long numblocks; 43 | unsigned long total; 44 | unsigned long maxmem; 45 | unsigned long memlimit; 46 | unsigned long objcount[LUA_NUMTAGS]; 47 | } Memcontrol; 48 | 49 | LUA_API Memcontrol l_memcontrol; 50 | 51 | 52 | /* 53 | ** generic variable for debug tricks 54 | */ 55 | extern void *l_Trick; 56 | 57 | 58 | 59 | /* 60 | ** Function to traverse and check all memory used by Lua 61 | */ 62 | int lua_checkmemory (lua_State *L); 63 | 64 | 65 | /* test for lock/unlock */ 66 | 67 | struct L_EXTRA { int lock; int *plock; }; 68 | #undef LUA_EXTRASPACE 69 | #define LUA_EXTRASPACE sizeof(struct L_EXTRA) 70 | #define getlock(l) cast(struct L_EXTRA*, lua_getextraspace(l)) 71 | #define luai_userstateopen(l) \ 72 | (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock)) 73 | #define luai_userstateclose(l) \ 74 | lua_assert(getlock(l)->lock == 1 && getlock(l)->plock == &(getlock(l)->lock)) 75 | #define luai_userstatethread(l,l1) \ 76 | lua_assert(getlock(l1)->plock == getlock(l)->plock) 77 | #define luai_userstatefree(l,l1) \ 78 | lua_assert(getlock(l)->plock == getlock(l1)->plock) 79 | #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0) 80 | #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0) 81 | 82 | 83 | 84 | LUA_API int luaB_opentests (lua_State *L); 85 | 86 | LUA_API void *debug_realloc (void *ud, void *block, 87 | size_t osize, size_t nsize); 88 | 89 | #if defined(lua_c) 90 | #define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol) 91 | #define luaL_openlibs(L) \ 92 | { (luaL_openlibs)(L); luaL_requiref(L, "T", luaB_opentests, 1); } 93 | #endif 94 | 95 | 96 | 97 | /* change some sizes to give some bugs a chance */ 98 | 99 | #undef LUAL_BUFFERSIZE 100 | #define LUAL_BUFFERSIZE 23 101 | #define MINSTRTABSIZE 2 102 | 103 | 104 | /* make stack-overflow tests run faster */ 105 | #undef LUAI_MAXSTACK 106 | #define LUAI_MAXSTACK 50000 107 | 108 | 109 | #undef LUAI_USER_ALIGNMENT_T 110 | #define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; } 111 | 112 | #endif 113 | 114 | -------------------------------------------------------------------------------- /test/lua-5.3-tests/pm.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.3-tests/pm.lua -------------------------------------------------------------------------------- /test/lua-5.3-tests/sort.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.3-tests/sort.lua -------------------------------------------------------------------------------- /test/lua-5.3-tests/strings.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viruscamp/luadec/895d92313fabaee260121c758c8320d1b21dd741/test/lua-5.3-tests/strings.lua -------------------------------------------------------------------------------- /test/lua-5.3-tests/vararg.lua: -------------------------------------------------------------------------------- 1 | -- $Id: vararg.lua,v 1.22 2014/12/26 17:20:53 roberto Exp $ 2 | 3 | print('testing vararg') 4 | 5 | _G.arg = nil 6 | 7 | function f(a, ...) 8 | local arg = {n = select('#', ...), ...} 9 | for i=1,arg.n do assert(a[i]==arg[i]) end 10 | return arg.n 11 | end 12 | 13 | function c12 (...) 14 | assert(arg == nil) 15 | local x = {...}; x.n = #x 16 | local res = (x.n==2 and x[1] == 1 and x[2] == 2) 17 | if res then res = 55 end 18 | return res, 2 19 | end 20 | 21 | function vararg (...) return {n = select('#', ...), ...} end 22 | 23 | local call = function (f, args) return f(table.unpack(args, 1, args.n)) end 24 | 25 | assert(f() == 0) 26 | assert(f({1,2,3}, 1, 2, 3) == 3) 27 | assert(f({"alo", nil, 45, f, nil}, "alo", nil, 45, f, nil) == 5) 28 | 29 | assert(c12(1,2)==55) 30 | a,b = assert(call(c12, {1,2})) 31 | assert(a == 55 and b == 2) 32 | a = call(c12, {1,2;n=2}) 33 | assert(a == 55 and b == 2) 34 | a = call(c12, {1,2;n=1}) 35 | assert(not a) 36 | assert(c12(1,2,3) == false) 37 | local a = vararg(call(next, {_G,nil;n=2})) 38 | local b,c = next(_G) 39 | assert(a[1] == b and a[2] == c and a.n == 2) 40 | a = vararg(call(call, {c12, {1,2}})) 41 | assert(a.n == 2 and a[1] == 55 and a[2] == 2) 42 | a = call(print, {'+'}) 43 | assert(a == nil) 44 | 45 | local t = {1, 10} 46 | function t:f (...) local arg = {...}; return self[...]+#arg end 47 | assert(t:f(1,4) == 3 and t:f(2) == 11) 48 | print('+') 49 | 50 | lim = 20 51 | local i, a = 1, {} 52 | while i <= lim do a[i] = i+0.3; i=i+1 end 53 | 54 | function f(a, b, c, d, ...) 55 | local more = {...} 56 | assert(a == 1.3 and more[1] == 5.3 and 57 | more[lim-4] == lim+0.3 and not more[lim-3]) 58 | end 59 | 60 | function g(a,b,c) 61 | assert(a == 1.3 and b == 2.3 and c == 3.3) 62 | end 63 | 64 | call(f, a) 65 | call(g, a) 66 | 67 | a = {} 68 | i = 1 69 | while i <= lim do a[i] = i; i=i+1 end 70 | assert(call(math.max, a) == lim) 71 | 72 | print("+") 73 | 74 | 75 | -- new-style varargs 76 | 77 | function oneless (a, ...) return ... end 78 | 79 | function f (n, a, ...) 80 | local b 81 | assert(arg == nil) 82 | if n == 0 then 83 | local b, c, d = ... 84 | return a, b, c, d, oneless(oneless(oneless(...))) 85 | else 86 | n, b, a = n-1, ..., a 87 | assert(b == ...) 88 | return f(n, a, ...) 89 | end 90 | end 91 | 92 | a,b,c,d,e = assert(f(10,5,4,3,2,1)) 93 | assert(a==5 and b==4 and c==3 and d==2 and e==1) 94 | 95 | a,b,c,d,e = f(4) 96 | assert(a==nil and b==nil and c==nil and d==nil and e==nil) 97 | 98 | 99 | -- varargs for main chunks 100 | f = load[[ return {...} ]] 101 | x = f(2,3) 102 | assert(x[1] == 2 and x[2] == 3 and x[3] == nil) 103 | 104 | 105 | f = load[[ 106 | local x = {...} 107 | for i=1,select('#', ...) do assert(x[i] == select(i, ...)) end 108 | assert(x[select('#', ...)+1] == nil) 109 | return true 110 | ]] 111 | 112 | assert(f("a", "b", nil, {}, assert)) 113 | assert(f()) 114 | 115 | a = {select(3, table.unpack{10,20,30,40})} 116 | assert(#a == 2 and a[1] == 30 and a[2] == 40) 117 | a = {select(1)} 118 | assert(next(a) == nil) 119 | a = {select(-1, 3, 5, 7)} 120 | assert(a[1] == 7 and a[2] == nil) 121 | a = {select(-2, 3, 5, 7)} 122 | assert(a[1] == 5 and a[2] == 7 and a[3] == nil) 123 | pcall(select, 10000) 124 | pcall(select, -10000) 125 | 126 | 127 | -- bug in 5.2.2 128 | 129 | function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, 130 | p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, 131 | p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, 132 | p31, p32, p33, p34, p35, p36, p37, p38, p39, p40, 133 | p41, p42, p43, p44, p45, p46, p48, p49, p50, ...) 134 | local a1,a2,a3,a4,a5,a6,a7 135 | local a8,a9,a10,a11,a12,a13,a14 136 | end 137 | 138 | -- assertion fail here 139 | f() 140 | 141 | 142 | print('OK') 143 | 144 | -------------------------------------------------------------------------------- /test/lua-5.3-tests/verybig.lua: -------------------------------------------------------------------------------- 1 | -- $Id: verybig.lua,v 1.24 2014/12/26 17:20:53 roberto Exp $ 2 | 3 | print "testing RK" 4 | 5 | -- testing opcodes with RK arguments larger than K limit 6 | local function foo () 7 | local dummy = { 8 | -- fill first 256 entries in table of constants 9 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 10 | 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 11 | 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 12 | 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 13 | 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 14 | 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 15 | 97, 98, 99, 100, 101, 102, 103, 104, 16 | 105, 106, 107, 108, 109, 110, 111, 112, 17 | 113, 114, 115, 116, 117, 118, 119, 120, 18 | 121, 122, 123, 124, 125, 126, 127, 128, 19 | 129, 130, 131, 132, 133, 134, 135, 136, 20 | 137, 138, 139, 140, 141, 142, 143, 144, 21 | 145, 146, 147, 148, 149, 150, 151, 152, 22 | 153, 154, 155, 156, 157, 158, 159, 160, 23 | 161, 162, 163, 164, 165, 166, 167, 168, 24 | 169, 170, 171, 172, 173, 174, 175, 176, 25 | 177, 178, 179, 180, 181, 182, 183, 184, 26 | 185, 186, 187, 188, 189, 190, 191, 192, 27 | 193, 194, 195, 196, 197, 198, 199, 200, 28 | 201, 202, 203, 204, 205, 206, 207, 208, 29 | 209, 210, 211, 212, 213, 214, 215, 216, 30 | 217, 218, 219, 220, 221, 222, 223, 224, 31 | 225, 226, 227, 228, 229, 230, 231, 232, 32 | 233, 234, 235, 236, 237, 238, 239, 240, 33 | 241, 242, 243, 244, 245, 246, 247, 248, 34 | 249, 250, 251, 252, 253, 254, 255, 256, 35 | } 36 | assert(24.5 + 0.6 == 25.1) 37 | local t = {foo = function (self, x) return x + self.x end, x = 10} 38 | t.t = t 39 | assert(t:foo(1.5) == 11.5) 40 | assert(t.t:foo(0.5) == 10.5) -- bug in 5.2 alpha 41 | assert(24.3 == 24.3) 42 | assert((function () return t.x end)() == 10) 43 | end 44 | 45 | 46 | foo() 47 | foo = nil 48 | 49 | if _soft then return 10 end 50 | 51 | print "testing large programs (>64k)" 52 | 53 | -- template to create a very big test file 54 | prog = [[$ 55 | 56 | local a,b 57 | 58 | b = {$1$ 59 | b30009 = 65534, 60 | b30010 = 65535, 61 | b30011 = 65536, 62 | b30012 = 65537, 63 | b30013 = 16777214, 64 | b30014 = 16777215, 65 | b30015 = 16777216, 66 | b30016 = 16777217, 67 | b30017 = 0x7fffff, 68 | b30018 = -0x7fffff, 69 | b30019 = 0x1ffffff, 70 | b30020 = -0x1ffffd, 71 | b30021 = -65534, 72 | b30022 = -65535, 73 | b30023 = -65536, 74 | b30024 = -0xffffff, 75 | b30025 = 15012.5, 76 | $2$ 77 | }; 78 | 79 | assert(b.a50008 == 25004 and b["a11"] == -5.5) 80 | assert(b.a33007 == -16503.5 and b.a50009 == -25004.5) 81 | assert(b["b"..30024] == -0xffffff) 82 | 83 | function b:xxx (a,b) return a+b end 84 | assert(b:xxx(10, 12) == 22) -- pushself with non-constant index 85 | b.xxx = nil 86 | 87 | s = 0; n=0 88 | for a,b in pairs(b) do s=s+b; n=n+1 end 89 | -- with 32-bit floats, exact value of 's' depends on summation order 90 | assert(81800000.0 < s and s < 81860000 and n == 70001) 91 | 92 | a = nil; b = nil 93 | print'+' 94 | 95 | function f(x) b=x end 96 | 97 | a = f{$3$} or 10 98 | 99 | assert(a==10) 100 | assert(b[1] == "a10" and b[2] == 5 and b[#b-1] == "a50009") 101 | 102 | 103 | function xxxx (x) return b[x] end 104 | 105 | assert(xxxx(3) == "a11") 106 | 107 | a = nil; b=nil 108 | xxxx = nil 109 | 110 | return 10 111 | 112 | ]] 113 | 114 | -- functions to fill in the $n$ 115 | 116 | local function sig (x) 117 | return (x % 2 == 0) and '' or '-' 118 | end 119 | 120 | F = { 121 | function () -- $1$ 122 | for i=10,50009 do 123 | io.write('a', i, ' = ', sig(i), 5+((i-10)/2), ',\n') 124 | end 125 | end, 126 | 127 | function () -- $2$ 128 | for i=30026,50009 do 129 | io.write('b', i, ' = ', sig(i), 15013+((i-30026)/2), ',\n') 130 | end 131 | end, 132 | 133 | function () -- $3$ 134 | for i=10,50009 do 135 | io.write('"a', i, '", ', sig(i), 5+((i-10)/2), ',\n') 136 | end 137 | end, 138 | } 139 | 140 | file = os.tmpname() 141 | io.output(file) 142 | for s in string.gmatch(prog, "$([^$]+)") do 143 | local n = tonumber(s) 144 | if not n then io.write(s) else F[n]() end 145 | end 146 | io.close() 147 | result = dofile(file) 148 | assert(os.remove(file)) 149 | print'OK' 150 | return result 151 | 152 | -------------------------------------------------------------------------------- /test/ok_declare/a_er.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a=234 -------------------------------------------------------------------------------- /test/ok_declare/a_ok.lua: -------------------------------------------------------------------------------- 1 | local a=234 -------------------------------------------------------------------------------- /test/ok_declare/a_ok2.lua: -------------------------------------------------------------------------------- 1 | local a 2 | print() 3 | a=234 -------------------------------------------------------------------------------- /test/other/_60000funs_simple.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | local f = function(self) 3 | local a,b,c --1 4 | --local a,b=1,c --1 5 | --local a=1,b,c --1 6 | --local a=1,b=1,c --0 7 | --local d = (a == c and b) --1 8 | return (a == c and b) --1 9 | end 10 | --]] 11 | 12 | local a,b,c --1 13 | --local a,b=1,c --1 14 | --local a=1,b,c --1 15 | --local a=1,b=1,c --0 16 | local d = (a == c and b) --1 17 | 18 | -------------------------------------------------------------------------------- /test/other/_simple_logic.lua: -------------------------------------------------------------------------------- 1 | local a,b 2 | b = (a ~= 0) -------------------------------------------------------------------------------- /test/other/constructs.lua: -------------------------------------------------------------------------------- 1 | 2 | assert(-(1 or 2) == -1 and (1 and 2)+(-1.25 or -4) == 0.75); 3 | -------------------------------------------------------------------------------- /test/other/fortest.lua: -------------------------------------------------------------------------------- 1 | for v = 8,18,1 do 2 | print(v) 3 | end -------------------------------------------------------------------------------- /test/other/fun.lua: -------------------------------------------------------------------------------- 1 | 2 | 3 | local b 4 | local function a() 5 | 6 | local c = 0 7 | local function get() 8 | c=c+1 9 | return c 10 | end 11 | return get 12 | end -------------------------------------------------------------------------------- /test/other/function_compare.lua: -------------------------------------------------------------------------------- 1 | local a, b, c 2 | 3 | function f1() 4 | print('ddd') 5 | end 6 | 7 | function f2(a,b) 8 | print(a,b) 9 | end 10 | 11 | function f3() 12 | local z=a 13 | local y=b 14 | print(z,y) 15 | end 16 | 17 | 18 | function f4(...) 19 | print(...) 20 | local z=a 21 | local y=b 22 | return z,y 23 | end 24 | 25 | function f5(x,y,...) 26 | local f6=function() 27 | print('dfd') 28 | print('dfds') 29 | end 30 | 31 | local f7=function() 32 | f6() 33 | end 34 | 35 | local f8=function() 36 | f6(a,b) 37 | end 38 | end 39 | 40 | -------------------------------------------------------------------------------- /test/other/getmop.lua: -------------------------------------------------------------------------------- 1 | --json = (loadfile "jfjson.lua")() 2 | --json = require("sbjson") 3 | --json = require("json") 4 | json = require("dkjson") 5 | socket = require("socket") 6 | socket.http = require("socket.http") 7 | 8 | local rname=arg[1]; 9 | 10 | local jsonfile = io.open("mop/"..rname..".json","r"); 11 | local jsonstr = jsonfile:read("*a"); 12 | jsonfile:close(); 13 | 14 | local recipes = json.decode(jsonstr); 15 | 16 | function sleep(n) 17 | if n > 0 then os.execute("ping -n " .. tonumber(n + 1) .. " localhost > NUL") end 18 | end 19 | 20 | local success = io.open("mop/"..rname.."/success.txt","w") 21 | local fail = io.open("mop/"..rname.."/fail.txt","w") 22 | 23 | for k,v in ipairs(recipes) do 24 | 25 | local sn = math.random(3,10) 26 | 27 | sleep(sn) 28 | 29 | local name = v.name 30 | local itemno = v.id 31 | print("getting id="..itemno.." name="..name) 32 | local b, c, h = socket.http.request("http://www.wowhead.com/spell="..itemno) 33 | 34 | if b == nil then 35 | print(" fail") 36 | fail:write(itemno, name, "\n") 37 | else 38 | local itemfile,msg = io.open("mop/"..rname.."/spell-"..itemno..".html","w") 39 | itemfile:write(b) 40 | itemfile:close() 41 | print(" success") 42 | success:write(itemno, name, "\n") 43 | end 44 | end 45 | 46 | success:close() 47 | fail:close() -------------------------------------------------------------------------------- /test/other/if_else.lua: -------------------------------------------------------------------------------- 1 | function a(b,c,d) 2 | if b>3 then 3 | c = 4 4 | else 5 | c = 5 6 | end 7 | print(c) 8 | end -------------------------------------------------------------------------------- /test/other/if_else_if.lua: -------------------------------------------------------------------------------- 1 | local a,b,c,d,e 2 | local print = print 3 | if a then 4 | print(a) 5 | elseif b then 6 | print(b) 7 | elseif c then 8 | print(c) 9 | end 10 | 11 | xxx() -------------------------------------------------------------------------------- /test/other/if_not_else.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a=234 3 | local function b() 4 | local print = print 5 | print(a) 6 | if not a then 7 | a=1 8 | else 9 | a=a+1 10 | end 11 | print(a) 12 | end 13 | 14 | return b -------------------------------------------------------------------------------- /test/other/local_and_set.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a=234 -------------------------------------------------------------------------------- /test/other/logic.lua: -------------------------------------------------------------------------------- 1 | local a,b,c,d,e,f,g 2 | 3 | local a = b>c 4 | local d = (e==f) 5 | 6 | --local d = (a and b ) or (not c) -------------------------------------------------------------------------------- /test/other/producelua.lua: -------------------------------------------------------------------------------- 1 | local out = 'local dummy' 2 | local i,j 3 | for i = string.byte('a'),string.byte('a')+21 do 4 | for j = 0,8 do 5 | out = out..' ,'..string.char(i)..j 6 | end 7 | end 8 | print(out) 9 | 10 | out = 'dummy = {"pre"' 11 | for j = 0,100 do 12 | out = out..' ,'..j 13 | end 14 | out = out..'}' 15 | print(out) 16 | -------------------------------------------------------------------------------- /test/other/readchunk.lua: -------------------------------------------------------------------------------- 1 | local chunk = assert(loadfile(arg[1])) 2 | 3 | if chunk then 4 | local out = assert(io.open(arg[2], "wb")) 5 | out:write(string.dump(chunk)) 6 | out:close() 7 | end 8 | -------------------------------------------------------------------------------- /test/other/serialize.lua: -------------------------------------------------------------------------------- 1 | function serialize(t) 2 | local mark={} 3 | local assign={} 4 | 5 | local function ser_table(tbl,parent) 6 | mark[tbl]=parent 7 | local tmp={} 8 | for k,v in pairs(tbl) do 9 | local key= type(k)=="number" and "["..k.."]" or k 10 | if type(v)=="table" then 11 | local dotkey= parent..(type(k)=="number" and key or "."..key) 12 | if mark[v] then 13 | table.insert(assign,dotkey.."="..mark[v]) 14 | else 15 | table.insert(tmp, key.."="..ser_table(v,dotkey)) 16 | end 17 | else 18 | table.insert(tmp, key.."="..v) 19 | end 20 | end 21 | return "{\n"..table.concat(tmp,",").."}\n" 22 | end 23 | 24 | return "do local ret="..ser_table(t,"ret")..table.concat(assign," ").." return ret end" 25 | end 26 | 27 | BFQuest={} 28 | loadfile("todo\\data.luac")() 29 | print(serialize(BFQuest)) 30 | -------------------------------------------------------------------------------- /test/other/table.lua: -------------------------------------------------------------------------------- 1 | local a = {a='ab', b='bc',1,2,3,4,5,6,7,8,9,10,c='cd',11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,d='de'} 2 | 3 | local b = {a='ab', b='bc',c='cd',d='de'} -------------------------------------------------------------------------------- /test/other/test.lua: -------------------------------------------------------------------------------- 1 | local chunk = loadfile("f.lua") 2 | 3 | if chunk then 4 | local b=chunk() 5 | local out = assert(io.open(arg[1], "wb")) 6 | local cb=string.dump(b) 7 | out:write(cb) 8 | out:close() 9 | b() 10 | local fb=loadstring(cb) 11 | fb() 12 | fb() 13 | b() 14 | fb() 15 | end 16 | -------------------------------------------------------------------------------- /test/other/testall.lua: -------------------------------------------------------------------------------- 1 | --is_vararg = 2 2 | --main function is always is_vararg = 2, and can't use arg, arg will be treat as a globol table. 3 | local a,b,n = arg[1],arg[2],arg.n 4 | local c,d = ... 5 | local x = 3 6 | 7 | --is_vararg = 0 8 | local function a() 9 | local x=3 10 | return x 11 | end 12 | 13 | --is_vararg = 3, if ... is used in function 14 | local function b(...) 15 | local a,b,n = arg[1],arg[2],arg.n 16 | local c,d = ... 17 | end 18 | 19 | --is_vararg = 3 20 | local function c(...) 21 | local c,d = ... 22 | end 23 | 24 | --is_vararg = 7, if ... is not used in function 25 | local function d(...) 26 | local a,b,n = arg[1],arg[2],arg.n 27 | end 28 | 29 | --is_vararg = 7 30 | local function e(...) 31 | local x=3 32 | return x 33 | end 34 | 35 | local function f(...) 36 | local x={...} 37 | return x 38 | end 39 | 40 | --table 41 | 42 | -------------------------------------------------------------------------------- /test/other/testindex.lua: -------------------------------------------------------------------------------- 1 | local a,b,c,d,e,f 2 | 3 | local t={ 4 | a=1,[" a"]=2,["not"]=3,[a]=4, 5 | f=function(self) 6 | print(self.a); 7 | end 8 | } 9 | 10 | t.a=5 11 | t[" a"]=6 12 | t["not"]=7 13 | t[a]=8 14 | 15 | b=t.a 16 | c=t[" a"] 17 | d=t["not"] 18 | e=t[a] 19 | 20 | t:f() 21 | -------------------------------------------------------------------------------- /test/other/testup.lua: -------------------------------------------------------------------------------- 1 | local cc, dd=3,4 2 | print(cc+dd) 3 | local a=3 4 | local b=4 5 | 6 | function c() 7 | local c = a+b 8 | return c 9 | end -------------------------------------------------------------------------------- /test/other/txt.lua: -------------------------------------------------------------------------------- 1 | S=[[]] 2 | T={} 3 | C=coroutine.create(function() end) 4 | print(type(S),type(T),type(C)) 5 | print(S>> testC not active: skipping API tests <<<\n\a') 3 | return 4 | end 5 | 6 | ----------- 7 | 8 | do 9 | local map = {} 10 | local t = {__eq = function (a,b) return map[a] == map[b] end} 11 | local function f(x) 12 | local u = T.newuserdata(0) 13 | debug.setmetatable(u, t) 14 | map[u] = x 15 | return u 16 | end 17 | assert(f(10) == f(10)) 18 | assert(f(10) ~= f(11)) 19 | assert(T.testC("equal 2 3; return 1", f(10), f(10))) 20 | assert(not T.testC("equal 2 3; return 1", f(10), f(20))) 21 | t.__eq = nil 22 | assert(f(10) ~= f(10)) 23 | end 24 | 25 | -------------- 26 | 27 | if not a and not string.find(b, "memory") then -- `real' error? 28 | T.totalmem(1000000000) -- restore high limit 29 | error(b, 0) 30 | end 31 | 32 | -------------- 33 | 34 | testamem("dump/undump", function () 35 | local a = loadstring(testprog) 36 | local b = a and string.dump(a) 37 | a = b and loadstring(b) 38 | return a and a() 39 | end) 40 | 41 | ---------------- 42 | 43 | if not trylocale("collate") then 44 | print("locale not supported") 45 | else 46 | assert("alo" < "o" and "o" < "amo") 47 | end 48 | 49 | ----------------- 50 | 51 | local f = function(x,y) 52 | return nil 53 | end -------------------------------------------------------------------------------- /test/todo/vararg.lua: -------------------------------------------------------------------------------- 1 | local function f(...) 2 | local a,b 3 | a,b = ... 4 | c,d = ... 5 | end -------------------------------------------------------------------------------- /test/unluac-test/adjust01.lua: -------------------------------------------------------------------------------- 1 | f((g())) -------------------------------------------------------------------------------- /test/unluac-test/adjust02.lua: -------------------------------------------------------------------------------- 1 | function f(...) 2 | return (g((...))) 3 | end -------------------------------------------------------------------------------- /test/unluac-test/adjust03.lua: -------------------------------------------------------------------------------- 1 | function f(...) 2 | return (g(...)) 3 | end -------------------------------------------------------------------------------- /test/unluac-test/adjust04.lua: -------------------------------------------------------------------------------- 1 | return f() -------------------------------------------------------------------------------- /test/unluac-test/adjust05.lua: -------------------------------------------------------------------------------- 1 | for x in (pairs(t)) do 2 | print(x) 3 | end -------------------------------------------------------------------------------- /test/unluac-test/assign.lua: -------------------------------------------------------------------------------- 1 | local a = 1 2 | local b = 2 3 | local c = 3 4 | -------------------------------------------------------------------------------- /test/unluac-test/booleanassign01.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a = x or y 3 | a = x and y 4 | -------------------------------------------------------------------------------- /test/unluac-test/booleanassign02.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a = w and x and y and z 3 | a = w or x or y or z 4 | a = w and x or y and z 5 | a = (w or x) and (y or z) 6 | a = (b and c or d and e) and (f and g or h and i) or (j and k or l and m) and (n and o or p and q) 7 | -------------------------------------------------------------------------------- /test/unluac-test/booleanassign03.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a = d and e and f and a and g and h and i 3 | a = d or e or f or a or g or h or i 4 | -------------------------------------------------------------------------------- /test/unluac-test/booleanassign04.lua: -------------------------------------------------------------------------------- 1 | x = a and b 2 | x = a or b 3 | x = a and b and c and d 4 | x = a or b or c or d 5 | -------------------------------------------------------------------------------- /test/unluac-test/booleanassign05.lua: -------------------------------------------------------------------------------- 1 | local value = thing.a or thing.b or "default" 2 | print(value) -------------------------------------------------------------------------------- /test/unluac-test/booleanassign06.lua: -------------------------------------------------------------------------------- 1 | if not thing.a and not thing.b then 2 | local value = "default" 3 | end -------------------------------------------------------------------------------- /test/unluac-test/booleanassign07.lua: -------------------------------------------------------------------------------- 1 | if not thing.a and not thing.b then 2 | side_effects() 3 | local value = "default" 4 | end -------------------------------------------------------------------------------- /test/unluac-test/booleanassign08.lua: -------------------------------------------------------------------------------- 1 | local value = "initial" 2 | print(value) 3 | value = thing.a or thing.b or "default" 4 | print(value) -------------------------------------------------------------------------------- /test/unluac-test/booleanassign09.lua: -------------------------------------------------------------------------------- 1 | local result = a < b and not c 2 | print(result) -------------------------------------------------------------------------------- /test/unluac-test/booleanassign10.lua: -------------------------------------------------------------------------------- 1 | local x 2 | if x == nil then 3 | x = (not y) or (z == w) 4 | end 5 | print(x) -------------------------------------------------------------------------------- /test/unluac-test/booleanexpression01.lua: -------------------------------------------------------------------------------- 1 | print(a or b) 2 | print(a and b) 3 | -------------------------------------------------------------------------------- /test/unluac-test/booleanexpression02.lua: -------------------------------------------------------------------------------- 1 | print(a and b, a or b) 2 | -------------------------------------------------------------------------------- /test/unluac-test/booleanexpression03.lua: -------------------------------------------------------------------------------- 1 | print(x == 0 or a.first and a.record.field == value) -------------------------------------------------------------------------------- /test/unluac-test/booleanexpression04.lua: -------------------------------------------------------------------------------- 1 | print((not x) and (a == b) and (y < z)) -------------------------------------------------------------------------------- /test/unluac-test/booleanexpression05.lua: -------------------------------------------------------------------------------- 1 | print(a == b and (c == d or c == e) and f == g) -------------------------------------------------------------------------------- /test/unluac-test/booleanmultiassign01.lua: -------------------------------------------------------------------------------- 1 | local a, b 2 | a, b = a and b, a or b 3 | a, b = a or b, a and b 4 | a, b = b and a, b or a 5 | a, b = b or a, b and a 6 | a, b = x and y, x or y 7 | -------------------------------------------------------------------------------- /test/unluac-test/booleanselfassign01.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a = a or x 3 | a = a and x 4 | y = y or x 5 | y = y and x 6 | -------------------------------------------------------------------------------- /test/unluac-test/closure.lua: -------------------------------------------------------------------------------- 1 | f = function(a, b) 2 | local c = a + b 3 | return c ^ 2 4 | end 5 | print(f(3, 4)) 6 | -------------------------------------------------------------------------------- /test/unluac-test/combinebexpression01.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a = b < c or d < e or f 3 | -------------------------------------------------------------------------------- /test/unluac-test/combinebexpression02.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a = b or c or d == e 3 | -------------------------------------------------------------------------------- /test/unluac-test/combinebexpression03.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a = b or c == d or e 3 | -------------------------------------------------------------------------------- /test/unluac-test/combinebexpression04.lua: -------------------------------------------------------------------------------- 1 | print(a or b or c == d) 2 | print(a or b == c or d) 3 | print(a and b == c or d) 4 | print(a or b == c and d) 5 | print(a or b ~= c or d) 6 | print(a == b or c or d) 7 | print(a < b and c or d) 8 | print(a ~= b or c and d) 9 | print(a == b and c and d) 10 | -------------------------------------------------------------------------------- /test/unluac-test/compareassign01.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a = x < y 3 | -------------------------------------------------------------------------------- /test/unluac-test/compareexpression.lua: -------------------------------------------------------------------------------- 1 | print(x == y) 2 | print(x < y) 3 | print(x <= y) 4 | -------------------------------------------------------------------------------- /test/unluac-test/compareorder01.lua: -------------------------------------------------------------------------------- 1 | if a < b then 2 | print("a < b") 3 | end 4 | if b > a then 5 | print("b > a") 6 | end 7 | -------------------------------------------------------------------------------- /test/unluac-test/compareorder02.lua: -------------------------------------------------------------------------------- 1 | -- In the case of two constants: 2 | -- comparison order is impossible to reproduce from bytecode 3 | -- this case seems unlikely to occur in production code though 4 | -- perhaps guess by the index of the constants? 5 | -- (that could work if both constants are fresh) 6 | if 1 < 2 then 7 | print("1 < 2") 8 | end 9 | if 2 > 1 then 10 | print("2 > 1") 11 | end 12 | -------------------------------------------------------------------------------- /test/unluac-test/compareorder03.lua: -------------------------------------------------------------------------------- 1 | if a < 2 then 2 | print("a < 2") 3 | end 4 | if 2 > a then 5 | print("2 > a") 6 | end 7 | -------------------------------------------------------------------------------- /test/unluac-test/compareorder04.lua: -------------------------------------------------------------------------------- 1 | print("begin") 2 | if not (math.random(100) > chance) then 3 | print("then") 4 | end 5 | print("end") -------------------------------------------------------------------------------- /test/unluac-test/compareorder05.lua: -------------------------------------------------------------------------------- 1 | print("begin") 2 | if math.random(100) <= chance then 3 | print("then") 4 | end 5 | print("end") -------------------------------------------------------------------------------- /test/unluac-test/complexassign01.lua: -------------------------------------------------------------------------------- 1 | if buffer then 2 | print("hello") 3 | end 4 | local single1 = 1 5 | local single2 = 2 6 | local single3 = 3 7 | if buffer then 8 | print("hello") 9 | end 10 | local single4 = 4 11 | local single5 = 5 12 | local single6 = 6 13 | -------------------------------------------------------------------------------- /test/unluac-test/complexassign02.lua: -------------------------------------------------------------------------------- 1 | if buffer then 2 | print("hello") 3 | end 4 | local expr1 = a + b + c + d 5 | local expr2 = expr1 + a + b + c + d 6 | local expr3 = a + b + c + d + expr2 7 | -------------------------------------------------------------------------------- /test/unluac-test/complexassign03.lua: -------------------------------------------------------------------------------- 1 | if buffer then 2 | print("hello") 3 | end 4 | local multi1a, multi1b, multi1c = 1, 2, 3 5 | local multi2a, multi2b, multi2c = multi_return() 6 | local multi3a, multi3b, multi3c = multi_return(x, y, z) 7 | -------------------------------------------------------------------------------- /test/unluac-test/condition.lua: -------------------------------------------------------------------------------- 1 | if a == b and c == d then 2 | f() 3 | end 4 | if a == b or c == d then 5 | f() 6 | end 7 | if a < b then 8 | f() 9 | end 10 | if a <= b then 11 | f() 12 | end 13 | if not a then 14 | f() 15 | end 16 | -------------------------------------------------------------------------------- /test/unluac-test/control01.lua: -------------------------------------------------------------------------------- 1 | if a then 2 | while b do 3 | f() 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /test/unluac-test/control02.lua: -------------------------------------------------------------------------------- 1 | if a then 2 | local x = 3 3 | if b then 4 | print(a, b) 5 | end 6 | print(x) 7 | end -------------------------------------------------------------------------------- /test/unluac-test/control03.lua: -------------------------------------------------------------------------------- 1 | if a then 2 | local x = 3 3 | if b then 4 | print(a, b) 5 | end 6 | end -------------------------------------------------------------------------------- /test/unluac-test/control04.lua: -------------------------------------------------------------------------------- 1 | local y 2 | if x then 3 | while y do 4 | print("hello") 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /test/unluac-test/control05.lua: -------------------------------------------------------------------------------- 1 | for i = 1, 10 do 2 | local x = f() 3 | if a then 4 | local y = g() 5 | if b then 6 | print(b) 7 | end 8 | break 9 | end 10 | end -------------------------------------------------------------------------------- /test/unluac-test/control06.lua: -------------------------------------------------------------------------------- 1 | for item in iter() do 2 | if complicated_condition() then 3 | f() 4 | if additional() then 5 | g() 6 | end 7 | break 8 | end 9 | end -------------------------------------------------------------------------------- /test/unluac-test/control07.lua: -------------------------------------------------------------------------------- 1 | repeat 2 | repeat 3 | f() 4 | until b 5 | g() 6 | until a -------------------------------------------------------------------------------- /test/unluac-test/declare.lua: -------------------------------------------------------------------------------- 1 | local a, b, c 2 | a = 1 3 | b = 2 4 | local d 5 | d = 3 6 | f() 7 | summon = function(bid, count) 8 | if type(bid) == "string" then 9 | bid = beings[bid].nid 10 | end 11 | local last_being 12 | for i = 1, count or 1 do 13 | last_being = Level.drop_being(bid, Level.empty_coord()) 14 | end 15 | return last_being 16 | end 17 | f() 18 | --a, b = a and b, a or b 19 | f() 20 | 21 | --[[while a < c do 22 | if(a == b) then 23 | a = c 24 | else 25 | break 26 | end 27 | end]] --TODO 28 | 29 | --[[while a < c do 30 | if a==b then 31 | c = 3 32 | if c == b then 33 | d = 6 34 | end 35 | end 36 | end]] --FIXED! 37 | 38 | --[[if a==b then 39 | if c==d then 40 | a = 4 41 | if a == c then 42 | a, b = 2, 3 43 | end 44 | end 45 | else 46 | c = 6 47 | end]] --FIXED! 48 | 49 | --[[while a == b do 50 | if c == d then 51 | c = 6 52 | end 53 | break 54 | end]] --OKAY because compiles as 55 | --[[while a == b and c == d do 56 | c = 6 57 | break 58 | end]] 59 | 60 | a, b, c, d = b, c, d, a 61 | return f() -------------------------------------------------------------------------------- /test/unluac-test/declare02.lua: -------------------------------------------------------------------------------- 1 | print("begin") 2 | local x, y, z 3 | print("begin") 4 | local a, b, c 5 | c = 4 6 | print(c) 7 | local d, e, f 8 | d = 8 9 | print(d) -------------------------------------------------------------------------------- /test/unluac-test/declare03.lua: -------------------------------------------------------------------------------- 1 | print("begin") 2 | local x, y, z -------------------------------------------------------------------------------- /test/unluac-test/doend01.lua: -------------------------------------------------------------------------------- 1 | do 2 | local a = 512 3 | print(a) 4 | end 5 | do 6 | local b = 255 7 | print(b) 8 | end -------------------------------------------------------------------------------- /test/unluac-test/doend02.lua: -------------------------------------------------------------------------------- 1 | while x do 2 | local v, w = 0 3 | print(w, v) 4 | end -------------------------------------------------------------------------------- /test/unluac-test/doend03.lua: -------------------------------------------------------------------------------- 1 | for x, y in pairs(t) do 2 | local v, w = 0 3 | print(w, v) 4 | end -------------------------------------------------------------------------------- /test/unluac-test/doend04.lua: -------------------------------------------------------------------------------- 1 | for z=1,6 do 2 | local v, w = 0 3 | print(w, v, z) 4 | end -------------------------------------------------------------------------------- /test/unluac-test/doend05.lua: -------------------------------------------------------------------------------- 1 | repeat 2 | local v, w = 0 3 | print(w, v) 4 | until x < 100 5 | -------------------------------------------------------------------------------- /test/unluac-test/ellipsis.lua: -------------------------------------------------------------------------------- 1 | local a, b, c 2 | a = ... 3 | a, b = ... 4 | a, b = ..., 2 5 | a, b, c = 1, ... 6 | a, b, c = ... 7 | -------------------------------------------------------------------------------- /test/unluac-test/expression.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a = x + y + z 3 | a = x + (y + z) 4 | a = x + y - z 5 | a = x - y + z 6 | a = x - y - z 7 | a = x - (y - z) 8 | a = x * y * z 9 | a = x * (y * z) 10 | a = x + y * z 11 | a = (z + y) / z 12 | a = x % (y + z) 13 | a = x ^ y ^ z 14 | a = (x ^ y) ^ z 15 | a = x .. y .. z 16 | a = (x .. y) .. z 17 | -------------------------------------------------------------------------------- /test/unluac-test/final01.lua: -------------------------------------------------------------------------------- 1 | if x then 2 | do return end 3 | print(x) 4 | end -------------------------------------------------------------------------------- /test/unluac-test/final02.lua: -------------------------------------------------------------------------------- 1 | while x > 0 do 2 | do break end 3 | print(x) 4 | x = x - 1 5 | end -------------------------------------------------------------------------------- /test/unluac-test/functioncall.lua: -------------------------------------------------------------------------------- 1 | local a, b, c 2 | a = f(1, 2, 3) 3 | a = f(x, y, z) 4 | a, b = f(1, 2, 3) 5 | a, b, c = 1, f(1, 2, 3) 6 | a, b, c = f(1, 2, 3), 1, 2 7 | a = f(g()) 8 | -------------------------------------------------------------------------------- /test/unluac-test/ifthen.lua: -------------------------------------------------------------------------------- 1 | local a, b 2 | if a then 3 | print(a) 4 | end 5 | if a == b then 6 | local c = a + b 7 | print(c ^ 2) 8 | end 9 | if a and b and x and y then 10 | print(a + x, b + y) 11 | end 12 | if a or b or x or y then 13 | print(a * x, b * y) 14 | end 15 | if (a or b) and (x or y) then 16 | print(a * x, b - y) 17 | end 18 | -------------------------------------------------------------------------------- /test/unluac-test/ifthenelse.lua: -------------------------------------------------------------------------------- 1 | if a then 2 | f() 3 | else 4 | g() 5 | end 6 | if b then 7 | f() 8 | if a then 9 | g() 10 | end 11 | else 12 | h() 13 | end 14 | if a then 15 | if b then 16 | f() 17 | else 18 | h() 19 | end 20 | g() 21 | end 22 | -------------------------------------------------------------------------------- /test/unluac-test/literal.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a = 5 3 | a = 2.5 4 | a = "hello" 5 | a = false 6 | a = true 7 | a = nil 8 | -------------------------------------------------------------------------------- /test/unluac-test/literallist.lua: -------------------------------------------------------------------------------- 1 | x = {1, 2 | 2, 3 | 7, 4 | "frog", 5 | z, 6 | y * w, 7 | 99} 8 | -------------------------------------------------------------------------------- /test/unluac-test/localbooleanassign.lua: -------------------------------------------------------------------------------- 1 | local armor = being.eq.armor 2 | local boots = being.eq.boots 3 | if not armor and not boots then 4 | being:msg( "You have no armor to fix! Nothing happens." ) 5 | return 6 | end 7 | local damaged_armor = armor and armor:is_damaged() 8 | local damaged_boots = boots and boots:is_damaged() 9 | if not damaged_armor and not damaged_boots then 10 | being:msg( "You have no armor that needs fixing! Nothing happens." ) 11 | return 12 | end 13 | ui.blink( YELLOW, 20 ) 14 | -------------------------------------------------------------------------------- /test/unluac-test/localfunction01.lua: -------------------------------------------------------------------------------- 1 | local function factorial(n) 2 | if n == 0 then 3 | return 1 4 | else 5 | return factorial(n - 1) * n 6 | end 7 | end 8 | print(factorial(10)) 9 | -------------------------------------------------------------------------------- /test/unluac-test/localfunction02.lua: -------------------------------------------------------------------------------- 1 | local factorial = function(n) 2 | if n == 0 then 3 | return 1 4 | else 5 | return factorial(n - 1) * n 6 | end 7 | end 8 | print(factorial(10)) 9 | -------------------------------------------------------------------------------- /test/unluac-test/localfunction03.lua: -------------------------------------------------------------------------------- 1 | local function factorial(n) 2 | return "not recursive" 3 | end 4 | print(factorial(10)) 5 | -------------------------------------------------------------------------------- /test/unluac-test/localfunction04.lua: -------------------------------------------------------------------------------- 1 | local factorial = function(n) 2 | return "not recursive" 3 | end 4 | print(factorial(10)) 5 | -------------------------------------------------------------------------------- /test/unluac-test/method01.lua: -------------------------------------------------------------------------------- 1 | function class:method(x) 2 | self:other_method(x) 3 | end -------------------------------------------------------------------------------- /test/unluac-test/multiassign.lua: -------------------------------------------------------------------------------- 1 | local a, b, c, d 2 | a, b = b, a 3 | a, b, c, d = b, c, d, a 4 | -------------------------------------------------------------------------------- /test/unluac-test/multiliteraltarget.lua: -------------------------------------------------------------------------------- 1 | local a 2 | a = {f()} 3 | -------------------------------------------------------------------------------- /test/unluac-test/nestedif.lua: -------------------------------------------------------------------------------- 1 | if x and y then 2 | f() 3 | if z then 4 | g() 5 | end 6 | end 7 | if x and y then 8 | if z then 9 | g() 10 | end 11 | f() 12 | end 13 | if x then 14 | f() 15 | if y then 16 | if z then 17 | g() 18 | end 19 | h() 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /test/unluac-test/nestedif02.lua: -------------------------------------------------------------------------------- 1 | if a then 2 | print(a) 3 | if b then 4 | print(b) 5 | if c then 6 | print(c) 7 | else 8 | print(z) 9 | end 10 | else 11 | print(y) 12 | end 13 | else 14 | print(x) 15 | end -------------------------------------------------------------------------------- /test/unluac-test/repeat.lua: -------------------------------------------------------------------------------- 1 | repeat 2 | f() 3 | until a 4 | repeat 5 | if b then 6 | f() 7 | end 8 | until a 9 | repeat 10 | repeat 11 | f() 12 | until b 13 | g() 14 | until a 15 | repeat 16 | f() 17 | repeat 18 | g() 19 | until b 20 | until a 21 | -------------------------------------------------------------------------------- /test/unluac-test/table01.lua: -------------------------------------------------------------------------------- 1 | local x 2 | x = {} 3 | x.first = 1 4 | x.second = 2 5 | x.third = 3 6 | y = {first = 1, 7 | second = 2, 8 | third = 3} 9 | -------------------------------------------------------------------------------- /test/unluac-test/table02.lua: -------------------------------------------------------------------------------- 1 | if buffer then 2 | print("buffer") 3 | end 4 | local x = {table_elt = 6} 5 | local list = {1, 6 | 6, 7 | 3, 8 | 2, 9 | 6, 10 | 3, 11 | 2, 12 | 6, 13 | 6} 14 | -------------------------------------------------------------------------------- /test/unluac-test/while.lua: -------------------------------------------------------------------------------- 1 | while a do 2 | f() 3 | end 4 | while a do 5 | if b then 6 | f() 7 | end 8 | end 9 | while a do 10 | while b do 11 | f() 12 | end 13 | g() 14 | end 15 | while a do 16 | f() 17 | while b do 18 | g() 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /test/while/if_while_break.lua: -------------------------------------------------------------------------------- 1 | if a then 2 | while 1 do 3 | f1() 4 | break 5 | end 6 | end 7 | 8 | f() 9 | 10 | if a then 11 | f1() 12 | else 13 | while 1 do 14 | f2() 15 | break 16 | end 17 | end 18 | 19 | f() 20 | 21 | -------------------------------------------------------------------------------- /test/while/until.lua: -------------------------------------------------------------------------------- 1 | function a() 2 | local a,b,c 3 | repeat 4 | a = 3 5 | until b and f() 6 | end 7 | 8 | function b() 9 | local a,b,c 10 | repeat 11 | repeat 12 | a = 3 13 | until b 14 | until f() 15 | end -------------------------------------------------------------------------------- /test/while/while-if.lua: -------------------------------------------------------------------------------- 1 | local a,b; 2 | 3 | while a and b do 4 | f() 5 | end 6 | 7 | while a do 8 | if b then 9 | f() 10 | end 11 | end 12 | 13 | while a do 14 | while b do 15 | f() 16 | end 17 | end -------------------------------------------------------------------------------- /test/while/while.lua: -------------------------------------------------------------------------------- 1 | function f1() 2 | local a,f 3 | while a do 4 | f() 5 | end 6 | --[[ 7 | 0 [-]: TEST R0 0 ; if R0 then PC := 2 else PC := 5 8 | 1 [-]: JMP 5 ; PC := 5 9 | 2 [-]: MOVE R2 R1 ; R2 := R1 10 | 3 [-]: CALL R2 1 1 ; R2() 11 | 4 [-]: JMP 0 ; PC := 0 12 | 5 [-]: RETURN R0 1 ; return 13 | --]] 14 | end 15 | 16 | function f2() 17 | local a,f 18 | while 1 do 19 | if a then 20 | else 21 | break 22 | end 23 | f() 24 | end 25 | --[[ 26 | 4--> 3 27 | 8--> 7 28 | 0 [-]: TEST R0 0 ; if R0 then PC := 2 else PC := 7 29 | 1 [-]: JMP 7 ; PC := 7 30 | 2 [-]: JMP 4 ; PC := 4 31 | 3 [-]: JMP 7 ; PC := 7 32 | 4 [-]: MOVE R2 R1 ; R2 := R1 33 | 5 [-]: CALL R2 1 1 ; R2() 34 | 6 [-]: JMP 0 ; PC := 0 35 | 7 [-]: RETURN R0 1 ; return 36 | --]] 37 | end 38 | 39 | function f3() 40 | local a,f 41 | while 1 do 42 | if a then 43 | f() 44 | else 45 | break 46 | end 47 | end 48 | --[[ 49 | 0 [-]: TEST R0 0 ; if R0 then PC := 2 else PC := 7 50 | 1 [-]: JMP 7 ; PC := 7 51 | 2 [-]: MOVE R2 R1 ; R2 := R1 52 | 3 [-]: CALL R2 1 1 ; R2() 53 | 4 [-]: JMP 0 ; PC := 0 54 | 5 [-]: JMP 7 ; PC := 7 55 | 6 [-]: JMP 0 ; PC := 0 56 | 7 [-]: RETURN R0 1 ; return 57 | --]] 58 | end 59 | 60 | function f4() 61 | local a,b,c,d,e,f,g 62 | while a do 63 | g() 64 | if b then 65 | f() 66 | end 67 | end 68 | end -------------------------------------------------------------------------------- /test/while/while1-if-else-break.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | 3 | while 1 do 4 | if a then 5 | print(a) 6 | else 7 | break 8 | end 9 | print(c) 10 | end 11 | -------------------------------------------------------------------------------- /test/while/while1-if-else.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | 3 | while 1 do 4 | if a then 5 | print(a) 6 | else 7 | print(b) 8 | end 9 | print(c) 10 | end -------------------------------------------------------------------------------- /test/while/while1-if.lua: -------------------------------------------------------------------------------- 1 | local a,b 2 | 3 | while 1 do 4 | if a then 5 | print(a) 6 | end 7 | print(b) 8 | end 9 | -------------------------------------------------------------------------------- /test/while/while1-while.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | 3 | while 1 do 4 | while a do 5 | print(a) 6 | end 7 | print(c) 8 | end 9 | 10 | --[[ 11 | while 1 do 12 | if a then 13 | print(a) 14 | continue 15 | end 16 | print(c) 17 | end 18 | --]] 19 | 20 | --[[ 21 | while a do 22 | xxx 23 | end 24 | 25 | while 1 do 26 | if a then 27 | donothing 28 | else 29 | break; 30 | end 31 | xxx 32 | end 33 | --]] -------------------------------------------------------------------------------- /test/while/while1.lua: -------------------------------------------------------------------------------- 1 | local a,b,c 2 | 3 | while 1 do 4 | local d,e 5 | print(c) 6 | end --------------------------------------------------------------------------------