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
Binary file
|
Binary file
|
@@ -0,0 +1,610 @@
|
|
1
|
+
/*
|
2
|
+
** Package 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-2012 Lua.org, PUC-Rio. See Copyright Notice in lua.h
|
7
|
+
*/
|
8
|
+
|
9
|
+
#define lib_package_c
|
10
|
+
#define LUA_LIB
|
11
|
+
|
12
|
+
#include "lua.h"
|
13
|
+
#include "lauxlib.h"
|
14
|
+
#include "lualib.h"
|
15
|
+
|
16
|
+
#include "lj_obj.h"
|
17
|
+
#include "lj_err.h"
|
18
|
+
#include "lj_lib.h"
|
19
|
+
|
20
|
+
/* ------------------------------------------------------------------------ */
|
21
|
+
|
22
|
+
/* Error codes for ll_loadfunc. */
|
23
|
+
#define PACKAGE_ERR_LIB 1
|
24
|
+
#define PACKAGE_ERR_FUNC 2
|
25
|
+
#define PACKAGE_ERR_LOAD 3
|
26
|
+
|
27
|
+
/* Redefined in platform specific part. */
|
28
|
+
#define PACKAGE_LIB_FAIL "open"
|
29
|
+
#define setprogdir(L) ((void)0)
|
30
|
+
|
31
|
+
/* Symbol name prefixes. */
|
32
|
+
#define SYMPREFIX_CF "luaopen_%s"
|
33
|
+
#define SYMPREFIX_BC "luaJIT_BC_%s"
|
34
|
+
|
35
|
+
#if LJ_TARGET_DLOPEN
|
36
|
+
|
37
|
+
#include <dlfcn.h>
|
38
|
+
|
39
|
+
static void ll_unloadlib(void *lib)
|
40
|
+
{
|
41
|
+
dlclose(lib);
|
42
|
+
}
|
43
|
+
|
44
|
+
static void *ll_load(lua_State *L, const char *path, int gl)
|
45
|
+
{
|
46
|
+
void *lib = dlopen(path, RTLD_NOW | (gl ? RTLD_GLOBAL : RTLD_LOCAL));
|
47
|
+
if (lib == NULL) lua_pushstring(L, dlerror());
|
48
|
+
return lib;
|
49
|
+
}
|
50
|
+
|
51
|
+
static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
|
52
|
+
{
|
53
|
+
lua_CFunction f = (lua_CFunction)dlsym(lib, sym);
|
54
|
+
if (f == NULL) lua_pushstring(L, dlerror());
|
55
|
+
return f;
|
56
|
+
}
|
57
|
+
|
58
|
+
static const char *ll_bcsym(void *lib, const char *sym)
|
59
|
+
{
|
60
|
+
#if defined(RTLD_DEFAULT)
|
61
|
+
if (lib == NULL) lib = RTLD_DEFAULT;
|
62
|
+
#elif LJ_TARGET_OSX || LJ_TARGET_BSD
|
63
|
+
if (lib == NULL) lib = (void *)(intptr_t)-2;
|
64
|
+
#endif
|
65
|
+
return (const char *)dlsym(lib, sym);
|
66
|
+
}
|
67
|
+
|
68
|
+
#elif LJ_TARGET_WINDOWS
|
69
|
+
|
70
|
+
#define WIN32_LEAN_AND_MEAN
|
71
|
+
#include <windows.h>
|
72
|
+
|
73
|
+
#ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
|
74
|
+
#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 4
|
75
|
+
#define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT 2
|
76
|
+
BOOL WINAPI GetModuleHandleExA(DWORD, LPCSTR, HMODULE*);
|
77
|
+
#endif
|
78
|
+
|
79
|
+
#undef setprogdir
|
80
|
+
|
81
|
+
static void setprogdir(lua_State *L)
|
82
|
+
{
|
83
|
+
char buff[MAX_PATH + 1];
|
84
|
+
char *lb;
|
85
|
+
DWORD nsize = sizeof(buff);
|
86
|
+
DWORD n = GetModuleFileNameA(NULL, buff, nsize);
|
87
|
+
if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) {
|
88
|
+
luaL_error(L, "unable to get ModuleFileName");
|
89
|
+
} else {
|
90
|
+
*lb = '\0';
|
91
|
+
luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff);
|
92
|
+
lua_remove(L, -2); /* remove original string */
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
static void pusherror(lua_State *L)
|
97
|
+
{
|
98
|
+
DWORD error = GetLastError();
|
99
|
+
#if LJ_TARGET_XBOXONE
|
100
|
+
wchar_t wbuffer[128];
|
101
|
+
char buffer[128*2];
|
102
|
+
if (FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
|
103
|
+
NULL, error, 0, wbuffer, sizeof(wbuffer)/sizeof(wchar_t), NULL) &&
|
104
|
+
WideCharToMultiByte(CP_ACP, 0, wbuffer, 128, buffer, 128*2, NULL, NULL))
|
105
|
+
#else
|
106
|
+
char buffer[128];
|
107
|
+
if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
|
108
|
+
NULL, error, 0, buffer, sizeof(buffer), NULL))
|
109
|
+
#endif
|
110
|
+
lua_pushstring(L, buffer);
|
111
|
+
else
|
112
|
+
lua_pushfstring(L, "system error %d\n", error);
|
113
|
+
}
|
114
|
+
|
115
|
+
static void ll_unloadlib(void *lib)
|
116
|
+
{
|
117
|
+
FreeLibrary((HINSTANCE)lib);
|
118
|
+
}
|
119
|
+
|
120
|
+
static void *ll_load(lua_State *L, const char *path, int gl)
|
121
|
+
{
|
122
|
+
HINSTANCE lib = LoadLibraryExA(path, NULL, 0);
|
123
|
+
if (lib == NULL) pusherror(L);
|
124
|
+
UNUSED(gl);
|
125
|
+
return lib;
|
126
|
+
}
|
127
|
+
|
128
|
+
static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
|
129
|
+
{
|
130
|
+
lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym);
|
131
|
+
if (f == NULL) pusherror(L);
|
132
|
+
return f;
|
133
|
+
}
|
134
|
+
|
135
|
+
static const char *ll_bcsym(void *lib, const char *sym)
|
136
|
+
{
|
137
|
+
if (lib) {
|
138
|
+
return (const char *)GetProcAddress((HINSTANCE)lib, sym);
|
139
|
+
} else {
|
140
|
+
HINSTANCE h = GetModuleHandleA(NULL);
|
141
|
+
const char *p = (const char *)GetProcAddress(h, sym);
|
142
|
+
if (p == NULL && GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
143
|
+
(const char *)ll_bcsym, &h))
|
144
|
+
p = (const char *)GetProcAddress(h, sym);
|
145
|
+
return p;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
#else
|
150
|
+
|
151
|
+
#undef PACKAGE_LIB_FAIL
|
152
|
+
#define PACKAGE_LIB_FAIL "absent"
|
153
|
+
|
154
|
+
#define DLMSG "dynamic libraries not enabled; no support for target OS"
|
155
|
+
|
156
|
+
static void ll_unloadlib(void *lib)
|
157
|
+
{
|
158
|
+
UNUSED(lib);
|
159
|
+
}
|
160
|
+
|
161
|
+
static void *ll_load(lua_State *L, const char *path, int gl)
|
162
|
+
{
|
163
|
+
UNUSED(path); UNUSED(gl);
|
164
|
+
lua_pushliteral(L, DLMSG);
|
165
|
+
return NULL;
|
166
|
+
}
|
167
|
+
|
168
|
+
static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
|
169
|
+
{
|
170
|
+
UNUSED(lib); UNUSED(sym);
|
171
|
+
lua_pushliteral(L, DLMSG);
|
172
|
+
return NULL;
|
173
|
+
}
|
174
|
+
|
175
|
+
static const char *ll_bcsym(void *lib, const char *sym)
|
176
|
+
{
|
177
|
+
UNUSED(lib); UNUSED(sym);
|
178
|
+
return NULL;
|
179
|
+
}
|
180
|
+
|
181
|
+
#endif
|
182
|
+
|
183
|
+
/* ------------------------------------------------------------------------ */
|
184
|
+
|
185
|
+
static void **ll_register(lua_State *L, const char *path)
|
186
|
+
{
|
187
|
+
void **plib;
|
188
|
+
lua_pushfstring(L, "LOADLIB: %s", path);
|
189
|
+
lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */
|
190
|
+
if (!lua_isnil(L, -1)) { /* is there an entry? */
|
191
|
+
plib = (void **)lua_touserdata(L, -1);
|
192
|
+
} else { /* no entry yet; create one */
|
193
|
+
lua_pop(L, 1);
|
194
|
+
plib = (void **)lua_newuserdata(L, sizeof(void *));
|
195
|
+
*plib = NULL;
|
196
|
+
luaL_getmetatable(L, "_LOADLIB");
|
197
|
+
lua_setmetatable(L, -2);
|
198
|
+
lua_pushfstring(L, "LOADLIB: %s", path);
|
199
|
+
lua_pushvalue(L, -2);
|
200
|
+
lua_settable(L, LUA_REGISTRYINDEX);
|
201
|
+
}
|
202
|
+
return plib;
|
203
|
+
}
|
204
|
+
|
205
|
+
static const char *mksymname(lua_State *L, const char *modname,
|
206
|
+
const char *prefix)
|
207
|
+
{
|
208
|
+
const char *funcname;
|
209
|
+
const char *mark = strchr(modname, *LUA_IGMARK);
|
210
|
+
if (mark) modname = mark + 1;
|
211
|
+
funcname = luaL_gsub(L, modname, ".", "_");
|
212
|
+
funcname = lua_pushfstring(L, prefix, funcname);
|
213
|
+
lua_remove(L, -2); /* remove 'gsub' result */
|
214
|
+
return funcname;
|
215
|
+
}
|
216
|
+
|
217
|
+
static int ll_loadfunc(lua_State *L, const char *path, const char *name, int r)
|
218
|
+
{
|
219
|
+
void **reg = ll_register(L, path);
|
220
|
+
if (*reg == NULL) *reg = ll_load(L, path, (*name == '*'));
|
221
|
+
if (*reg == NULL) {
|
222
|
+
return PACKAGE_ERR_LIB; /* Unable to load library. */
|
223
|
+
} else if (*name == '*') { /* Only load library into global namespace. */
|
224
|
+
lua_pushboolean(L, 1);
|
225
|
+
return 0;
|
226
|
+
} else {
|
227
|
+
const char *sym = r ? name : mksymname(L, name, SYMPREFIX_CF);
|
228
|
+
lua_CFunction f = ll_sym(L, *reg, sym);
|
229
|
+
if (f) {
|
230
|
+
lua_pushcfunction(L, f);
|
231
|
+
return 0;
|
232
|
+
}
|
233
|
+
if (!r) {
|
234
|
+
const char *bcdata = ll_bcsym(*reg, mksymname(L, name, SYMPREFIX_BC));
|
235
|
+
lua_pop(L, 1);
|
236
|
+
if (bcdata) {
|
237
|
+
if (luaL_loadbuffer(L, bcdata, LJ_MAX_BUF, name) != 0)
|
238
|
+
return PACKAGE_ERR_LOAD;
|
239
|
+
return 0;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
return PACKAGE_ERR_FUNC; /* Unable to find function. */
|
243
|
+
}
|
244
|
+
}
|
245
|
+
|
246
|
+
static int lj_cf_package_loadlib(lua_State *L)
|
247
|
+
{
|
248
|
+
const char *path = luaL_checkstring(L, 1);
|
249
|
+
const char *init = luaL_checkstring(L, 2);
|
250
|
+
int st = ll_loadfunc(L, path, init, 1);
|
251
|
+
if (st == 0) { /* no errors? */
|
252
|
+
return 1; /* return the loaded function */
|
253
|
+
} else { /* error; error message is on stack top */
|
254
|
+
lua_pushnil(L);
|
255
|
+
lua_insert(L, -2);
|
256
|
+
lua_pushstring(L, (st == PACKAGE_ERR_LIB) ? PACKAGE_LIB_FAIL : "init");
|
257
|
+
return 3; /* return nil, error message, and where */
|
258
|
+
}
|
259
|
+
}
|
260
|
+
|
261
|
+
static int lj_cf_package_unloadlib(lua_State *L)
|
262
|
+
{
|
263
|
+
void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB");
|
264
|
+
if (*lib) ll_unloadlib(*lib);
|
265
|
+
*lib = NULL; /* mark library as closed */
|
266
|
+
return 0;
|
267
|
+
}
|
268
|
+
|
269
|
+
/* ------------------------------------------------------------------------ */
|
270
|
+
|
271
|
+
static int readable(const char *filename)
|
272
|
+
{
|
273
|
+
FILE *f = fopen(filename, "r"); /* try to open file */
|
274
|
+
if (f == NULL) return 0; /* open failed */
|
275
|
+
fclose(f);
|
276
|
+
return 1;
|
277
|
+
}
|
278
|
+
|
279
|
+
static const char *pushnexttemplate(lua_State *L, const char *path)
|
280
|
+
{
|
281
|
+
const char *l;
|
282
|
+
while (*path == *LUA_PATHSEP) path++; /* skip separators */
|
283
|
+
if (*path == '\0') return NULL; /* no more templates */
|
284
|
+
l = strchr(path, *LUA_PATHSEP); /* find next separator */
|
285
|
+
if (l == NULL) l = path + strlen(path);
|
286
|
+
lua_pushlstring(L, path, (size_t)(l - path)); /* template */
|
287
|
+
return l;
|
288
|
+
}
|
289
|
+
|
290
|
+
static const char *searchpath (lua_State *L, const char *name,
|
291
|
+
const char *path, const char *sep,
|
292
|
+
const char *dirsep)
|
293
|
+
{
|
294
|
+
luaL_Buffer msg; /* to build error message */
|
295
|
+
luaL_buffinit(L, &msg);
|
296
|
+
if (*sep != '\0') /* non-empty separator? */
|
297
|
+
name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */
|
298
|
+
while ((path = pushnexttemplate(L, path)) != NULL) {
|
299
|
+
const char *filename = luaL_gsub(L, lua_tostring(L, -1),
|
300
|
+
LUA_PATH_MARK, name);
|
301
|
+
lua_remove(L, -2); /* remove path template */
|
302
|
+
if (readable(filename)) /* does file exist and is readable? */
|
303
|
+
return filename; /* return that file name */
|
304
|
+
lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
|
305
|
+
lua_remove(L, -2); /* remove file name */
|
306
|
+
luaL_addvalue(&msg); /* concatenate error msg. entry */
|
307
|
+
}
|
308
|
+
luaL_pushresult(&msg); /* create error message */
|
309
|
+
return NULL; /* not found */
|
310
|
+
}
|
311
|
+
|
312
|
+
static int lj_cf_package_searchpath(lua_State *L)
|
313
|
+
{
|
314
|
+
const char *f = searchpath(L, luaL_checkstring(L, 1),
|
315
|
+
luaL_checkstring(L, 2),
|
316
|
+
luaL_optstring(L, 3, "."),
|
317
|
+
luaL_optstring(L, 4, LUA_DIRSEP));
|
318
|
+
if (f != NULL) {
|
319
|
+
return 1;
|
320
|
+
} else { /* error message is on top of the stack */
|
321
|
+
lua_pushnil(L);
|
322
|
+
lua_insert(L, -2);
|
323
|
+
return 2; /* return nil + error message */
|
324
|
+
}
|
325
|
+
}
|
326
|
+
|
327
|
+
static const char *findfile(lua_State *L, const char *name,
|
328
|
+
const char *pname)
|
329
|
+
{
|
330
|
+
const char *path;
|
331
|
+
lua_getfield(L, LUA_ENVIRONINDEX, pname);
|
332
|
+
path = lua_tostring(L, -1);
|
333
|
+
if (path == NULL)
|
334
|
+
luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
|
335
|
+
return searchpath(L, name, path, ".", LUA_DIRSEP);
|
336
|
+
}
|
337
|
+
|
338
|
+
static void loaderror(lua_State *L, const char *filename)
|
339
|
+
{
|
340
|
+
luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s",
|
341
|
+
lua_tostring(L, 1), filename, lua_tostring(L, -1));
|
342
|
+
}
|
343
|
+
|
344
|
+
static int lj_cf_package_loader_lua(lua_State *L)
|
345
|
+
{
|
346
|
+
const char *filename;
|
347
|
+
const char *name = luaL_checkstring(L, 1);
|
348
|
+
filename = findfile(L, name, "path");
|
349
|
+
if (filename == NULL) return 1; /* library not found in this path */
|
350
|
+
if (luaL_loadfile(L, filename) != 0)
|
351
|
+
loaderror(L, filename);
|
352
|
+
return 1; /* library loaded successfully */
|
353
|
+
}
|
354
|
+
|
355
|
+
static int lj_cf_package_loader_c(lua_State *L)
|
356
|
+
{
|
357
|
+
const char *name = luaL_checkstring(L, 1);
|
358
|
+
const char *filename = findfile(L, name, "cpath");
|
359
|
+
if (filename == NULL) return 1; /* library not found in this path */
|
360
|
+
if (ll_loadfunc(L, filename, name, 0) != 0)
|
361
|
+
loaderror(L, filename);
|
362
|
+
return 1; /* library loaded successfully */
|
363
|
+
}
|
364
|
+
|
365
|
+
static int lj_cf_package_loader_croot(lua_State *L)
|
366
|
+
{
|
367
|
+
const char *filename;
|
368
|
+
const char *name = luaL_checkstring(L, 1);
|
369
|
+
const char *p = strchr(name, '.');
|
370
|
+
int st;
|
371
|
+
if (p == NULL) return 0; /* is root */
|
372
|
+
lua_pushlstring(L, name, (size_t)(p - name));
|
373
|
+
filename = findfile(L, lua_tostring(L, -1), "cpath");
|
374
|
+
if (filename == NULL) return 1; /* root not found */
|
375
|
+
if ((st = ll_loadfunc(L, filename, name, 0)) != 0) {
|
376
|
+
if (st != PACKAGE_ERR_FUNC) loaderror(L, filename); /* real error */
|
377
|
+
lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
|
378
|
+
name, filename);
|
379
|
+
return 1; /* function not found */
|
380
|
+
}
|
381
|
+
return 1;
|
382
|
+
}
|
383
|
+
|
384
|
+
static int lj_cf_package_loader_preload(lua_State *L)
|
385
|
+
{
|
386
|
+
const char *name = luaL_checkstring(L, 1);
|
387
|
+
lua_getfield(L, LUA_ENVIRONINDEX, "preload");
|
388
|
+
if (!lua_istable(L, -1))
|
389
|
+
luaL_error(L, LUA_QL("package.preload") " must be a table");
|
390
|
+
lua_getfield(L, -1, name);
|
391
|
+
if (lua_isnil(L, -1)) { /* Not found? */
|
392
|
+
const char *bcname = mksymname(L, name, SYMPREFIX_BC);
|
393
|
+
const char *bcdata = ll_bcsym(NULL, bcname);
|
394
|
+
if (bcdata == NULL || luaL_loadbuffer(L, bcdata, LJ_MAX_BUF, name) != 0)
|
395
|
+
lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
|
396
|
+
}
|
397
|
+
return 1;
|
398
|
+
}
|
399
|
+
|
400
|
+
/* ------------------------------------------------------------------------ */
|
401
|
+
|
402
|
+
static const int sentinel_ = 0;
|
403
|
+
#define sentinel ((void *)&sentinel_)
|
404
|
+
|
405
|
+
static int lj_cf_package_require(lua_State *L)
|
406
|
+
{
|
407
|
+
const char *name = luaL_checkstring(L, 1);
|
408
|
+
int i;
|
409
|
+
lua_settop(L, 1); /* _LOADED table will be at index 2 */
|
410
|
+
lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
|
411
|
+
lua_getfield(L, 2, name);
|
412
|
+
if (lua_toboolean(L, -1)) { /* is it there? */
|
413
|
+
if (lua_touserdata(L, -1) == sentinel) /* check loops */
|
414
|
+
luaL_error(L, "loop or previous error loading module " LUA_QS, name);
|
415
|
+
return 1; /* package is already loaded */
|
416
|
+
}
|
417
|
+
/* else must load it; iterate over available loaders */
|
418
|
+
lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
|
419
|
+
if (!lua_istable(L, -1))
|
420
|
+
luaL_error(L, LUA_QL("package.loaders") " must be a table");
|
421
|
+
lua_pushliteral(L, ""); /* error message accumulator */
|
422
|
+
for (i = 1; ; i++) {
|
423
|
+
lua_rawgeti(L, -2, i); /* get a loader */
|
424
|
+
if (lua_isnil(L, -1))
|
425
|
+
luaL_error(L, "module " LUA_QS " not found:%s",
|
426
|
+
name, lua_tostring(L, -2));
|
427
|
+
lua_pushstring(L, name);
|
428
|
+
lua_call(L, 1, 1); /* call it */
|
429
|
+
if (lua_isfunction(L, -1)) /* did it find module? */
|
430
|
+
break; /* module loaded successfully */
|
431
|
+
else if (lua_isstring(L, -1)) /* loader returned error message? */
|
432
|
+
lua_concat(L, 2); /* accumulate it */
|
433
|
+
else
|
434
|
+
lua_pop(L, 1);
|
435
|
+
}
|
436
|
+
lua_pushlightuserdata(L, sentinel);
|
437
|
+
lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
|
438
|
+
lua_pushstring(L, name); /* pass name as argument to module */
|
439
|
+
lua_call(L, 1, 1); /* run loaded module */
|
440
|
+
if (!lua_isnil(L, -1)) /* non-nil return? */
|
441
|
+
lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
|
442
|
+
lua_getfield(L, 2, name);
|
443
|
+
if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */
|
444
|
+
lua_pushboolean(L, 1); /* use true as result */
|
445
|
+
lua_pushvalue(L, -1); /* extra copy to be returned */
|
446
|
+
lua_setfield(L, 2, name); /* _LOADED[name] = true */
|
447
|
+
}
|
448
|
+
lj_lib_checkfpu(L);
|
449
|
+
return 1;
|
450
|
+
}
|
451
|
+
|
452
|
+
/* ------------------------------------------------------------------------ */
|
453
|
+
|
454
|
+
static void setfenv(lua_State *L)
|
455
|
+
{
|
456
|
+
lua_Debug ar;
|
457
|
+
if (lua_getstack(L, 1, &ar) == 0 ||
|
458
|
+
lua_getinfo(L, "f", &ar) == 0 || /* get calling function */
|
459
|
+
lua_iscfunction(L, -1))
|
460
|
+
luaL_error(L, LUA_QL("module") " not called from a Lua function");
|
461
|
+
lua_pushvalue(L, -2);
|
462
|
+
lua_setfenv(L, -2);
|
463
|
+
lua_pop(L, 1);
|
464
|
+
}
|
465
|
+
|
466
|
+
static void dooptions(lua_State *L, int n)
|
467
|
+
{
|
468
|
+
int i;
|
469
|
+
for (i = 2; i <= n; i++) {
|
470
|
+
lua_pushvalue(L, i); /* get option (a function) */
|
471
|
+
lua_pushvalue(L, -2); /* module */
|
472
|
+
lua_call(L, 1, 0);
|
473
|
+
}
|
474
|
+
}
|
475
|
+
|
476
|
+
static void modinit(lua_State *L, const char *modname)
|
477
|
+
{
|
478
|
+
const char *dot;
|
479
|
+
lua_pushvalue(L, -1);
|
480
|
+
lua_setfield(L, -2, "_M"); /* module._M = module */
|
481
|
+
lua_pushstring(L, modname);
|
482
|
+
lua_setfield(L, -2, "_NAME");
|
483
|
+
dot = strrchr(modname, '.'); /* look for last dot in module name */
|
484
|
+
if (dot == NULL) dot = modname; else dot++;
|
485
|
+
/* set _PACKAGE as package name (full module name minus last part) */
|
486
|
+
lua_pushlstring(L, modname, (size_t)(dot - modname));
|
487
|
+
lua_setfield(L, -2, "_PACKAGE");
|
488
|
+
}
|
489
|
+
|
490
|
+
static int lj_cf_package_module(lua_State *L)
|
491
|
+
{
|
492
|
+
const char *modname = luaL_checkstring(L, 1);
|
493
|
+
int loaded = lua_gettop(L) + 1; /* index of _LOADED table */
|
494
|
+
lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
|
495
|
+
lua_getfield(L, loaded, modname); /* get _LOADED[modname] */
|
496
|
+
if (!lua_istable(L, -1)) { /* not found? */
|
497
|
+
lua_pop(L, 1); /* remove previous result */
|
498
|
+
/* try global variable (and create one if it does not exist) */
|
499
|
+
if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL)
|
500
|
+
lj_err_callerv(L, LJ_ERR_BADMODN, modname);
|
501
|
+
lua_pushvalue(L, -1);
|
502
|
+
lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */
|
503
|
+
}
|
504
|
+
/* check whether table already has a _NAME field */
|
505
|
+
lua_getfield(L, -1, "_NAME");
|
506
|
+
if (!lua_isnil(L, -1)) { /* is table an initialized module? */
|
507
|
+
lua_pop(L, 1);
|
508
|
+
} else { /* no; initialize it */
|
509
|
+
lua_pop(L, 1);
|
510
|
+
modinit(L, modname);
|
511
|
+
}
|
512
|
+
lua_pushvalue(L, -1);
|
513
|
+
setfenv(L);
|
514
|
+
dooptions(L, loaded - 1);
|
515
|
+
return 0;
|
516
|
+
}
|
517
|
+
|
518
|
+
static int lj_cf_package_seeall(lua_State *L)
|
519
|
+
{
|
520
|
+
luaL_checktype(L, 1, LUA_TTABLE);
|
521
|
+
if (!lua_getmetatable(L, 1)) {
|
522
|
+
lua_createtable(L, 0, 1); /* create new metatable */
|
523
|
+
lua_pushvalue(L, -1);
|
524
|
+
lua_setmetatable(L, 1);
|
525
|
+
}
|
526
|
+
lua_pushvalue(L, LUA_GLOBALSINDEX);
|
527
|
+
lua_setfield(L, -2, "__index"); /* mt.__index = _G */
|
528
|
+
return 0;
|
529
|
+
}
|
530
|
+
|
531
|
+
/* ------------------------------------------------------------------------ */
|
532
|
+
|
533
|
+
#define AUXMARK "\1"
|
534
|
+
|
535
|
+
static void setpath(lua_State *L, const char *fieldname, const char *envname,
|
536
|
+
const char *def, int noenv)
|
537
|
+
{
|
538
|
+
#if LJ_TARGET_CONSOLE
|
539
|
+
const char *path = NULL;
|
540
|
+
UNUSED(envname);
|
541
|
+
#else
|
542
|
+
const char *path = getenv(envname);
|
543
|
+
#endif
|
544
|
+
if (path == NULL || noenv) {
|
545
|
+
lua_pushstring(L, def);
|
546
|
+
} else {
|
547
|
+
path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,
|
548
|
+
LUA_PATHSEP AUXMARK LUA_PATHSEP);
|
549
|
+
luaL_gsub(L, path, AUXMARK, def);
|
550
|
+
lua_remove(L, -2);
|
551
|
+
}
|
552
|
+
setprogdir(L);
|
553
|
+
lua_setfield(L, -2, fieldname);
|
554
|
+
}
|
555
|
+
|
556
|
+
static const luaL_Reg package_lib[] = {
|
557
|
+
{ "loadlib", lj_cf_package_loadlib },
|
558
|
+
{ "searchpath", lj_cf_package_searchpath },
|
559
|
+
{ "seeall", lj_cf_package_seeall },
|
560
|
+
{ NULL, NULL }
|
561
|
+
};
|
562
|
+
|
563
|
+
static const luaL_Reg package_global[] = {
|
564
|
+
{ "module", lj_cf_package_module },
|
565
|
+
{ "require", lj_cf_package_require },
|
566
|
+
{ NULL, NULL }
|
567
|
+
};
|
568
|
+
|
569
|
+
static const lua_CFunction package_loaders[] =
|
570
|
+
{
|
571
|
+
lj_cf_package_loader_preload,
|
572
|
+
lj_cf_package_loader_lua,
|
573
|
+
lj_cf_package_loader_c,
|
574
|
+
lj_cf_package_loader_croot,
|
575
|
+
NULL
|
576
|
+
};
|
577
|
+
|
578
|
+
LUALIB_API int luaopen_package(lua_State *L)
|
579
|
+
{
|
580
|
+
int i;
|
581
|
+
int noenv;
|
582
|
+
luaL_newmetatable(L, "_LOADLIB");
|
583
|
+
lj_lib_pushcf(L, lj_cf_package_unloadlib, 1);
|
584
|
+
lua_setfield(L, -2, "__gc");
|
585
|
+
luaL_register(L, LUA_LOADLIBNAME, package_lib);
|
586
|
+
lua_pushvalue(L, -1);
|
587
|
+
lua_replace(L, LUA_ENVIRONINDEX);
|
588
|
+
lua_createtable(L, sizeof(package_loaders)/sizeof(package_loaders[0])-1, 0);
|
589
|
+
for (i = 0; package_loaders[i] != NULL; i++) {
|
590
|
+
lj_lib_pushcf(L, package_loaders[i], 1);
|
591
|
+
lua_rawseti(L, -2, i+1);
|
592
|
+
}
|
593
|
+
lua_setfield(L, -2, "loaders");
|
594
|
+
lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
|
595
|
+
noenv = lua_toboolean(L, -1);
|
596
|
+
lua_pop(L, 1);
|
597
|
+
setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT, noenv);
|
598
|
+
setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT, noenv);
|
599
|
+
lua_pushliteral(L, LUA_PATH_CONFIG);
|
600
|
+
lua_setfield(L, -2, "config");
|
601
|
+
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
|
602
|
+
lua_setfield(L, -2, "loaded");
|
603
|
+
luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 4);
|
604
|
+
lua_setfield(L, -2, "preload");
|
605
|
+
lua_pushvalue(L, LUA_GLOBALSINDEX);
|
606
|
+
luaL_register(L, NULL, package_global);
|
607
|
+
lua_pop(L, 1);
|
608
|
+
return 1;
|
609
|
+
}
|
610
|
+
|