immunio 0.15.4 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +0 -27
- data/ext/immunio/Rakefile +9 -0
- data/lib/immunio/plugins/active_record.rb +1 -1
- data/lib/immunio/plugins/active_record_relation.rb +1 -1
- data/lib/immunio/plugins/environment_reporter.rb +20 -0
- data/lib/immunio/rufus_lua_ext/ref.rb +1 -3
- data/lib/immunio/version.rb +1 -1
- data/lib/immunio/vm.rb +1 -2
- data/lua-hooks/Makefile +97 -0
- data/lua-hooks/ext/all.c +41 -52
- data/lua-hooks/ext/all.o +0 -0
- data/lua-hooks/ext/libinjection/libinjection_html5.o +0 -0
- data/lua-hooks/ext/libinjection/libinjection_sqli.o +0 -0
- data/lua-hooks/ext/libinjection/libinjection_xss.o +0 -0
- data/lua-hooks/ext/libinjection/lualib.c +2 -2
- data/lua-hooks/ext/lpeg/lpcap.c +2 -2
- data/lua-hooks/ext/lpeg/lpcap.o +0 -0
- data/lua-hooks/ext/lpeg/lpcode.c +2 -2
- data/lua-hooks/ext/lpeg/lpcode.h +1 -1
- data/lua-hooks/ext/lpeg/lpcode.o +0 -0
- data/lua-hooks/ext/lpeg/lpprint.o +0 -0
- data/lua-hooks/ext/lpeg/lptree.c +2 -2
- data/lua-hooks/ext/lpeg/lptypes.h +1 -1
- data/lua-hooks/ext/lpeg/lpvm.c +2 -2
- data/lua-hooks/ext/lpeg/lpvm.o +0 -0
- data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +16 -3
- data/lua-hooks/ext/lua-snapshot/snapshot.c +14 -7
- data/lua-hooks/ext/luajit/COPYRIGHT +56 -0
- data/lua-hooks/ext/luajit/Makefile +159 -0
- data/lua-hooks/ext/luajit/README +16 -0
- data/lua-hooks/ext/luajit/doc/bluequad-print.css +166 -0
- data/lua-hooks/ext/luajit/doc/bluequad.css +325 -0
- data/lua-hooks/ext/luajit/doc/changes.html +804 -0
- data/lua-hooks/ext/luajit/doc/contact.html +104 -0
- data/lua-hooks/ext/luajit/doc/ext_c_api.html +189 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi.html +332 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +570 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +1261 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +603 -0
- data/lua-hooks/ext/luajit/doc/ext_jit.html +201 -0
- data/lua-hooks/ext/luajit/doc/ext_profiler.html +365 -0
- data/lua-hooks/ext/luajit/doc/extensions.html +448 -0
- data/lua-hooks/ext/luajit/doc/faq.html +186 -0
- data/lua-hooks/ext/luajit/doc/img/contact.png +0 -0
- data/lua-hooks/ext/luajit/doc/install.html +659 -0
- data/lua-hooks/ext/luajit/doc/luajit.html +236 -0
- data/lua-hooks/ext/luajit/doc/running.html +309 -0
- data/lua-hooks/ext/luajit/doc/status.html +118 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +456 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1125 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +518 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1166 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +416 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +953 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +419 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1919 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +83 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +12 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +471 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +1945 -0
- data/lua-hooks/ext/luajit/dynasm/dynasm.lua +1094 -0
- data/lua-hooks/ext/luajit/etc/luajit.1 +88 -0
- data/lua-hooks/ext/luajit/etc/luajit.pc +25 -0
- data/lua-hooks/ext/luajit/src/Makefile +697 -0
- data/lua-hooks/ext/luajit/src/Makefile.dep +244 -0
- data/lua-hooks/ext/luajit/src/host/README +4 -0
- data/lua-hooks/ext/luajit/src/host/buildvm +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm.c +518 -0
- data/lua-hooks/ext/luajit/src/host/buildvm.h +105 -0
- data/lua-hooks/ext/luajit/src/host/buildvm.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_arch.h +7449 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +345 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_asm.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +229 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_fold.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +457 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_lib.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +45 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +368 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_peobj.o +0 -0
- data/lua-hooks/ext/luajit/src/host/genlibbc.lua +197 -0
- data/lua-hooks/ext/luajit/src/host/genminilua.lua +428 -0
- data/lua-hooks/ext/luajit/src/host/minilua +0 -0
- data/lua-hooks/ext/luajit/src/host/minilua.c +7770 -0
- data/lua-hooks/ext/luajit/src/host/minilua.o +0 -0
- data/lua-hooks/ext/luajit/src/jit/bc.lua +190 -0
- data/lua-hooks/ext/luajit/src/jit/bcsave.lua +661 -0
- data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +689 -0
- data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +428 -0
- data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +17 -0
- data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +591 -0
- data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +17 -0
- data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +838 -0
- data/lua-hooks/ext/luajit/src/jit/dump.lua +706 -0
- data/lua-hooks/ext/luajit/src/jit/p.lua +310 -0
- data/lua-hooks/ext/luajit/src/jit/v.lua +170 -0
- data/lua-hooks/ext/luajit/src/jit/vmdef.lua +362 -0
- data/lua-hooks/ext/luajit/src/jit/zone.lua +45 -0
- data/lua-hooks/ext/{lua → luajit/src}/lauxlib.h +10 -17
- data/lua-hooks/ext/luajit/src/lib_aux.c +356 -0
- data/lua-hooks/ext/luajit/src/lib_aux.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_aux_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_base.c +664 -0
- data/lua-hooks/ext/luajit/src/lib_base.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_base_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_bit.c +180 -0
- data/lua-hooks/ext/luajit/src/lib_bit.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_bit_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_debug.c +405 -0
- data/lua-hooks/ext/luajit/src/lib_debug.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_debug_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_ffi.c +872 -0
- data/lua-hooks/ext/luajit/src/lib_ffi.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_ffi_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_init.c +55 -0
- data/lua-hooks/ext/luajit/src/lib_init.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_init_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_io.c +541 -0
- data/lua-hooks/ext/luajit/src/lib_io.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_io_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_jit.c +767 -0
- data/lua-hooks/ext/luajit/src/lib_jit.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_jit_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_math.c +230 -0
- data/lua-hooks/ext/luajit/src/lib_math.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_math_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_os.c +292 -0
- data/lua-hooks/ext/luajit/src/lib_os.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_os_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_package.c +610 -0
- data/lua-hooks/ext/luajit/src/lib_package.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_package_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_string.c +752 -0
- data/lua-hooks/ext/luajit/src/lib_string.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_string_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_table.c +307 -0
- data/lua-hooks/ext/luajit/src/lib_table.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_table_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/libluajit.a +0 -0
- data/lua-hooks/ext/luajit/src/libluajit.so +0 -0
- data/lua-hooks/ext/luajit/src/lj.supp +26 -0
- data/lua-hooks/ext/luajit/src/lj_alloc.c +1398 -0
- data/lua-hooks/ext/luajit/src/lj_alloc.h +17 -0
- data/lua-hooks/ext/luajit/src/lj_alloc.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_alloc_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_api.c +1210 -0
- data/lua-hooks/ext/luajit/src/lj_api.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_api_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_arch.h +509 -0
- data/lua-hooks/ext/luajit/src/lj_asm.c +2278 -0
- data/lua-hooks/ext/luajit/src/lj_asm.h +17 -0
- data/lua-hooks/ext/luajit/src/lj_asm.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_asm_arm.h +2217 -0
- data/lua-hooks/ext/luajit/src/lj_asm_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_asm_mips.h +1833 -0
- data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +2015 -0
- data/lua-hooks/ext/luajit/src/lj_asm_x86.h +2634 -0
- data/lua-hooks/ext/luajit/src/lj_bc.c +14 -0
- data/lua-hooks/ext/luajit/src/lj_bc.h +265 -0
- data/lua-hooks/ext/luajit/src/lj_bc.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bc_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcdef.h +220 -0
- data/lua-hooks/ext/luajit/src/lj_bcdump.h +68 -0
- data/lua-hooks/ext/luajit/src/lj_bcread.c +457 -0
- data/lua-hooks/ext/luajit/src/lj_bcread.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcread_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcwrite.c +361 -0
- data/lua-hooks/ext/luajit/src/lj_bcwrite.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcwrite_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_buf.c +234 -0
- data/lua-hooks/ext/luajit/src/lj_buf.h +105 -0
- data/lua-hooks/ext/luajit/src/lj_buf.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_buf_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_carith.c +429 -0
- data/lua-hooks/ext/luajit/src/lj_carith.h +37 -0
- data/lua-hooks/ext/luajit/src/lj_carith.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_carith_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccall.c +984 -0
- data/lua-hooks/ext/luajit/src/lj_ccall.h +178 -0
- data/lua-hooks/ext/luajit/src/lj_ccall.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccall_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback.c +712 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback.h +25 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cconv.c +752 -0
- data/lua-hooks/ext/luajit/src/lj_cconv.h +70 -0
- data/lua-hooks/ext/luajit/src/lj_cconv.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cconv_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cdata.c +288 -0
- data/lua-hooks/ext/luajit/src/lj_cdata.h +76 -0
- data/lua-hooks/ext/luajit/src/lj_cdata.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cdata_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_char.c +43 -0
- data/lua-hooks/ext/luajit/src/lj_char.h +42 -0
- data/lua-hooks/ext/luajit/src/lj_char.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_char_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_clib.c +418 -0
- data/lua-hooks/ext/luajit/src/lj_clib.h +29 -0
- data/lua-hooks/ext/luajit/src/lj_clib.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_clib_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cparse.c +1862 -0
- data/lua-hooks/ext/luajit/src/lj_cparse.h +65 -0
- data/lua-hooks/ext/luajit/src/lj_cparse.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cparse_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_crecord.c +1834 -0
- data/lua-hooks/ext/luajit/src/lj_crecord.h +38 -0
- data/lua-hooks/ext/luajit/src/lj_crecord.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_crecord_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ctype.c +635 -0
- data/lua-hooks/ext/luajit/src/lj_ctype.h +461 -0
- data/lua-hooks/ext/luajit/src/lj_ctype.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ctype_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_debug.c +699 -0
- data/lua-hooks/ext/luajit/src/lj_debug.h +65 -0
- data/lua-hooks/ext/luajit/src/lj_debug.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_debug_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_def.h +365 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch.c +557 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch.h +138 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_emit_arm.h +356 -0
- data/lua-hooks/ext/luajit/src/lj_emit_mips.h +211 -0
- data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +238 -0
- data/lua-hooks/ext/luajit/src/lj_emit_x86.h +462 -0
- data/lua-hooks/ext/luajit/src/lj_err.c +794 -0
- data/lua-hooks/ext/luajit/src/lj_err.h +41 -0
- data/lua-hooks/ext/luajit/src/lj_err.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_err_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_errmsg.h +190 -0
- data/lua-hooks/ext/luajit/src/lj_ff.h +18 -0
- data/lua-hooks/ext/luajit/src/lj_ffdef.h +209 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord.c +1247 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord.h +24 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_folddef.h +1138 -0
- data/lua-hooks/ext/luajit/src/lj_frame.h +259 -0
- data/lua-hooks/ext/luajit/src/lj_func.c +185 -0
- data/lua-hooks/ext/luajit/src/lj_func.h +24 -0
- data/lua-hooks/ext/luajit/src/lj_func.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_func_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gc.c +845 -0
- data/lua-hooks/ext/luajit/src/lj_gc.h +134 -0
- data/lua-hooks/ext/luajit/src/lj_gc.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gc_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit.c +787 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit.h +22 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ir.c +505 -0
- data/lua-hooks/ext/luajit/src/lj_ir.h +577 -0
- data/lua-hooks/ext/luajit/src/lj_ir.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ir_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ircall.h +321 -0
- data/lua-hooks/ext/luajit/src/lj_iropt.h +161 -0
- data/lua-hooks/ext/luajit/src/lj_jit.h +440 -0
- data/lua-hooks/ext/luajit/src/lj_lex.c +482 -0
- data/lua-hooks/ext/luajit/src/lj_lex.h +86 -0
- data/lua-hooks/ext/luajit/src/lj_lex.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_lex_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_lib.c +303 -0
- data/lua-hooks/ext/luajit/src/lj_lib.h +115 -0
- data/lua-hooks/ext/luajit/src/lj_lib.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_lib_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_libdef.h +414 -0
- data/lua-hooks/ext/luajit/src/lj_load.c +168 -0
- data/lua-hooks/ext/luajit/src/lj_load.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_load_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_mcode.c +386 -0
- data/lua-hooks/ext/luajit/src/lj_mcode.h +30 -0
- data/lua-hooks/ext/luajit/src/lj_mcode.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_mcode_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_meta.c +477 -0
- data/lua-hooks/ext/luajit/src/lj_meta.h +38 -0
- data/lua-hooks/ext/luajit/src/lj_meta.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_meta_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_obj.c +50 -0
- data/lua-hooks/ext/luajit/src/lj_obj.h +976 -0
- data/lua-hooks/ext/luajit/src/lj_obj.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_obj_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_dce.c +78 -0
- data/lua-hooks/ext/luajit/src/lj_opt_dce.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_dce_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_fold.c +2488 -0
- data/lua-hooks/ext/luajit/src/lj_opt_fold.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_fold_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_loop.c +449 -0
- data/lua-hooks/ext/luajit/src/lj_opt_loop.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_loop_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_mem.c +935 -0
- data/lua-hooks/ext/luajit/src/lj_opt_mem.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_mem_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +652 -0
- data/lua-hooks/ext/luajit/src/lj_opt_narrow.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_narrow_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_sink.c +245 -0
- data/lua-hooks/ext/luajit/src/lj_opt_sink.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_sink_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_split.c +856 -0
- data/lua-hooks/ext/luajit/src/lj_opt_split.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_split_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_parse.c +2725 -0
- data/lua-hooks/ext/luajit/src/lj_parse.h +18 -0
- data/lua-hooks/ext/luajit/src/lj_parse.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_parse_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_profile.c +368 -0
- data/lua-hooks/ext/luajit/src/lj_profile.h +21 -0
- data/lua-hooks/ext/luajit/src/lj_profile.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_profile_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_recdef.h +270 -0
- data/lua-hooks/ext/luajit/src/lj_record.c +2554 -0
- data/lua-hooks/ext/luajit/src/lj_record.h +45 -0
- data/lua-hooks/ext/luajit/src/lj_record.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_record_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_snap.c +870 -0
- data/lua-hooks/ext/luajit/src/lj_snap.h +34 -0
- data/lua-hooks/ext/luajit/src/lj_snap.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_snap_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_state.c +300 -0
- data/lua-hooks/ext/luajit/src/lj_state.h +35 -0
- data/lua-hooks/ext/luajit/src/lj_state.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_state_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_str.c +197 -0
- data/lua-hooks/ext/luajit/src/lj_str.h +27 -0
- data/lua-hooks/ext/luajit/src/lj_str.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_str_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt.c +554 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt.h +125 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strscan.c +547 -0
- data/lua-hooks/ext/luajit/src/lj_strscan.h +39 -0
- data/lua-hooks/ext/luajit/src/lj_strscan.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strscan_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_tab.c +666 -0
- data/lua-hooks/ext/luajit/src/lj_tab.h +73 -0
- data/lua-hooks/ext/luajit/src/lj_tab.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_tab_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_target.h +164 -0
- data/lua-hooks/ext/luajit/src/lj_target_arm.h +270 -0
- data/lua-hooks/ext/luajit/src/lj_target_arm64.h +97 -0
- data/lua-hooks/ext/luajit/src/lj_target_mips.h +260 -0
- data/lua-hooks/ext/luajit/src/lj_target_ppc.h +280 -0
- data/lua-hooks/ext/luajit/src/lj_target_x86.h +345 -0
- data/lua-hooks/ext/luajit/src/lj_trace.c +859 -0
- data/lua-hooks/ext/luajit/src/lj_trace.h +54 -0
- data/lua-hooks/ext/luajit/src/lj_trace.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_trace_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_traceerr.h +63 -0
- data/lua-hooks/ext/luajit/src/lj_udata.c +34 -0
- data/lua-hooks/ext/luajit/src/lj_udata.h +14 -0
- data/lua-hooks/ext/luajit/src/lj_udata.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_udata_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vm.S +2730 -0
- data/lua-hooks/ext/luajit/src/lj_vm.h +114 -0
- data/lua-hooks/ext/luajit/src/lj_vm.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vm_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent.c +58 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent.h +59 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmmath.c +152 -0
- data/lua-hooks/ext/luajit/src/lj_vmmath.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmmath_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/ljamalg.c +96 -0
- data/lua-hooks/ext/{lua → luajit/src}/lua.h +12 -7
- data/lua-hooks/ext/luajit/src/lua.hpp +9 -0
- data/lua-hooks/ext/luajit/src/luaconf.h +156 -0
- data/lua-hooks/ext/luajit/src/luajit +0 -0
- data/lua-hooks/ext/luajit/src/luajit.c +570 -0
- data/lua-hooks/ext/luajit/src/luajit.h +79 -0
- data/lua-hooks/ext/luajit/src/luajit.o +0 -0
- data/lua-hooks/ext/luajit/src/lualib.h +43 -0
- data/lua-hooks/ext/luajit/src/msvcbuild.bat +114 -0
- data/lua-hooks/ext/luajit/src/ps4build.bat +103 -0
- data/lua-hooks/ext/luajit/src/psvitabuild.bat +93 -0
- data/lua-hooks/ext/luajit/src/vm_arm.dasc +4585 -0
- data/lua-hooks/ext/luajit/src/vm_arm64.dasc +3764 -0
- data/lua-hooks/ext/luajit/src/vm_mips.dasc +4355 -0
- data/lua-hooks/ext/luajit/src/vm_ppc.dasc +5252 -0
- data/lua-hooks/ext/luajit/src/vm_x64.dasc +4902 -0
- data/lua-hooks/ext/luajit/src/vm_x86.dasc +5710 -0
- data/lua-hooks/ext/luajit/src/xb1build.bat +101 -0
- data/lua-hooks/ext/luajit/src/xedkbuild.bat +92 -0
- data/lua-hooks/ext/luautf8/lutf8lib.c +3 -3
- data/lua-hooks/lib/boot.lua +37 -2
- metadata +372 -69
- data/lua-hooks/ext/bitop/README +0 -22
- data/lua-hooks/ext/bitop/bit.c +0 -189
- data/lua-hooks/ext/extconf.rb +0 -38
- data/lua-hooks/ext/lua/COPYRIGHT +0 -34
- data/lua-hooks/ext/lua/lapi.c +0 -1087
- data/lua-hooks/ext/lua/lapi.h +0 -16
- data/lua-hooks/ext/lua/lauxlib.c +0 -652
- data/lua-hooks/ext/lua/lbaselib.c +0 -659
- data/lua-hooks/ext/lua/lcode.c +0 -831
- data/lua-hooks/ext/lua/lcode.h +0 -76
- data/lua-hooks/ext/lua/ldblib.c +0 -398
- data/lua-hooks/ext/lua/ldebug.c +0 -638
- data/lua-hooks/ext/lua/ldebug.h +0 -33
- data/lua-hooks/ext/lua/ldo.c +0 -519
- data/lua-hooks/ext/lua/ldo.h +0 -57
- data/lua-hooks/ext/lua/ldump.c +0 -164
- data/lua-hooks/ext/lua/lfunc.c +0 -174
- data/lua-hooks/ext/lua/lfunc.h +0 -34
- data/lua-hooks/ext/lua/lgc.c +0 -710
- data/lua-hooks/ext/lua/lgc.h +0 -110
- data/lua-hooks/ext/lua/linit.c +0 -38
- data/lua-hooks/ext/lua/liolib.c +0 -556
- data/lua-hooks/ext/lua/llex.c +0 -463
- data/lua-hooks/ext/lua/llex.h +0 -81
- data/lua-hooks/ext/lua/llimits.h +0 -128
- data/lua-hooks/ext/lua/lmathlib.c +0 -263
- data/lua-hooks/ext/lua/lmem.c +0 -86
- data/lua-hooks/ext/lua/lmem.h +0 -49
- data/lua-hooks/ext/lua/loadlib.c +0 -705
- data/lua-hooks/ext/lua/loadlib_rel.c +0 -760
- data/lua-hooks/ext/lua/lobject.c +0 -214
- data/lua-hooks/ext/lua/lobject.h +0 -381
- data/lua-hooks/ext/lua/lopcodes.c +0 -102
- data/lua-hooks/ext/lua/lopcodes.h +0 -268
- data/lua-hooks/ext/lua/loslib.c +0 -243
- data/lua-hooks/ext/lua/lparser.c +0 -1339
- data/lua-hooks/ext/lua/lparser.h +0 -82
- data/lua-hooks/ext/lua/lstate.c +0 -214
- data/lua-hooks/ext/lua/lstate.h +0 -169
- data/lua-hooks/ext/lua/lstring.c +0 -111
- data/lua-hooks/ext/lua/lstring.h +0 -31
- data/lua-hooks/ext/lua/lstrlib.c +0 -871
- data/lua-hooks/ext/lua/ltable.c +0 -588
- data/lua-hooks/ext/lua/ltable.h +0 -40
- data/lua-hooks/ext/lua/ltablib.c +0 -287
- data/lua-hooks/ext/lua/ltm.c +0 -75
- data/lua-hooks/ext/lua/ltm.h +0 -54
- data/lua-hooks/ext/lua/lua.c +0 -392
- data/lua-hooks/ext/lua/lua.def +0 -131
- data/lua-hooks/ext/lua/lua.rc +0 -28
- data/lua-hooks/ext/lua/lua_dll.rc +0 -26
- data/lua-hooks/ext/lua/luac.c +0 -200
- data/lua-hooks/ext/lua/luac.rc +0 -1
- data/lua-hooks/ext/lua/luaconf.h +0 -763
- data/lua-hooks/ext/lua/luaconf.h.in +0 -724
- data/lua-hooks/ext/lua/luaconf.h.orig +0 -763
- data/lua-hooks/ext/lua/lualib.h +0 -53
- data/lua-hooks/ext/lua/lundump.c +0 -227
- data/lua-hooks/ext/lua/lundump.h +0 -36
- data/lua-hooks/ext/lua/lvm.c +0 -767
- data/lua-hooks/ext/lua/lvm.h +0 -36
- data/lua-hooks/ext/lua/lzio.c +0 -82
- data/lua-hooks/ext/lua/lzio.h +0 -67
- data/lua-hooks/ext/lua/print.c +0 -227
@@ -0,0 +1,356 @@
|
|
1
|
+
/*
|
2
|
+
** Auxiliary library for the Lua/C API.
|
3
|
+
** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
|
4
|
+
**
|
5
|
+
** Major parts taken verbatim or adapted from the Lua interpreter.
|
6
|
+
** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
|
7
|
+
*/
|
8
|
+
|
9
|
+
#include <errno.h>
|
10
|
+
#include <stdarg.h>
|
11
|
+
#include <stdio.h>
|
12
|
+
|
13
|
+
#define lib_aux_c
|
14
|
+
#define LUA_LIB
|
15
|
+
|
16
|
+
#include "lua.h"
|
17
|
+
#include "lauxlib.h"
|
18
|
+
|
19
|
+
#include "lj_obj.h"
|
20
|
+
#include "lj_err.h"
|
21
|
+
#include "lj_state.h"
|
22
|
+
#include "lj_trace.h"
|
23
|
+
#include "lj_lib.h"
|
24
|
+
|
25
|
+
#if LJ_TARGET_POSIX
|
26
|
+
#include <sys/wait.h>
|
27
|
+
#endif
|
28
|
+
|
29
|
+
/* -- I/O error handling -------------------------------------------------- */
|
30
|
+
|
31
|
+
LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname)
|
32
|
+
{
|
33
|
+
if (stat) {
|
34
|
+
setboolV(L->top++, 1);
|
35
|
+
return 1;
|
36
|
+
} else {
|
37
|
+
int en = errno; /* Lua API calls may change this value. */
|
38
|
+
setnilV(L->top++);
|
39
|
+
if (fname)
|
40
|
+
lua_pushfstring(L, "%s: %s", fname, strerror(en));
|
41
|
+
else
|
42
|
+
lua_pushfstring(L, "%s", strerror(en));
|
43
|
+
setintV(L->top++, en);
|
44
|
+
lj_trace_abort(G(L));
|
45
|
+
return 3;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
LUALIB_API int luaL_execresult(lua_State *L, int stat)
|
50
|
+
{
|
51
|
+
if (stat != -1) {
|
52
|
+
#if LJ_TARGET_POSIX
|
53
|
+
if (WIFSIGNALED(stat)) {
|
54
|
+
stat = WTERMSIG(stat);
|
55
|
+
setnilV(L->top++);
|
56
|
+
lua_pushliteral(L, "signal");
|
57
|
+
} else {
|
58
|
+
if (WIFEXITED(stat))
|
59
|
+
stat = WEXITSTATUS(stat);
|
60
|
+
if (stat == 0)
|
61
|
+
setboolV(L->top++, 1);
|
62
|
+
else
|
63
|
+
setnilV(L->top++);
|
64
|
+
lua_pushliteral(L, "exit");
|
65
|
+
}
|
66
|
+
#else
|
67
|
+
if (stat == 0)
|
68
|
+
setboolV(L->top++, 1);
|
69
|
+
else
|
70
|
+
setnilV(L->top++);
|
71
|
+
lua_pushliteral(L, "exit");
|
72
|
+
#endif
|
73
|
+
setintV(L->top++, stat);
|
74
|
+
return 3;
|
75
|
+
}
|
76
|
+
return luaL_fileresult(L, 0, NULL);
|
77
|
+
}
|
78
|
+
|
79
|
+
/* -- Module registration ------------------------------------------------- */
|
80
|
+
|
81
|
+
LUALIB_API const char *luaL_findtable(lua_State *L, int idx,
|
82
|
+
const char *fname, int szhint)
|
83
|
+
{
|
84
|
+
const char *e;
|
85
|
+
lua_pushvalue(L, idx);
|
86
|
+
do {
|
87
|
+
e = strchr(fname, '.');
|
88
|
+
if (e == NULL) e = fname + strlen(fname);
|
89
|
+
lua_pushlstring(L, fname, (size_t)(e - fname));
|
90
|
+
lua_rawget(L, -2);
|
91
|
+
if (lua_isnil(L, -1)) { /* no such field? */
|
92
|
+
lua_pop(L, 1); /* remove this nil */
|
93
|
+
lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
|
94
|
+
lua_pushlstring(L, fname, (size_t)(e - fname));
|
95
|
+
lua_pushvalue(L, -2);
|
96
|
+
lua_settable(L, -4); /* set new table into field */
|
97
|
+
} else if (!lua_istable(L, -1)) { /* field has a non-table value? */
|
98
|
+
lua_pop(L, 2); /* remove table and value */
|
99
|
+
return fname; /* return problematic part of the name */
|
100
|
+
}
|
101
|
+
lua_remove(L, -2); /* remove previous table */
|
102
|
+
fname = e + 1;
|
103
|
+
} while (*e == '.');
|
104
|
+
return NULL;
|
105
|
+
}
|
106
|
+
|
107
|
+
static int libsize(const luaL_Reg *l)
|
108
|
+
{
|
109
|
+
int size = 0;
|
110
|
+
for (; l->name; l++) size++;
|
111
|
+
return size;
|
112
|
+
}
|
113
|
+
|
114
|
+
LUALIB_API void luaL_openlib(lua_State *L, const char *libname,
|
115
|
+
const luaL_Reg *l, int nup)
|
116
|
+
{
|
117
|
+
lj_lib_checkfpu(L);
|
118
|
+
if (libname) {
|
119
|
+
int size = libsize(l);
|
120
|
+
/* check whether lib already exists */
|
121
|
+
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
|
122
|
+
lua_getfield(L, -1, libname); /* get _LOADED[libname] */
|
123
|
+
if (!lua_istable(L, -1)) { /* not found? */
|
124
|
+
lua_pop(L, 1); /* remove previous result */
|
125
|
+
/* try global variable (and create one if it does not exist) */
|
126
|
+
if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
|
127
|
+
lj_err_callerv(L, LJ_ERR_BADMODN, libname);
|
128
|
+
lua_pushvalue(L, -1);
|
129
|
+
lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
|
130
|
+
}
|
131
|
+
lua_remove(L, -2); /* remove _LOADED table */
|
132
|
+
lua_insert(L, -(nup+1)); /* move library table to below upvalues */
|
133
|
+
}
|
134
|
+
for (; l->name; l++) {
|
135
|
+
int i;
|
136
|
+
for (i = 0; i < nup; i++) /* copy upvalues to the top */
|
137
|
+
lua_pushvalue(L, -nup);
|
138
|
+
lua_pushcclosure(L, l->func, nup);
|
139
|
+
lua_setfield(L, -(nup+2), l->name);
|
140
|
+
}
|
141
|
+
lua_pop(L, nup); /* remove upvalues */
|
142
|
+
}
|
143
|
+
|
144
|
+
LUALIB_API void luaL_register(lua_State *L, const char *libname,
|
145
|
+
const luaL_Reg *l)
|
146
|
+
{
|
147
|
+
luaL_openlib(L, libname, l, 0);
|
148
|
+
}
|
149
|
+
|
150
|
+
LUALIB_API const char *luaL_gsub(lua_State *L, const char *s,
|
151
|
+
const char *p, const char *r)
|
152
|
+
{
|
153
|
+
const char *wild;
|
154
|
+
size_t l = strlen(p);
|
155
|
+
luaL_Buffer b;
|
156
|
+
luaL_buffinit(L, &b);
|
157
|
+
while ((wild = strstr(s, p)) != NULL) {
|
158
|
+
luaL_addlstring(&b, s, (size_t)(wild - s)); /* push prefix */
|
159
|
+
luaL_addstring(&b, r); /* push replacement in place of pattern */
|
160
|
+
s = wild + l; /* continue after `p' */
|
161
|
+
}
|
162
|
+
luaL_addstring(&b, s); /* push last suffix */
|
163
|
+
luaL_pushresult(&b);
|
164
|
+
return lua_tostring(L, -1);
|
165
|
+
}
|
166
|
+
|
167
|
+
/* -- Buffer handling ----------------------------------------------------- */
|
168
|
+
|
169
|
+
#define bufflen(B) ((size_t)((B)->p - (B)->buffer))
|
170
|
+
#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B)))
|
171
|
+
|
172
|
+
static int emptybuffer(luaL_Buffer *B)
|
173
|
+
{
|
174
|
+
size_t l = bufflen(B);
|
175
|
+
if (l == 0)
|
176
|
+
return 0; /* put nothing on stack */
|
177
|
+
lua_pushlstring(B->L, B->buffer, l);
|
178
|
+
B->p = B->buffer;
|
179
|
+
B->lvl++;
|
180
|
+
return 1;
|
181
|
+
}
|
182
|
+
|
183
|
+
static void adjuststack(luaL_Buffer *B)
|
184
|
+
{
|
185
|
+
if (B->lvl > 1) {
|
186
|
+
lua_State *L = B->L;
|
187
|
+
int toget = 1; /* number of levels to concat */
|
188
|
+
size_t toplen = lua_strlen(L, -1);
|
189
|
+
do {
|
190
|
+
size_t l = lua_strlen(L, -(toget+1));
|
191
|
+
if (!(B->lvl - toget + 1 >= LUA_MINSTACK/2 || toplen > l))
|
192
|
+
break;
|
193
|
+
toplen += l;
|
194
|
+
toget++;
|
195
|
+
} while (toget < B->lvl);
|
196
|
+
lua_concat(L, toget);
|
197
|
+
B->lvl = B->lvl - toget + 1;
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
201
|
+
LUALIB_API char *luaL_prepbuffer(luaL_Buffer *B)
|
202
|
+
{
|
203
|
+
if (emptybuffer(B))
|
204
|
+
adjuststack(B);
|
205
|
+
return B->buffer;
|
206
|
+
}
|
207
|
+
|
208
|
+
LUALIB_API void luaL_addlstring(luaL_Buffer *B, const char *s, size_t l)
|
209
|
+
{
|
210
|
+
while (l--)
|
211
|
+
luaL_addchar(B, *s++);
|
212
|
+
}
|
213
|
+
|
214
|
+
LUALIB_API void luaL_addstring(luaL_Buffer *B, const char *s)
|
215
|
+
{
|
216
|
+
luaL_addlstring(B, s, strlen(s));
|
217
|
+
}
|
218
|
+
|
219
|
+
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
|
220
|
+
{
|
221
|
+
emptybuffer(B);
|
222
|
+
lua_concat(B->L, B->lvl);
|
223
|
+
B->lvl = 1;
|
224
|
+
}
|
225
|
+
|
226
|
+
LUALIB_API void luaL_addvalue(luaL_Buffer *B)
|
227
|
+
{
|
228
|
+
lua_State *L = B->L;
|
229
|
+
size_t vl;
|
230
|
+
const char *s = lua_tolstring(L, -1, &vl);
|
231
|
+
if (vl <= bufffree(B)) { /* fit into buffer? */
|
232
|
+
memcpy(B->p, s, vl); /* put it there */
|
233
|
+
B->p += vl;
|
234
|
+
lua_pop(L, 1); /* remove from stack */
|
235
|
+
} else {
|
236
|
+
if (emptybuffer(B))
|
237
|
+
lua_insert(L, -2); /* put buffer before new value */
|
238
|
+
B->lvl++; /* add new value into B stack */
|
239
|
+
adjuststack(B);
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
|
244
|
+
{
|
245
|
+
B->L = L;
|
246
|
+
B->p = B->buffer;
|
247
|
+
B->lvl = 0;
|
248
|
+
}
|
249
|
+
|
250
|
+
/* -- Reference management ------------------------------------------------ */
|
251
|
+
|
252
|
+
#define FREELIST_REF 0
|
253
|
+
|
254
|
+
/* Convert a stack index to an absolute index. */
|
255
|
+
#define abs_index(L, i) \
|
256
|
+
((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1)
|
257
|
+
|
258
|
+
LUALIB_API int luaL_ref(lua_State *L, int t)
|
259
|
+
{
|
260
|
+
int ref;
|
261
|
+
t = abs_index(L, t);
|
262
|
+
if (lua_isnil(L, -1)) {
|
263
|
+
lua_pop(L, 1); /* remove from stack */
|
264
|
+
return LUA_REFNIL; /* `nil' has a unique fixed reference */
|
265
|
+
}
|
266
|
+
lua_rawgeti(L, t, FREELIST_REF); /* get first free element */
|
267
|
+
ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */
|
268
|
+
lua_pop(L, 1); /* remove it from stack */
|
269
|
+
if (ref != 0) { /* any free element? */
|
270
|
+
lua_rawgeti(L, t, ref); /* remove it from list */
|
271
|
+
lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */
|
272
|
+
} else { /* no free elements */
|
273
|
+
ref = (int)lua_objlen(L, t);
|
274
|
+
ref++; /* create new reference */
|
275
|
+
}
|
276
|
+
lua_rawseti(L, t, ref);
|
277
|
+
return ref;
|
278
|
+
}
|
279
|
+
|
280
|
+
LUALIB_API void luaL_unref(lua_State *L, int t, int ref)
|
281
|
+
{
|
282
|
+
if (ref >= 0) {
|
283
|
+
t = abs_index(L, t);
|
284
|
+
lua_rawgeti(L, t, FREELIST_REF);
|
285
|
+
lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */
|
286
|
+
lua_pushinteger(L, ref);
|
287
|
+
lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */
|
288
|
+
}
|
289
|
+
}
|
290
|
+
|
291
|
+
/* -- Default allocator and panic function -------------------------------- */
|
292
|
+
|
293
|
+
static int panic(lua_State *L)
|
294
|
+
{
|
295
|
+
const char *s = lua_tostring(L, -1);
|
296
|
+
fputs("PANIC: unprotected error in call to Lua API (", stderr);
|
297
|
+
fputs(s ? s : "?", stderr);
|
298
|
+
fputc(')', stderr); fputc('\n', stderr);
|
299
|
+
fflush(stderr);
|
300
|
+
return 0;
|
301
|
+
}
|
302
|
+
|
303
|
+
#ifdef LUAJIT_USE_SYSMALLOC
|
304
|
+
|
305
|
+
#if LJ_64 && !defined(LUAJIT_USE_VALGRIND)
|
306
|
+
#error "Must use builtin allocator for 64 bit target"
|
307
|
+
#endif
|
308
|
+
|
309
|
+
static void *mem_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
|
310
|
+
{
|
311
|
+
(void)ud;
|
312
|
+
(void)osize;
|
313
|
+
if (nsize == 0) {
|
314
|
+
free(ptr);
|
315
|
+
return NULL;
|
316
|
+
} else {
|
317
|
+
return realloc(ptr, nsize);
|
318
|
+
}
|
319
|
+
}
|
320
|
+
|
321
|
+
LUALIB_API lua_State *luaL_newstate(void)
|
322
|
+
{
|
323
|
+
lua_State *L = lua_newstate(mem_alloc, NULL);
|
324
|
+
if (L) G(L)->panic = panic;
|
325
|
+
return L;
|
326
|
+
}
|
327
|
+
|
328
|
+
#else
|
329
|
+
|
330
|
+
#include "lj_alloc.h"
|
331
|
+
|
332
|
+
LUALIB_API lua_State *luaL_newstate(void)
|
333
|
+
{
|
334
|
+
lua_State *L;
|
335
|
+
void *ud = lj_alloc_create();
|
336
|
+
if (ud == NULL) return NULL;
|
337
|
+
#if LJ_64
|
338
|
+
L = lj_state_newstate(lj_alloc_f, ud);
|
339
|
+
#else
|
340
|
+
L = lua_newstate(lj_alloc_f, ud);
|
341
|
+
#endif
|
342
|
+
if (L) G(L)->panic = panic;
|
343
|
+
return L;
|
344
|
+
}
|
345
|
+
|
346
|
+
#if LJ_64
|
347
|
+
LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)
|
348
|
+
{
|
349
|
+
UNUSED(f); UNUSED(ud);
|
350
|
+
fputs("Must use luaL_newstate() for 64 bit target\n", stderr);
|
351
|
+
return NULL;
|
352
|
+
}
|
353
|
+
#endif
|
354
|
+
|
355
|
+
#endif
|
356
|
+
|
Binary file
|
Binary file
|
@@ -0,0 +1,664 @@
|
|
1
|
+
/*
|
2
|
+
** Base and coroutine library.
|
3
|
+
** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
|
4
|
+
**
|
5
|
+
** Major portions taken verbatim or adapted from the Lua interpreter.
|
6
|
+
** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h
|
7
|
+
*/
|
8
|
+
|
9
|
+
#include <stdio.h>
|
10
|
+
|
11
|
+
#define lib_base_c
|
12
|
+
#define LUA_LIB
|
13
|
+
|
14
|
+
#include "lua.h"
|
15
|
+
#include "lauxlib.h"
|
16
|
+
#include "lualib.h"
|
17
|
+
|
18
|
+
#include "lj_obj.h"
|
19
|
+
#include "lj_gc.h"
|
20
|
+
#include "lj_err.h"
|
21
|
+
#include "lj_debug.h"
|
22
|
+
#include "lj_str.h"
|
23
|
+
#include "lj_tab.h"
|
24
|
+
#include "lj_meta.h"
|
25
|
+
#include "lj_state.h"
|
26
|
+
#if LJ_HASFFI
|
27
|
+
#include "lj_ctype.h"
|
28
|
+
#include "lj_cconv.h"
|
29
|
+
#endif
|
30
|
+
#include "lj_bc.h"
|
31
|
+
#include "lj_ff.h"
|
32
|
+
#include "lj_dispatch.h"
|
33
|
+
#include "lj_char.h"
|
34
|
+
#include "lj_strscan.h"
|
35
|
+
#include "lj_strfmt.h"
|
36
|
+
#include "lj_lib.h"
|
37
|
+
|
38
|
+
/* -- Base library: checks ------------------------------------------------ */
|
39
|
+
|
40
|
+
#define LJLIB_MODULE_base
|
41
|
+
|
42
|
+
LJLIB_ASM(assert) LJLIB_REC(.)
|
43
|
+
{
|
44
|
+
GCstr *s;
|
45
|
+
lj_lib_checkany(L, 1);
|
46
|
+
s = lj_lib_optstr(L, 2);
|
47
|
+
if (s)
|
48
|
+
lj_err_callermsg(L, strdata(s));
|
49
|
+
else
|
50
|
+
lj_err_caller(L, LJ_ERR_ASSERT);
|
51
|
+
return FFH_UNREACHABLE;
|
52
|
+
}
|
53
|
+
|
54
|
+
/* ORDER LJ_T */
|
55
|
+
LJLIB_PUSH("nil")
|
56
|
+
LJLIB_PUSH("boolean")
|
57
|
+
LJLIB_PUSH(top-1) /* boolean */
|
58
|
+
LJLIB_PUSH("userdata")
|
59
|
+
LJLIB_PUSH("string")
|
60
|
+
LJLIB_PUSH("upval")
|
61
|
+
LJLIB_PUSH("thread")
|
62
|
+
LJLIB_PUSH("proto")
|
63
|
+
LJLIB_PUSH("function")
|
64
|
+
LJLIB_PUSH("trace")
|
65
|
+
LJLIB_PUSH("cdata")
|
66
|
+
LJLIB_PUSH("table")
|
67
|
+
LJLIB_PUSH(top-9) /* userdata */
|
68
|
+
LJLIB_PUSH("number")
|
69
|
+
LJLIB_ASM_(type) LJLIB_REC(.)
|
70
|
+
/* Recycle the lj_lib_checkany(L, 1) from assert. */
|
71
|
+
|
72
|
+
/* -- Base library: iterators --------------------------------------------- */
|
73
|
+
|
74
|
+
/* This solves a circular dependency problem -- change FF_next_N as needed. */
|
75
|
+
LJ_STATIC_ASSERT((int)FF_next == FF_next_N);
|
76
|
+
|
77
|
+
LJLIB_ASM(next)
|
78
|
+
{
|
79
|
+
lj_lib_checktab(L, 1);
|
80
|
+
return FFH_UNREACHABLE;
|
81
|
+
}
|
82
|
+
|
83
|
+
#if LJ_52 || LJ_HASFFI
|
84
|
+
static int ffh_pairs(lua_State *L, MMS mm)
|
85
|
+
{
|
86
|
+
TValue *o = lj_lib_checkany(L, 1);
|
87
|
+
cTValue *mo = lj_meta_lookup(L, o, mm);
|
88
|
+
if ((LJ_52 || tviscdata(o)) && !tvisnil(mo)) {
|
89
|
+
L->top = o+1; /* Only keep one argument. */
|
90
|
+
copyTV(L, L->base-1-LJ_FR2, mo); /* Replace callable. */
|
91
|
+
return FFH_TAILCALL;
|
92
|
+
} else {
|
93
|
+
if (!tvistab(o)) lj_err_argt(L, 1, LUA_TTABLE);
|
94
|
+
if (LJ_FR2) { copyTV(L, o-1, o); o--; }
|
95
|
+
setfuncV(L, o-1, funcV(lj_lib_upvalue(L, 1)));
|
96
|
+
if (mm == MM_pairs) setnilV(o+1); else setintV(o+1, 0);
|
97
|
+
return FFH_RES(3);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
#else
|
101
|
+
#define ffh_pairs(L, mm) (lj_lib_checktab(L, 1), FFH_UNREACHABLE)
|
102
|
+
#endif
|
103
|
+
|
104
|
+
LJLIB_PUSH(lastcl)
|
105
|
+
LJLIB_ASM(pairs) LJLIB_REC(xpairs 0)
|
106
|
+
{
|
107
|
+
return ffh_pairs(L, MM_pairs);
|
108
|
+
}
|
109
|
+
|
110
|
+
LJLIB_NOREGUV LJLIB_ASM(ipairs_aux) LJLIB_REC(.)
|
111
|
+
{
|
112
|
+
lj_lib_checktab(L, 1);
|
113
|
+
lj_lib_checkint(L, 2);
|
114
|
+
return FFH_UNREACHABLE;
|
115
|
+
}
|
116
|
+
|
117
|
+
LJLIB_PUSH(lastcl)
|
118
|
+
LJLIB_ASM(ipairs) LJLIB_REC(xpairs 1)
|
119
|
+
{
|
120
|
+
return ffh_pairs(L, MM_ipairs);
|
121
|
+
}
|
122
|
+
|
123
|
+
/* -- Base library: getters and setters ----------------------------------- */
|
124
|
+
|
125
|
+
LJLIB_ASM_(getmetatable) LJLIB_REC(.)
|
126
|
+
/* Recycle the lj_lib_checkany(L, 1) from assert. */
|
127
|
+
|
128
|
+
LJLIB_ASM(setmetatable) LJLIB_REC(.)
|
129
|
+
{
|
130
|
+
GCtab *t = lj_lib_checktab(L, 1);
|
131
|
+
GCtab *mt = lj_lib_checktabornil(L, 2);
|
132
|
+
if (!tvisnil(lj_meta_lookup(L, L->base, MM_metatable)))
|
133
|
+
lj_err_caller(L, LJ_ERR_PROTMT);
|
134
|
+
setgcref(t->metatable, obj2gco(mt));
|
135
|
+
if (mt) { lj_gc_objbarriert(L, t, mt); }
|
136
|
+
settabV(L, L->base-1-LJ_FR2, t);
|
137
|
+
return FFH_RES(1);
|
138
|
+
}
|
139
|
+
|
140
|
+
LJLIB_CF(getfenv) LJLIB_REC(.)
|
141
|
+
{
|
142
|
+
GCfunc *fn;
|
143
|
+
cTValue *o = L->base;
|
144
|
+
if (!(o < L->top && tvisfunc(o))) {
|
145
|
+
int level = lj_lib_optint(L, 1, 1);
|
146
|
+
o = lj_debug_frame(L, level, &level);
|
147
|
+
if (o == NULL)
|
148
|
+
lj_err_arg(L, 1, LJ_ERR_INVLVL);
|
149
|
+
if (LJ_FR2) o--;
|
150
|
+
}
|
151
|
+
fn = &gcval(o)->fn;
|
152
|
+
settabV(L, L->top++, isluafunc(fn) ? tabref(fn->l.env) : tabref(L->env));
|
153
|
+
return 1;
|
154
|
+
}
|
155
|
+
|
156
|
+
LJLIB_CF(setfenv)
|
157
|
+
{
|
158
|
+
GCfunc *fn;
|
159
|
+
GCtab *t = lj_lib_checktab(L, 2);
|
160
|
+
cTValue *o = L->base;
|
161
|
+
if (!(o < L->top && tvisfunc(o))) {
|
162
|
+
int level = lj_lib_checkint(L, 1);
|
163
|
+
if (level == 0) {
|
164
|
+
/* NOBARRIER: A thread (i.e. L) is never black. */
|
165
|
+
setgcref(L->env, obj2gco(t));
|
166
|
+
return 0;
|
167
|
+
}
|
168
|
+
o = lj_debug_frame(L, level, &level);
|
169
|
+
if (o == NULL)
|
170
|
+
lj_err_arg(L, 1, LJ_ERR_INVLVL);
|
171
|
+
if (LJ_FR2) o--;
|
172
|
+
}
|
173
|
+
fn = &gcval(o)->fn;
|
174
|
+
if (!isluafunc(fn))
|
175
|
+
lj_err_caller(L, LJ_ERR_SETFENV);
|
176
|
+
setgcref(fn->l.env, obj2gco(t));
|
177
|
+
lj_gc_objbarrier(L, obj2gco(fn), t);
|
178
|
+
setfuncV(L, L->top++, fn);
|
179
|
+
return 1;
|
180
|
+
}
|
181
|
+
|
182
|
+
LJLIB_ASM(rawget) LJLIB_REC(.)
|
183
|
+
{
|
184
|
+
lj_lib_checktab(L, 1);
|
185
|
+
lj_lib_checkany(L, 2);
|
186
|
+
return FFH_UNREACHABLE;
|
187
|
+
}
|
188
|
+
|
189
|
+
LJLIB_CF(rawset) LJLIB_REC(.)
|
190
|
+
{
|
191
|
+
lj_lib_checktab(L, 1);
|
192
|
+
lj_lib_checkany(L, 2);
|
193
|
+
L->top = 1+lj_lib_checkany(L, 3);
|
194
|
+
lua_rawset(L, 1);
|
195
|
+
return 1;
|
196
|
+
}
|
197
|
+
|
198
|
+
LJLIB_CF(rawequal) LJLIB_REC(.)
|
199
|
+
{
|
200
|
+
cTValue *o1 = lj_lib_checkany(L, 1);
|
201
|
+
cTValue *o2 = lj_lib_checkany(L, 2);
|
202
|
+
setboolV(L->top-1, lj_obj_equal(o1, o2));
|
203
|
+
return 1;
|
204
|
+
}
|
205
|
+
|
206
|
+
#if LJ_52
|
207
|
+
LJLIB_CF(rawlen) LJLIB_REC(.)
|
208
|
+
{
|
209
|
+
cTValue *o = L->base;
|
210
|
+
int32_t len;
|
211
|
+
if (L->top > o && tvisstr(o))
|
212
|
+
len = (int32_t)strV(o)->len;
|
213
|
+
else
|
214
|
+
len = (int32_t)lj_tab_len(lj_lib_checktab(L, 1));
|
215
|
+
setintV(L->top-1, len);
|
216
|
+
return 1;
|
217
|
+
}
|
218
|
+
#endif
|
219
|
+
|
220
|
+
LJLIB_CF(unpack)
|
221
|
+
{
|
222
|
+
GCtab *t = lj_lib_checktab(L, 1);
|
223
|
+
int32_t n, i = lj_lib_optint(L, 2, 1);
|
224
|
+
int32_t e = (L->base+3-1 < L->top && !tvisnil(L->base+3-1)) ?
|
225
|
+
lj_lib_checkint(L, 3) : (int32_t)lj_tab_len(t);
|
226
|
+
if (i > e) return 0;
|
227
|
+
n = e - i + 1;
|
228
|
+
if (n <= 0 || !lua_checkstack(L, n))
|
229
|
+
lj_err_caller(L, LJ_ERR_UNPACK);
|
230
|
+
do {
|
231
|
+
cTValue *tv = lj_tab_getint(t, i);
|
232
|
+
if (tv) {
|
233
|
+
copyTV(L, L->top++, tv);
|
234
|
+
} else {
|
235
|
+
setnilV(L->top++);
|
236
|
+
}
|
237
|
+
} while (i++ < e);
|
238
|
+
return n;
|
239
|
+
}
|
240
|
+
|
241
|
+
LJLIB_CF(select) LJLIB_REC(.)
|
242
|
+
{
|
243
|
+
int32_t n = (int32_t)(L->top - L->base);
|
244
|
+
if (n >= 1 && tvisstr(L->base) && *strVdata(L->base) == '#') {
|
245
|
+
setintV(L->top-1, n-1);
|
246
|
+
return 1;
|
247
|
+
} else {
|
248
|
+
int32_t i = lj_lib_checkint(L, 1);
|
249
|
+
if (i < 0) i = n + i; else if (i > n) i = n;
|
250
|
+
if (i < 1)
|
251
|
+
lj_err_arg(L, 1, LJ_ERR_IDXRNG);
|
252
|
+
return n - i;
|
253
|
+
}
|
254
|
+
}
|
255
|
+
|
256
|
+
/* -- Base library: conversions ------------------------------------------- */
|
257
|
+
|
258
|
+
LJLIB_ASM(tonumber) LJLIB_REC(.)
|
259
|
+
{
|
260
|
+
int32_t base = lj_lib_optint(L, 2, 10);
|
261
|
+
if (base == 10) {
|
262
|
+
TValue *o = lj_lib_checkany(L, 1);
|
263
|
+
if (lj_strscan_numberobj(o)) {
|
264
|
+
copyTV(L, L->base-1-LJ_FR2, o);
|
265
|
+
return FFH_RES(1);
|
266
|
+
}
|
267
|
+
#if LJ_HASFFI
|
268
|
+
if (tviscdata(o)) {
|
269
|
+
CTState *cts = ctype_cts(L);
|
270
|
+
CType *ct = lj_ctype_rawref(cts, cdataV(o)->ctypeid);
|
271
|
+
if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);
|
272
|
+
if (ctype_isnum(ct->info) || ctype_iscomplex(ct->info)) {
|
273
|
+
if (LJ_DUALNUM && ctype_isinteger_or_bool(ct->info) &&
|
274
|
+
ct->size <= 4 && !(ct->size == 4 && (ct->info & CTF_UNSIGNED))) {
|
275
|
+
int32_t i;
|
276
|
+
lj_cconv_ct_tv(cts, ctype_get(cts, CTID_INT32), (uint8_t *)&i, o, 0);
|
277
|
+
setintV(L->base-1-LJ_FR2, i);
|
278
|
+
return FFH_RES(1);
|
279
|
+
}
|
280
|
+
lj_cconv_ct_tv(cts, ctype_get(cts, CTID_DOUBLE),
|
281
|
+
(uint8_t *)&(L->base-1-LJ_FR2)->n, o, 0);
|
282
|
+
return FFH_RES(1);
|
283
|
+
}
|
284
|
+
}
|
285
|
+
#endif
|
286
|
+
} else {
|
287
|
+
const char *p = strdata(lj_lib_checkstr(L, 1));
|
288
|
+
char *ep;
|
289
|
+
unsigned long ul;
|
290
|
+
if (base < 2 || base > 36)
|
291
|
+
lj_err_arg(L, 2, LJ_ERR_BASERNG);
|
292
|
+
ul = strtoul(p, &ep, base);
|
293
|
+
if (p != ep) {
|
294
|
+
while (lj_char_isspace((unsigned char)(*ep))) ep++;
|
295
|
+
if (*ep == '\0') {
|
296
|
+
if (LJ_DUALNUM && LJ_LIKELY(ul < 0x80000000u))
|
297
|
+
setintV(L->base-1-LJ_FR2, (int32_t)ul);
|
298
|
+
else
|
299
|
+
setnumV(L->base-1-LJ_FR2, (lua_Number)ul);
|
300
|
+
return FFH_RES(1);
|
301
|
+
}
|
302
|
+
}
|
303
|
+
}
|
304
|
+
setnilV(L->base-1-LJ_FR2);
|
305
|
+
return FFH_RES(1);
|
306
|
+
}
|
307
|
+
|
308
|
+
LJLIB_ASM(tostring) LJLIB_REC(.)
|
309
|
+
{
|
310
|
+
TValue *o = lj_lib_checkany(L, 1);
|
311
|
+
cTValue *mo;
|
312
|
+
L->top = o+1; /* Only keep one argument. */
|
313
|
+
if (!tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) {
|
314
|
+
copyTV(L, L->base-1-LJ_FR2, mo); /* Replace callable. */
|
315
|
+
return FFH_TAILCALL;
|
316
|
+
}
|
317
|
+
lj_gc_check(L);
|
318
|
+
setstrV(L, L->base-1-LJ_FR2, lj_strfmt_obj(L, L->base));
|
319
|
+
return FFH_RES(1);
|
320
|
+
}
|
321
|
+
|
322
|
+
/* -- Base library: throw and catch errors -------------------------------- */
|
323
|
+
|
324
|
+
LJLIB_CF(error)
|
325
|
+
{
|
326
|
+
int32_t level = lj_lib_optint(L, 2, 1);
|
327
|
+
lua_settop(L, 1);
|
328
|
+
if (lua_isstring(L, 1) && level > 0) {
|
329
|
+
luaL_where(L, level);
|
330
|
+
lua_pushvalue(L, 1);
|
331
|
+
lua_concat(L, 2);
|
332
|
+
}
|
333
|
+
return lua_error(L);
|
334
|
+
}
|
335
|
+
|
336
|
+
LJLIB_ASM(pcall) LJLIB_REC(.)
|
337
|
+
{
|
338
|
+
lj_lib_checkany(L, 1);
|
339
|
+
lj_lib_checkfunc(L, 2); /* For xpcall only. */
|
340
|
+
return FFH_UNREACHABLE;
|
341
|
+
}
|
342
|
+
LJLIB_ASM_(xpcall) LJLIB_REC(.)
|
343
|
+
|
344
|
+
/* -- Base library: load Lua code ----------------------------------------- */
|
345
|
+
|
346
|
+
static int load_aux(lua_State *L, int status, int envarg)
|
347
|
+
{
|
348
|
+
if (status == 0) {
|
349
|
+
if (tvistab(L->base+envarg-1)) {
|
350
|
+
GCfunc *fn = funcV(L->top-1);
|
351
|
+
GCtab *t = tabV(L->base+envarg-1);
|
352
|
+
setgcref(fn->c.env, obj2gco(t));
|
353
|
+
lj_gc_objbarrier(L, fn, t);
|
354
|
+
}
|
355
|
+
return 1;
|
356
|
+
} else {
|
357
|
+
setnilV(L->top-2);
|
358
|
+
return 2;
|
359
|
+
}
|
360
|
+
}
|
361
|
+
|
362
|
+
LJLIB_CF(loadfile)
|
363
|
+
{
|
364
|
+
GCstr *fname = lj_lib_optstr(L, 1);
|
365
|
+
GCstr *mode = lj_lib_optstr(L, 2);
|
366
|
+
int status;
|
367
|
+
lua_settop(L, 3); /* Ensure env arg exists. */
|
368
|
+
status = luaL_loadfilex(L, fname ? strdata(fname) : NULL,
|
369
|
+
mode ? strdata(mode) : NULL);
|
370
|
+
return load_aux(L, status, 3);
|
371
|
+
}
|
372
|
+
|
373
|
+
static const char *reader_func(lua_State *L, void *ud, size_t *size)
|
374
|
+
{
|
375
|
+
UNUSED(ud);
|
376
|
+
luaL_checkstack(L, 2, "too many nested functions");
|
377
|
+
copyTV(L, L->top++, L->base);
|
378
|
+
lua_call(L, 0, 1); /* Call user-supplied function. */
|
379
|
+
L->top--;
|
380
|
+
if (tvisnil(L->top)) {
|
381
|
+
*size = 0;
|
382
|
+
return NULL;
|
383
|
+
} else if (tvisstr(L->top) || tvisnumber(L->top)) {
|
384
|
+
copyTV(L, L->base+4, L->top); /* Anchor string in reserved stack slot. */
|
385
|
+
return lua_tolstring(L, 5, size);
|
386
|
+
} else {
|
387
|
+
lj_err_caller(L, LJ_ERR_RDRSTR);
|
388
|
+
return NULL;
|
389
|
+
}
|
390
|
+
}
|
391
|
+
|
392
|
+
LJLIB_CF(load)
|
393
|
+
{
|
394
|
+
GCstr *name = lj_lib_optstr(L, 2);
|
395
|
+
GCstr *mode = lj_lib_optstr(L, 3);
|
396
|
+
int status;
|
397
|
+
if (L->base < L->top && (tvisstr(L->base) || tvisnumber(L->base))) {
|
398
|
+
GCstr *s = lj_lib_checkstr(L, 1);
|
399
|
+
lua_settop(L, 4); /* Ensure env arg exists. */
|
400
|
+
status = luaL_loadbufferx(L, strdata(s), s->len, strdata(name ? name : s),
|
401
|
+
mode ? strdata(mode) : NULL);
|
402
|
+
} else {
|
403
|
+
lj_lib_checkfunc(L, 1);
|
404
|
+
lua_settop(L, 5); /* Reserve a slot for the string from the reader. */
|
405
|
+
status = lua_loadx(L, reader_func, NULL, name ? strdata(name) : "=(load)",
|
406
|
+
mode ? strdata(mode) : NULL);
|
407
|
+
}
|
408
|
+
return load_aux(L, status, 4);
|
409
|
+
}
|
410
|
+
|
411
|
+
LJLIB_CF(loadstring)
|
412
|
+
{
|
413
|
+
return lj_cf_load(L);
|
414
|
+
}
|
415
|
+
|
416
|
+
LJLIB_CF(dofile)
|
417
|
+
{
|
418
|
+
GCstr *fname = lj_lib_optstr(L, 1);
|
419
|
+
setnilV(L->top);
|
420
|
+
L->top = L->base+1;
|
421
|
+
if (luaL_loadfile(L, fname ? strdata(fname) : NULL) != 0)
|
422
|
+
lua_error(L);
|
423
|
+
lua_call(L, 0, LUA_MULTRET);
|
424
|
+
return (int)(L->top - L->base) - 1;
|
425
|
+
}
|
426
|
+
|
427
|
+
/* -- Base library: GC control -------------------------------------------- */
|
428
|
+
|
429
|
+
LJLIB_CF(gcinfo)
|
430
|
+
{
|
431
|
+
setintV(L->top++, (int32_t)(G(L)->gc.total >> 10));
|
432
|
+
return 1;
|
433
|
+
}
|
434
|
+
|
435
|
+
LJLIB_CF(collectgarbage)
|
436
|
+
{
|
437
|
+
int opt = lj_lib_checkopt(L, 1, LUA_GCCOLLECT, /* ORDER LUA_GC* */
|
438
|
+
"\4stop\7restart\7collect\5count\1\377\4step\10setpause\12setstepmul");
|
439
|
+
int32_t data = lj_lib_optint(L, 2, 0);
|
440
|
+
if (opt == LUA_GCCOUNT) {
|
441
|
+
setnumV(L->top, (lua_Number)G(L)->gc.total/1024.0);
|
442
|
+
} else {
|
443
|
+
int res = lua_gc(L, opt, data);
|
444
|
+
if (opt == LUA_GCSTEP)
|
445
|
+
setboolV(L->top, res);
|
446
|
+
else
|
447
|
+
setintV(L->top, res);
|
448
|
+
}
|
449
|
+
L->top++;
|
450
|
+
return 1;
|
451
|
+
}
|
452
|
+
|
453
|
+
/* -- Base library: miscellaneous functions ------------------------------- */
|
454
|
+
|
455
|
+
LJLIB_PUSH(top-2) /* Upvalue holds weak table. */
|
456
|
+
LJLIB_CF(newproxy)
|
457
|
+
{
|
458
|
+
lua_settop(L, 1);
|
459
|
+
lua_newuserdata(L, 0);
|
460
|
+
if (lua_toboolean(L, 1) == 0) { /* newproxy(): without metatable. */
|
461
|
+
return 1;
|
462
|
+
} else if (lua_isboolean(L, 1)) { /* newproxy(true): with metatable. */
|
463
|
+
lua_newtable(L);
|
464
|
+
lua_pushvalue(L, -1);
|
465
|
+
lua_pushboolean(L, 1);
|
466
|
+
lua_rawset(L, lua_upvalueindex(1)); /* Remember mt in weak table. */
|
467
|
+
} else { /* newproxy(proxy): inherit metatable. */
|
468
|
+
int validproxy = 0;
|
469
|
+
if (lua_getmetatable(L, 1)) {
|
470
|
+
lua_rawget(L, lua_upvalueindex(1));
|
471
|
+
validproxy = lua_toboolean(L, -1);
|
472
|
+
lua_pop(L, 1);
|
473
|
+
}
|
474
|
+
if (!validproxy)
|
475
|
+
lj_err_arg(L, 1, LJ_ERR_NOPROXY);
|
476
|
+
lua_getmetatable(L, 1);
|
477
|
+
}
|
478
|
+
lua_setmetatable(L, 2);
|
479
|
+
return 1;
|
480
|
+
}
|
481
|
+
|
482
|
+
LJLIB_PUSH("tostring")
|
483
|
+
LJLIB_CF(print)
|
484
|
+
{
|
485
|
+
ptrdiff_t i, nargs = L->top - L->base;
|
486
|
+
cTValue *tv = lj_tab_getstr(tabref(L->env), strV(lj_lib_upvalue(L, 1)));
|
487
|
+
int shortcut;
|
488
|
+
if (tv && !tvisnil(tv)) {
|
489
|
+
copyTV(L, L->top++, tv);
|
490
|
+
} else {
|
491
|
+
setstrV(L, L->top++, strV(lj_lib_upvalue(L, 1)));
|
492
|
+
lua_gettable(L, LUA_GLOBALSINDEX);
|
493
|
+
tv = L->top-1;
|
494
|
+
}
|
495
|
+
shortcut = (tvisfunc(tv) && funcV(tv)->c.ffid == FF_tostring);
|
496
|
+
for (i = 0; i < nargs; i++) {
|
497
|
+
cTValue *o = &L->base[i];
|
498
|
+
char buf[STRFMT_MAXBUF_NUM];
|
499
|
+
const char *str;
|
500
|
+
size_t size;
|
501
|
+
MSize len;
|
502
|
+
if (shortcut && (str = lj_strfmt_wstrnum(buf, o, &len)) != NULL) {
|
503
|
+
size = len;
|
504
|
+
} else {
|
505
|
+
copyTV(L, L->top+1, o);
|
506
|
+
copyTV(L, L->top, L->top-1);
|
507
|
+
L->top += 2;
|
508
|
+
lua_call(L, 1, 1);
|
509
|
+
str = lua_tolstring(L, -1, &size);
|
510
|
+
if (!str)
|
511
|
+
lj_err_caller(L, LJ_ERR_PRTOSTR);
|
512
|
+
L->top--;
|
513
|
+
}
|
514
|
+
if (i)
|
515
|
+
putchar('\t');
|
516
|
+
fwrite(str, 1, size, stdout);
|
517
|
+
}
|
518
|
+
putchar('\n');
|
519
|
+
return 0;
|
520
|
+
}
|
521
|
+
|
522
|
+
LJLIB_PUSH(top-3)
|
523
|
+
LJLIB_SET(_VERSION)
|
524
|
+
|
525
|
+
#include "lj_libdef.h"
|
526
|
+
|
527
|
+
/* -- Coroutine library --------------------------------------------------- */
|
528
|
+
|
529
|
+
#define LJLIB_MODULE_coroutine
|
530
|
+
|
531
|
+
LJLIB_CF(coroutine_status)
|
532
|
+
{
|
533
|
+
const char *s;
|
534
|
+
lua_State *co;
|
535
|
+
if (!(L->top > L->base && tvisthread(L->base)))
|
536
|
+
lj_err_arg(L, 1, LJ_ERR_NOCORO);
|
537
|
+
co = threadV(L->base);
|
538
|
+
if (co == L) s = "running";
|
539
|
+
else if (co->status == LUA_YIELD) s = "suspended";
|
540
|
+
else if (co->status != 0) s = "dead";
|
541
|
+
else if (co->base > tvref(co->stack)+1+LJ_FR2) s = "normal";
|
542
|
+
else if (co->top == co->base) s = "dead";
|
543
|
+
else s = "suspended";
|
544
|
+
lua_pushstring(L, s);
|
545
|
+
return 1;
|
546
|
+
}
|
547
|
+
|
548
|
+
LJLIB_CF(coroutine_running)
|
549
|
+
{
|
550
|
+
#if LJ_52
|
551
|
+
int ismain = lua_pushthread(L);
|
552
|
+
setboolV(L->top++, ismain);
|
553
|
+
return 2;
|
554
|
+
#else
|
555
|
+
if (lua_pushthread(L))
|
556
|
+
setnilV(L->top++);
|
557
|
+
return 1;
|
558
|
+
#endif
|
559
|
+
}
|
560
|
+
|
561
|
+
LJLIB_CF(coroutine_create)
|
562
|
+
{
|
563
|
+
lua_State *L1;
|
564
|
+
if (!(L->base < L->top && tvisfunc(L->base)))
|
565
|
+
lj_err_argt(L, 1, LUA_TFUNCTION);
|
566
|
+
L1 = lua_newthread(L);
|
567
|
+
setfuncV(L, L1->top++, funcV(L->base));
|
568
|
+
return 1;
|
569
|
+
}
|
570
|
+
|
571
|
+
LJLIB_ASM(coroutine_yield)
|
572
|
+
{
|
573
|
+
lj_err_caller(L, LJ_ERR_CYIELD);
|
574
|
+
return FFH_UNREACHABLE;
|
575
|
+
}
|
576
|
+
|
577
|
+
static int ffh_resume(lua_State *L, lua_State *co, int wrap)
|
578
|
+
{
|
579
|
+
if (co->cframe != NULL || co->status > LUA_YIELD ||
|
580
|
+
(co->status == 0 && co->top == co->base)) {
|
581
|
+
ErrMsg em = co->cframe ? LJ_ERR_CORUN : LJ_ERR_CODEAD;
|
582
|
+
if (wrap) lj_err_caller(L, em);
|
583
|
+
setboolV(L->base-1-LJ_FR2, 0);
|
584
|
+
setstrV(L, L->base-LJ_FR2, lj_err_str(L, em));
|
585
|
+
return FFH_RES(2);
|
586
|
+
}
|
587
|
+
lj_state_growstack(co, (MSize)(L->top - L->base));
|
588
|
+
return FFH_RETRY;
|
589
|
+
}
|
590
|
+
|
591
|
+
LJLIB_ASM(coroutine_resume)
|
592
|
+
{
|
593
|
+
if (!(L->top > L->base && tvisthread(L->base)))
|
594
|
+
lj_err_arg(L, 1, LJ_ERR_NOCORO);
|
595
|
+
return ffh_resume(L, threadV(L->base), 0);
|
596
|
+
}
|
597
|
+
|
598
|
+
LJLIB_NOREG LJLIB_ASM(coroutine_wrap_aux)
|
599
|
+
{
|
600
|
+
return ffh_resume(L, threadV(lj_lib_upvalue(L, 1)), 1);
|
601
|
+
}
|
602
|
+
|
603
|
+
/* Inline declarations. */
|
604
|
+
LJ_ASMF void lj_ff_coroutine_wrap_aux(void);
|
605
|
+
#if !(LJ_TARGET_MIPS && defined(ljamalg_c))
|
606
|
+
LJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L,
|
607
|
+
lua_State *co);
|
608
|
+
#endif
|
609
|
+
|
610
|
+
/* Error handler, called from assembler VM. */
|
611
|
+
void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L, lua_State *co)
|
612
|
+
{
|
613
|
+
co->top--; copyTV(L, L->top, co->top); L->top++;
|
614
|
+
if (tvisstr(L->top-1))
|
615
|
+
lj_err_callermsg(L, strVdata(L->top-1));
|
616
|
+
else
|
617
|
+
lj_err_run(L);
|
618
|
+
}
|
619
|
+
|
620
|
+
/* Forward declaration. */
|
621
|
+
static void setpc_wrap_aux(lua_State *L, GCfunc *fn);
|
622
|
+
|
623
|
+
LJLIB_CF(coroutine_wrap)
|
624
|
+
{
|
625
|
+
GCfunc *fn;
|
626
|
+
lj_cf_coroutine_create(L);
|
627
|
+
fn = lj_lib_pushcc(L, lj_ffh_coroutine_wrap_aux, FF_coroutine_wrap_aux, 1);
|
628
|
+
setpc_wrap_aux(L, fn);
|
629
|
+
return 1;
|
630
|
+
}
|
631
|
+
|
632
|
+
#include "lj_libdef.h"
|
633
|
+
|
634
|
+
/* Fix the PC of wrap_aux. Really ugly workaround. */
|
635
|
+
static void setpc_wrap_aux(lua_State *L, GCfunc *fn)
|
636
|
+
{
|
637
|
+
setmref(fn->c.pc, &L2GG(L)->bcff[lj_lib_init_coroutine[1]+2]);
|
638
|
+
}
|
639
|
+
|
640
|
+
/* ------------------------------------------------------------------------ */
|
641
|
+
|
642
|
+
static void newproxy_weaktable(lua_State *L)
|
643
|
+
{
|
644
|
+
/* NOBARRIER: The table is new (marked white). */
|
645
|
+
GCtab *t = lj_tab_new(L, 0, 1);
|
646
|
+
settabV(L, L->top++, t);
|
647
|
+
setgcref(t->metatable, obj2gco(t));
|
648
|
+
setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")),
|
649
|
+
lj_str_newlit(L, "kv"));
|
650
|
+
t->nomm = (uint8_t)(~(1u<<MM_mode));
|
651
|
+
}
|
652
|
+
|
653
|
+
LUALIB_API int luaopen_base(lua_State *L)
|
654
|
+
{
|
655
|
+
/* NOBARRIER: Table and value are the same. */
|
656
|
+
GCtab *env = tabref(L->env);
|
657
|
+
settabV(L, lj_tab_setstr(L, env, lj_str_newlit(L, "_G")), env);
|
658
|
+
lua_pushliteral(L, LUA_VERSION); /* top-3. */
|
659
|
+
newproxy_weaktable(L); /* top-2. */
|
660
|
+
LJ_LIB_REG(L, "_G", base);
|
661
|
+
LJ_LIB_REG(L, LUA_COLIBNAME, coroutine);
|
662
|
+
return 2;
|
663
|
+
}
|
664
|
+
|