immunio 0.15.4 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (454) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +0 -27
  3. data/ext/immunio/Rakefile +9 -0
  4. data/lib/immunio/plugins/active_record.rb +1 -1
  5. data/lib/immunio/plugins/active_record_relation.rb +1 -1
  6. data/lib/immunio/plugins/environment_reporter.rb +20 -0
  7. data/lib/immunio/rufus_lua_ext/ref.rb +1 -3
  8. data/lib/immunio/version.rb +1 -1
  9. data/lib/immunio/vm.rb +1 -2
  10. data/lua-hooks/Makefile +97 -0
  11. data/lua-hooks/ext/all.c +41 -52
  12. data/lua-hooks/ext/all.o +0 -0
  13. data/lua-hooks/ext/libinjection/libinjection_html5.o +0 -0
  14. data/lua-hooks/ext/libinjection/libinjection_sqli.o +0 -0
  15. data/lua-hooks/ext/libinjection/libinjection_xss.o +0 -0
  16. data/lua-hooks/ext/libinjection/lualib.c +2 -2
  17. data/lua-hooks/ext/lpeg/lpcap.c +2 -2
  18. data/lua-hooks/ext/lpeg/lpcap.o +0 -0
  19. data/lua-hooks/ext/lpeg/lpcode.c +2 -2
  20. data/lua-hooks/ext/lpeg/lpcode.h +1 -1
  21. data/lua-hooks/ext/lpeg/lpcode.o +0 -0
  22. data/lua-hooks/ext/lpeg/lpprint.o +0 -0
  23. data/lua-hooks/ext/lpeg/lptree.c +2 -2
  24. data/lua-hooks/ext/lpeg/lptypes.h +1 -1
  25. data/lua-hooks/ext/lpeg/lpvm.c +2 -2
  26. data/lua-hooks/ext/lpeg/lpvm.o +0 -0
  27. data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +16 -3
  28. data/lua-hooks/ext/lua-snapshot/snapshot.c +14 -7
  29. data/lua-hooks/ext/luajit/COPYRIGHT +56 -0
  30. data/lua-hooks/ext/luajit/Makefile +159 -0
  31. data/lua-hooks/ext/luajit/README +16 -0
  32. data/lua-hooks/ext/luajit/doc/bluequad-print.css +166 -0
  33. data/lua-hooks/ext/luajit/doc/bluequad.css +325 -0
  34. data/lua-hooks/ext/luajit/doc/changes.html +804 -0
  35. data/lua-hooks/ext/luajit/doc/contact.html +104 -0
  36. data/lua-hooks/ext/luajit/doc/ext_c_api.html +189 -0
  37. data/lua-hooks/ext/luajit/doc/ext_ffi.html +332 -0
  38. data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +570 -0
  39. data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +1261 -0
  40. data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +603 -0
  41. data/lua-hooks/ext/luajit/doc/ext_jit.html +201 -0
  42. data/lua-hooks/ext/luajit/doc/ext_profiler.html +365 -0
  43. data/lua-hooks/ext/luajit/doc/extensions.html +448 -0
  44. data/lua-hooks/ext/luajit/doc/faq.html +186 -0
  45. data/lua-hooks/ext/luajit/doc/img/contact.png +0 -0
  46. data/lua-hooks/ext/luajit/doc/install.html +659 -0
  47. data/lua-hooks/ext/luajit/doc/luajit.html +236 -0
  48. data/lua-hooks/ext/luajit/doc/running.html +309 -0
  49. data/lua-hooks/ext/luajit/doc/status.html +118 -0
  50. data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +456 -0
  51. data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1125 -0
  52. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +518 -0
  53. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1166 -0
  54. data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +416 -0
  55. data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +953 -0
  56. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +419 -0
  57. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1919 -0
  58. data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +83 -0
  59. data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +12 -0
  60. data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +471 -0
  61. data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +1945 -0
  62. data/lua-hooks/ext/luajit/dynasm/dynasm.lua +1094 -0
  63. data/lua-hooks/ext/luajit/etc/luajit.1 +88 -0
  64. data/lua-hooks/ext/luajit/etc/luajit.pc +25 -0
  65. data/lua-hooks/ext/luajit/src/Makefile +697 -0
  66. data/lua-hooks/ext/luajit/src/Makefile.dep +244 -0
  67. data/lua-hooks/ext/luajit/src/host/README +4 -0
  68. data/lua-hooks/ext/luajit/src/host/buildvm +0 -0
  69. data/lua-hooks/ext/luajit/src/host/buildvm.c +518 -0
  70. data/lua-hooks/ext/luajit/src/host/buildvm.h +105 -0
  71. data/lua-hooks/ext/luajit/src/host/buildvm.o +0 -0
  72. data/lua-hooks/ext/luajit/src/host/buildvm_arch.h +7449 -0
  73. data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +345 -0
  74. data/lua-hooks/ext/luajit/src/host/buildvm_asm.o +0 -0
  75. data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +229 -0
  76. data/lua-hooks/ext/luajit/src/host/buildvm_fold.o +0 -0
  77. data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +457 -0
  78. data/lua-hooks/ext/luajit/src/host/buildvm_lib.o +0 -0
  79. data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +45 -0
  80. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +368 -0
  81. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.o +0 -0
  82. data/lua-hooks/ext/luajit/src/host/genlibbc.lua +197 -0
  83. data/lua-hooks/ext/luajit/src/host/genminilua.lua +428 -0
  84. data/lua-hooks/ext/luajit/src/host/minilua +0 -0
  85. data/lua-hooks/ext/luajit/src/host/minilua.c +7770 -0
  86. data/lua-hooks/ext/luajit/src/host/minilua.o +0 -0
  87. data/lua-hooks/ext/luajit/src/jit/bc.lua +190 -0
  88. data/lua-hooks/ext/luajit/src/jit/bcsave.lua +661 -0
  89. data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +689 -0
  90. data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +428 -0
  91. data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +17 -0
  92. data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +591 -0
  93. data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +17 -0
  94. data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +838 -0
  95. data/lua-hooks/ext/luajit/src/jit/dump.lua +706 -0
  96. data/lua-hooks/ext/luajit/src/jit/p.lua +310 -0
  97. data/lua-hooks/ext/luajit/src/jit/v.lua +170 -0
  98. data/lua-hooks/ext/luajit/src/jit/vmdef.lua +362 -0
  99. data/lua-hooks/ext/luajit/src/jit/zone.lua +45 -0
  100. data/lua-hooks/ext/{lua → luajit/src}/lauxlib.h +10 -17
  101. data/lua-hooks/ext/luajit/src/lib_aux.c +356 -0
  102. data/lua-hooks/ext/luajit/src/lib_aux.o +0 -0
  103. data/lua-hooks/ext/luajit/src/lib_aux_dyn.o +0 -0
  104. data/lua-hooks/ext/luajit/src/lib_base.c +664 -0
  105. data/lua-hooks/ext/luajit/src/lib_base.o +0 -0
  106. data/lua-hooks/ext/luajit/src/lib_base_dyn.o +0 -0
  107. data/lua-hooks/ext/luajit/src/lib_bit.c +180 -0
  108. data/lua-hooks/ext/luajit/src/lib_bit.o +0 -0
  109. data/lua-hooks/ext/luajit/src/lib_bit_dyn.o +0 -0
  110. data/lua-hooks/ext/luajit/src/lib_debug.c +405 -0
  111. data/lua-hooks/ext/luajit/src/lib_debug.o +0 -0
  112. data/lua-hooks/ext/luajit/src/lib_debug_dyn.o +0 -0
  113. data/lua-hooks/ext/luajit/src/lib_ffi.c +872 -0
  114. data/lua-hooks/ext/luajit/src/lib_ffi.o +0 -0
  115. data/lua-hooks/ext/luajit/src/lib_ffi_dyn.o +0 -0
  116. data/lua-hooks/ext/luajit/src/lib_init.c +55 -0
  117. data/lua-hooks/ext/luajit/src/lib_init.o +0 -0
  118. data/lua-hooks/ext/luajit/src/lib_init_dyn.o +0 -0
  119. data/lua-hooks/ext/luajit/src/lib_io.c +541 -0
  120. data/lua-hooks/ext/luajit/src/lib_io.o +0 -0
  121. data/lua-hooks/ext/luajit/src/lib_io_dyn.o +0 -0
  122. data/lua-hooks/ext/luajit/src/lib_jit.c +767 -0
  123. data/lua-hooks/ext/luajit/src/lib_jit.o +0 -0
  124. data/lua-hooks/ext/luajit/src/lib_jit_dyn.o +0 -0
  125. data/lua-hooks/ext/luajit/src/lib_math.c +230 -0
  126. data/lua-hooks/ext/luajit/src/lib_math.o +0 -0
  127. data/lua-hooks/ext/luajit/src/lib_math_dyn.o +0 -0
  128. data/lua-hooks/ext/luajit/src/lib_os.c +292 -0
  129. data/lua-hooks/ext/luajit/src/lib_os.o +0 -0
  130. data/lua-hooks/ext/luajit/src/lib_os_dyn.o +0 -0
  131. data/lua-hooks/ext/luajit/src/lib_package.c +610 -0
  132. data/lua-hooks/ext/luajit/src/lib_package.o +0 -0
  133. data/lua-hooks/ext/luajit/src/lib_package_dyn.o +0 -0
  134. data/lua-hooks/ext/luajit/src/lib_string.c +752 -0
  135. data/lua-hooks/ext/luajit/src/lib_string.o +0 -0
  136. data/lua-hooks/ext/luajit/src/lib_string_dyn.o +0 -0
  137. data/lua-hooks/ext/luajit/src/lib_table.c +307 -0
  138. data/lua-hooks/ext/luajit/src/lib_table.o +0 -0
  139. data/lua-hooks/ext/luajit/src/lib_table_dyn.o +0 -0
  140. data/lua-hooks/ext/luajit/src/libluajit.a +0 -0
  141. data/lua-hooks/ext/luajit/src/libluajit.so +0 -0
  142. data/lua-hooks/ext/luajit/src/lj.supp +26 -0
  143. data/lua-hooks/ext/luajit/src/lj_alloc.c +1398 -0
  144. data/lua-hooks/ext/luajit/src/lj_alloc.h +17 -0
  145. data/lua-hooks/ext/luajit/src/lj_alloc.o +0 -0
  146. data/lua-hooks/ext/luajit/src/lj_alloc_dyn.o +0 -0
  147. data/lua-hooks/ext/luajit/src/lj_api.c +1210 -0
  148. data/lua-hooks/ext/luajit/src/lj_api.o +0 -0
  149. data/lua-hooks/ext/luajit/src/lj_api_dyn.o +0 -0
  150. data/lua-hooks/ext/luajit/src/lj_arch.h +509 -0
  151. data/lua-hooks/ext/luajit/src/lj_asm.c +2278 -0
  152. data/lua-hooks/ext/luajit/src/lj_asm.h +17 -0
  153. data/lua-hooks/ext/luajit/src/lj_asm.o +0 -0
  154. data/lua-hooks/ext/luajit/src/lj_asm_arm.h +2217 -0
  155. data/lua-hooks/ext/luajit/src/lj_asm_dyn.o +0 -0
  156. data/lua-hooks/ext/luajit/src/lj_asm_mips.h +1833 -0
  157. data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +2015 -0
  158. data/lua-hooks/ext/luajit/src/lj_asm_x86.h +2634 -0
  159. data/lua-hooks/ext/luajit/src/lj_bc.c +14 -0
  160. data/lua-hooks/ext/luajit/src/lj_bc.h +265 -0
  161. data/lua-hooks/ext/luajit/src/lj_bc.o +0 -0
  162. data/lua-hooks/ext/luajit/src/lj_bc_dyn.o +0 -0
  163. data/lua-hooks/ext/luajit/src/lj_bcdef.h +220 -0
  164. data/lua-hooks/ext/luajit/src/lj_bcdump.h +68 -0
  165. data/lua-hooks/ext/luajit/src/lj_bcread.c +457 -0
  166. data/lua-hooks/ext/luajit/src/lj_bcread.o +0 -0
  167. data/lua-hooks/ext/luajit/src/lj_bcread_dyn.o +0 -0
  168. data/lua-hooks/ext/luajit/src/lj_bcwrite.c +361 -0
  169. data/lua-hooks/ext/luajit/src/lj_bcwrite.o +0 -0
  170. data/lua-hooks/ext/luajit/src/lj_bcwrite_dyn.o +0 -0
  171. data/lua-hooks/ext/luajit/src/lj_buf.c +234 -0
  172. data/lua-hooks/ext/luajit/src/lj_buf.h +105 -0
  173. data/lua-hooks/ext/luajit/src/lj_buf.o +0 -0
  174. data/lua-hooks/ext/luajit/src/lj_buf_dyn.o +0 -0
  175. data/lua-hooks/ext/luajit/src/lj_carith.c +429 -0
  176. data/lua-hooks/ext/luajit/src/lj_carith.h +37 -0
  177. data/lua-hooks/ext/luajit/src/lj_carith.o +0 -0
  178. data/lua-hooks/ext/luajit/src/lj_carith_dyn.o +0 -0
  179. data/lua-hooks/ext/luajit/src/lj_ccall.c +984 -0
  180. data/lua-hooks/ext/luajit/src/lj_ccall.h +178 -0
  181. data/lua-hooks/ext/luajit/src/lj_ccall.o +0 -0
  182. data/lua-hooks/ext/luajit/src/lj_ccall_dyn.o +0 -0
  183. data/lua-hooks/ext/luajit/src/lj_ccallback.c +712 -0
  184. data/lua-hooks/ext/luajit/src/lj_ccallback.h +25 -0
  185. data/lua-hooks/ext/luajit/src/lj_ccallback.o +0 -0
  186. data/lua-hooks/ext/luajit/src/lj_ccallback_dyn.o +0 -0
  187. data/lua-hooks/ext/luajit/src/lj_cconv.c +752 -0
  188. data/lua-hooks/ext/luajit/src/lj_cconv.h +70 -0
  189. data/lua-hooks/ext/luajit/src/lj_cconv.o +0 -0
  190. data/lua-hooks/ext/luajit/src/lj_cconv_dyn.o +0 -0
  191. data/lua-hooks/ext/luajit/src/lj_cdata.c +288 -0
  192. data/lua-hooks/ext/luajit/src/lj_cdata.h +76 -0
  193. data/lua-hooks/ext/luajit/src/lj_cdata.o +0 -0
  194. data/lua-hooks/ext/luajit/src/lj_cdata_dyn.o +0 -0
  195. data/lua-hooks/ext/luajit/src/lj_char.c +43 -0
  196. data/lua-hooks/ext/luajit/src/lj_char.h +42 -0
  197. data/lua-hooks/ext/luajit/src/lj_char.o +0 -0
  198. data/lua-hooks/ext/luajit/src/lj_char_dyn.o +0 -0
  199. data/lua-hooks/ext/luajit/src/lj_clib.c +418 -0
  200. data/lua-hooks/ext/luajit/src/lj_clib.h +29 -0
  201. data/lua-hooks/ext/luajit/src/lj_clib.o +0 -0
  202. data/lua-hooks/ext/luajit/src/lj_clib_dyn.o +0 -0
  203. data/lua-hooks/ext/luajit/src/lj_cparse.c +1862 -0
  204. data/lua-hooks/ext/luajit/src/lj_cparse.h +65 -0
  205. data/lua-hooks/ext/luajit/src/lj_cparse.o +0 -0
  206. data/lua-hooks/ext/luajit/src/lj_cparse_dyn.o +0 -0
  207. data/lua-hooks/ext/luajit/src/lj_crecord.c +1834 -0
  208. data/lua-hooks/ext/luajit/src/lj_crecord.h +38 -0
  209. data/lua-hooks/ext/luajit/src/lj_crecord.o +0 -0
  210. data/lua-hooks/ext/luajit/src/lj_crecord_dyn.o +0 -0
  211. data/lua-hooks/ext/luajit/src/lj_ctype.c +635 -0
  212. data/lua-hooks/ext/luajit/src/lj_ctype.h +461 -0
  213. data/lua-hooks/ext/luajit/src/lj_ctype.o +0 -0
  214. data/lua-hooks/ext/luajit/src/lj_ctype_dyn.o +0 -0
  215. data/lua-hooks/ext/luajit/src/lj_debug.c +699 -0
  216. data/lua-hooks/ext/luajit/src/lj_debug.h +65 -0
  217. data/lua-hooks/ext/luajit/src/lj_debug.o +0 -0
  218. data/lua-hooks/ext/luajit/src/lj_debug_dyn.o +0 -0
  219. data/lua-hooks/ext/luajit/src/lj_def.h +365 -0
  220. data/lua-hooks/ext/luajit/src/lj_dispatch.c +557 -0
  221. data/lua-hooks/ext/luajit/src/lj_dispatch.h +138 -0
  222. data/lua-hooks/ext/luajit/src/lj_dispatch.o +0 -0
  223. data/lua-hooks/ext/luajit/src/lj_dispatch_dyn.o +0 -0
  224. data/lua-hooks/ext/luajit/src/lj_emit_arm.h +356 -0
  225. data/lua-hooks/ext/luajit/src/lj_emit_mips.h +211 -0
  226. data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +238 -0
  227. data/lua-hooks/ext/luajit/src/lj_emit_x86.h +462 -0
  228. data/lua-hooks/ext/luajit/src/lj_err.c +794 -0
  229. data/lua-hooks/ext/luajit/src/lj_err.h +41 -0
  230. data/lua-hooks/ext/luajit/src/lj_err.o +0 -0
  231. data/lua-hooks/ext/luajit/src/lj_err_dyn.o +0 -0
  232. data/lua-hooks/ext/luajit/src/lj_errmsg.h +190 -0
  233. data/lua-hooks/ext/luajit/src/lj_ff.h +18 -0
  234. data/lua-hooks/ext/luajit/src/lj_ffdef.h +209 -0
  235. data/lua-hooks/ext/luajit/src/lj_ffrecord.c +1247 -0
  236. data/lua-hooks/ext/luajit/src/lj_ffrecord.h +24 -0
  237. data/lua-hooks/ext/luajit/src/lj_ffrecord.o +0 -0
  238. data/lua-hooks/ext/luajit/src/lj_ffrecord_dyn.o +0 -0
  239. data/lua-hooks/ext/luajit/src/lj_folddef.h +1138 -0
  240. data/lua-hooks/ext/luajit/src/lj_frame.h +259 -0
  241. data/lua-hooks/ext/luajit/src/lj_func.c +185 -0
  242. data/lua-hooks/ext/luajit/src/lj_func.h +24 -0
  243. data/lua-hooks/ext/luajit/src/lj_func.o +0 -0
  244. data/lua-hooks/ext/luajit/src/lj_func_dyn.o +0 -0
  245. data/lua-hooks/ext/luajit/src/lj_gc.c +845 -0
  246. data/lua-hooks/ext/luajit/src/lj_gc.h +134 -0
  247. data/lua-hooks/ext/luajit/src/lj_gc.o +0 -0
  248. data/lua-hooks/ext/luajit/src/lj_gc_dyn.o +0 -0
  249. data/lua-hooks/ext/luajit/src/lj_gdbjit.c +787 -0
  250. data/lua-hooks/ext/luajit/src/lj_gdbjit.h +22 -0
  251. data/lua-hooks/ext/luajit/src/lj_gdbjit.o +0 -0
  252. data/lua-hooks/ext/luajit/src/lj_gdbjit_dyn.o +0 -0
  253. data/lua-hooks/ext/luajit/src/lj_ir.c +505 -0
  254. data/lua-hooks/ext/luajit/src/lj_ir.h +577 -0
  255. data/lua-hooks/ext/luajit/src/lj_ir.o +0 -0
  256. data/lua-hooks/ext/luajit/src/lj_ir_dyn.o +0 -0
  257. data/lua-hooks/ext/luajit/src/lj_ircall.h +321 -0
  258. data/lua-hooks/ext/luajit/src/lj_iropt.h +161 -0
  259. data/lua-hooks/ext/luajit/src/lj_jit.h +440 -0
  260. data/lua-hooks/ext/luajit/src/lj_lex.c +482 -0
  261. data/lua-hooks/ext/luajit/src/lj_lex.h +86 -0
  262. data/lua-hooks/ext/luajit/src/lj_lex.o +0 -0
  263. data/lua-hooks/ext/luajit/src/lj_lex_dyn.o +0 -0
  264. data/lua-hooks/ext/luajit/src/lj_lib.c +303 -0
  265. data/lua-hooks/ext/luajit/src/lj_lib.h +115 -0
  266. data/lua-hooks/ext/luajit/src/lj_lib.o +0 -0
  267. data/lua-hooks/ext/luajit/src/lj_lib_dyn.o +0 -0
  268. data/lua-hooks/ext/luajit/src/lj_libdef.h +414 -0
  269. data/lua-hooks/ext/luajit/src/lj_load.c +168 -0
  270. data/lua-hooks/ext/luajit/src/lj_load.o +0 -0
  271. data/lua-hooks/ext/luajit/src/lj_load_dyn.o +0 -0
  272. data/lua-hooks/ext/luajit/src/lj_mcode.c +386 -0
  273. data/lua-hooks/ext/luajit/src/lj_mcode.h +30 -0
  274. data/lua-hooks/ext/luajit/src/lj_mcode.o +0 -0
  275. data/lua-hooks/ext/luajit/src/lj_mcode_dyn.o +0 -0
  276. data/lua-hooks/ext/luajit/src/lj_meta.c +477 -0
  277. data/lua-hooks/ext/luajit/src/lj_meta.h +38 -0
  278. data/lua-hooks/ext/luajit/src/lj_meta.o +0 -0
  279. data/lua-hooks/ext/luajit/src/lj_meta_dyn.o +0 -0
  280. data/lua-hooks/ext/luajit/src/lj_obj.c +50 -0
  281. data/lua-hooks/ext/luajit/src/lj_obj.h +976 -0
  282. data/lua-hooks/ext/luajit/src/lj_obj.o +0 -0
  283. data/lua-hooks/ext/luajit/src/lj_obj_dyn.o +0 -0
  284. data/lua-hooks/ext/luajit/src/lj_opt_dce.c +78 -0
  285. data/lua-hooks/ext/luajit/src/lj_opt_dce.o +0 -0
  286. data/lua-hooks/ext/luajit/src/lj_opt_dce_dyn.o +0 -0
  287. data/lua-hooks/ext/luajit/src/lj_opt_fold.c +2488 -0
  288. data/lua-hooks/ext/luajit/src/lj_opt_fold.o +0 -0
  289. data/lua-hooks/ext/luajit/src/lj_opt_fold_dyn.o +0 -0
  290. data/lua-hooks/ext/luajit/src/lj_opt_loop.c +449 -0
  291. data/lua-hooks/ext/luajit/src/lj_opt_loop.o +0 -0
  292. data/lua-hooks/ext/luajit/src/lj_opt_loop_dyn.o +0 -0
  293. data/lua-hooks/ext/luajit/src/lj_opt_mem.c +935 -0
  294. data/lua-hooks/ext/luajit/src/lj_opt_mem.o +0 -0
  295. data/lua-hooks/ext/luajit/src/lj_opt_mem_dyn.o +0 -0
  296. data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +652 -0
  297. data/lua-hooks/ext/luajit/src/lj_opt_narrow.o +0 -0
  298. data/lua-hooks/ext/luajit/src/lj_opt_narrow_dyn.o +0 -0
  299. data/lua-hooks/ext/luajit/src/lj_opt_sink.c +245 -0
  300. data/lua-hooks/ext/luajit/src/lj_opt_sink.o +0 -0
  301. data/lua-hooks/ext/luajit/src/lj_opt_sink_dyn.o +0 -0
  302. data/lua-hooks/ext/luajit/src/lj_opt_split.c +856 -0
  303. data/lua-hooks/ext/luajit/src/lj_opt_split.o +0 -0
  304. data/lua-hooks/ext/luajit/src/lj_opt_split_dyn.o +0 -0
  305. data/lua-hooks/ext/luajit/src/lj_parse.c +2725 -0
  306. data/lua-hooks/ext/luajit/src/lj_parse.h +18 -0
  307. data/lua-hooks/ext/luajit/src/lj_parse.o +0 -0
  308. data/lua-hooks/ext/luajit/src/lj_parse_dyn.o +0 -0
  309. data/lua-hooks/ext/luajit/src/lj_profile.c +368 -0
  310. data/lua-hooks/ext/luajit/src/lj_profile.h +21 -0
  311. data/lua-hooks/ext/luajit/src/lj_profile.o +0 -0
  312. data/lua-hooks/ext/luajit/src/lj_profile_dyn.o +0 -0
  313. data/lua-hooks/ext/luajit/src/lj_recdef.h +270 -0
  314. data/lua-hooks/ext/luajit/src/lj_record.c +2554 -0
  315. data/lua-hooks/ext/luajit/src/lj_record.h +45 -0
  316. data/lua-hooks/ext/luajit/src/lj_record.o +0 -0
  317. data/lua-hooks/ext/luajit/src/lj_record_dyn.o +0 -0
  318. data/lua-hooks/ext/luajit/src/lj_snap.c +870 -0
  319. data/lua-hooks/ext/luajit/src/lj_snap.h +34 -0
  320. data/lua-hooks/ext/luajit/src/lj_snap.o +0 -0
  321. data/lua-hooks/ext/luajit/src/lj_snap_dyn.o +0 -0
  322. data/lua-hooks/ext/luajit/src/lj_state.c +300 -0
  323. data/lua-hooks/ext/luajit/src/lj_state.h +35 -0
  324. data/lua-hooks/ext/luajit/src/lj_state.o +0 -0
  325. data/lua-hooks/ext/luajit/src/lj_state_dyn.o +0 -0
  326. data/lua-hooks/ext/luajit/src/lj_str.c +197 -0
  327. data/lua-hooks/ext/luajit/src/lj_str.h +27 -0
  328. data/lua-hooks/ext/luajit/src/lj_str.o +0 -0
  329. data/lua-hooks/ext/luajit/src/lj_str_dyn.o +0 -0
  330. data/lua-hooks/ext/luajit/src/lj_strfmt.c +554 -0
  331. data/lua-hooks/ext/luajit/src/lj_strfmt.h +125 -0
  332. data/lua-hooks/ext/luajit/src/lj_strfmt.o +0 -0
  333. data/lua-hooks/ext/luajit/src/lj_strfmt_dyn.o +0 -0
  334. data/lua-hooks/ext/luajit/src/lj_strscan.c +547 -0
  335. data/lua-hooks/ext/luajit/src/lj_strscan.h +39 -0
  336. data/lua-hooks/ext/luajit/src/lj_strscan.o +0 -0
  337. data/lua-hooks/ext/luajit/src/lj_strscan_dyn.o +0 -0
  338. data/lua-hooks/ext/luajit/src/lj_tab.c +666 -0
  339. data/lua-hooks/ext/luajit/src/lj_tab.h +73 -0
  340. data/lua-hooks/ext/luajit/src/lj_tab.o +0 -0
  341. data/lua-hooks/ext/luajit/src/lj_tab_dyn.o +0 -0
  342. data/lua-hooks/ext/luajit/src/lj_target.h +164 -0
  343. data/lua-hooks/ext/luajit/src/lj_target_arm.h +270 -0
  344. data/lua-hooks/ext/luajit/src/lj_target_arm64.h +97 -0
  345. data/lua-hooks/ext/luajit/src/lj_target_mips.h +260 -0
  346. data/lua-hooks/ext/luajit/src/lj_target_ppc.h +280 -0
  347. data/lua-hooks/ext/luajit/src/lj_target_x86.h +345 -0
  348. data/lua-hooks/ext/luajit/src/lj_trace.c +859 -0
  349. data/lua-hooks/ext/luajit/src/lj_trace.h +54 -0
  350. data/lua-hooks/ext/luajit/src/lj_trace.o +0 -0
  351. data/lua-hooks/ext/luajit/src/lj_trace_dyn.o +0 -0
  352. data/lua-hooks/ext/luajit/src/lj_traceerr.h +63 -0
  353. data/lua-hooks/ext/luajit/src/lj_udata.c +34 -0
  354. data/lua-hooks/ext/luajit/src/lj_udata.h +14 -0
  355. data/lua-hooks/ext/luajit/src/lj_udata.o +0 -0
  356. data/lua-hooks/ext/luajit/src/lj_udata_dyn.o +0 -0
  357. data/lua-hooks/ext/luajit/src/lj_vm.S +2730 -0
  358. data/lua-hooks/ext/luajit/src/lj_vm.h +114 -0
  359. data/lua-hooks/ext/luajit/src/lj_vm.o +0 -0
  360. data/lua-hooks/ext/luajit/src/lj_vm_dyn.o +0 -0
  361. data/lua-hooks/ext/luajit/src/lj_vmevent.c +58 -0
  362. data/lua-hooks/ext/luajit/src/lj_vmevent.h +59 -0
  363. data/lua-hooks/ext/luajit/src/lj_vmevent.o +0 -0
  364. data/lua-hooks/ext/luajit/src/lj_vmevent_dyn.o +0 -0
  365. data/lua-hooks/ext/luajit/src/lj_vmmath.c +152 -0
  366. data/lua-hooks/ext/luajit/src/lj_vmmath.o +0 -0
  367. data/lua-hooks/ext/luajit/src/lj_vmmath_dyn.o +0 -0
  368. data/lua-hooks/ext/luajit/src/ljamalg.c +96 -0
  369. data/lua-hooks/ext/{lua → luajit/src}/lua.h +12 -7
  370. data/lua-hooks/ext/luajit/src/lua.hpp +9 -0
  371. data/lua-hooks/ext/luajit/src/luaconf.h +156 -0
  372. data/lua-hooks/ext/luajit/src/luajit +0 -0
  373. data/lua-hooks/ext/luajit/src/luajit.c +570 -0
  374. data/lua-hooks/ext/luajit/src/luajit.h +79 -0
  375. data/lua-hooks/ext/luajit/src/luajit.o +0 -0
  376. data/lua-hooks/ext/luajit/src/lualib.h +43 -0
  377. data/lua-hooks/ext/luajit/src/msvcbuild.bat +114 -0
  378. data/lua-hooks/ext/luajit/src/ps4build.bat +103 -0
  379. data/lua-hooks/ext/luajit/src/psvitabuild.bat +93 -0
  380. data/lua-hooks/ext/luajit/src/vm_arm.dasc +4585 -0
  381. data/lua-hooks/ext/luajit/src/vm_arm64.dasc +3764 -0
  382. data/lua-hooks/ext/luajit/src/vm_mips.dasc +4355 -0
  383. data/lua-hooks/ext/luajit/src/vm_ppc.dasc +5252 -0
  384. data/lua-hooks/ext/luajit/src/vm_x64.dasc +4902 -0
  385. data/lua-hooks/ext/luajit/src/vm_x86.dasc +5710 -0
  386. data/lua-hooks/ext/luajit/src/xb1build.bat +101 -0
  387. data/lua-hooks/ext/luajit/src/xedkbuild.bat +92 -0
  388. data/lua-hooks/ext/luautf8/lutf8lib.c +3 -3
  389. data/lua-hooks/lib/boot.lua +37 -2
  390. metadata +372 -69
  391. data/lua-hooks/ext/bitop/README +0 -22
  392. data/lua-hooks/ext/bitop/bit.c +0 -189
  393. data/lua-hooks/ext/extconf.rb +0 -38
  394. data/lua-hooks/ext/lua/COPYRIGHT +0 -34
  395. data/lua-hooks/ext/lua/lapi.c +0 -1087
  396. data/lua-hooks/ext/lua/lapi.h +0 -16
  397. data/lua-hooks/ext/lua/lauxlib.c +0 -652
  398. data/lua-hooks/ext/lua/lbaselib.c +0 -659
  399. data/lua-hooks/ext/lua/lcode.c +0 -831
  400. data/lua-hooks/ext/lua/lcode.h +0 -76
  401. data/lua-hooks/ext/lua/ldblib.c +0 -398
  402. data/lua-hooks/ext/lua/ldebug.c +0 -638
  403. data/lua-hooks/ext/lua/ldebug.h +0 -33
  404. data/lua-hooks/ext/lua/ldo.c +0 -519
  405. data/lua-hooks/ext/lua/ldo.h +0 -57
  406. data/lua-hooks/ext/lua/ldump.c +0 -164
  407. data/lua-hooks/ext/lua/lfunc.c +0 -174
  408. data/lua-hooks/ext/lua/lfunc.h +0 -34
  409. data/lua-hooks/ext/lua/lgc.c +0 -710
  410. data/lua-hooks/ext/lua/lgc.h +0 -110
  411. data/lua-hooks/ext/lua/linit.c +0 -38
  412. data/lua-hooks/ext/lua/liolib.c +0 -556
  413. data/lua-hooks/ext/lua/llex.c +0 -463
  414. data/lua-hooks/ext/lua/llex.h +0 -81
  415. data/lua-hooks/ext/lua/llimits.h +0 -128
  416. data/lua-hooks/ext/lua/lmathlib.c +0 -263
  417. data/lua-hooks/ext/lua/lmem.c +0 -86
  418. data/lua-hooks/ext/lua/lmem.h +0 -49
  419. data/lua-hooks/ext/lua/loadlib.c +0 -705
  420. data/lua-hooks/ext/lua/loadlib_rel.c +0 -760
  421. data/lua-hooks/ext/lua/lobject.c +0 -214
  422. data/lua-hooks/ext/lua/lobject.h +0 -381
  423. data/lua-hooks/ext/lua/lopcodes.c +0 -102
  424. data/lua-hooks/ext/lua/lopcodes.h +0 -268
  425. data/lua-hooks/ext/lua/loslib.c +0 -243
  426. data/lua-hooks/ext/lua/lparser.c +0 -1339
  427. data/lua-hooks/ext/lua/lparser.h +0 -82
  428. data/lua-hooks/ext/lua/lstate.c +0 -214
  429. data/lua-hooks/ext/lua/lstate.h +0 -169
  430. data/lua-hooks/ext/lua/lstring.c +0 -111
  431. data/lua-hooks/ext/lua/lstring.h +0 -31
  432. data/lua-hooks/ext/lua/lstrlib.c +0 -871
  433. data/lua-hooks/ext/lua/ltable.c +0 -588
  434. data/lua-hooks/ext/lua/ltable.h +0 -40
  435. data/lua-hooks/ext/lua/ltablib.c +0 -287
  436. data/lua-hooks/ext/lua/ltm.c +0 -75
  437. data/lua-hooks/ext/lua/ltm.h +0 -54
  438. data/lua-hooks/ext/lua/lua.c +0 -392
  439. data/lua-hooks/ext/lua/lua.def +0 -131
  440. data/lua-hooks/ext/lua/lua.rc +0 -28
  441. data/lua-hooks/ext/lua/lua_dll.rc +0 -26
  442. data/lua-hooks/ext/lua/luac.c +0 -200
  443. data/lua-hooks/ext/lua/luac.rc +0 -1
  444. data/lua-hooks/ext/lua/luaconf.h +0 -763
  445. data/lua-hooks/ext/lua/luaconf.h.in +0 -724
  446. data/lua-hooks/ext/lua/luaconf.h.orig +0 -763
  447. data/lua-hooks/ext/lua/lualib.h +0 -53
  448. data/lua-hooks/ext/lua/lundump.c +0 -227
  449. data/lua-hooks/ext/lua/lundump.h +0 -36
  450. data/lua-hooks/ext/lua/lvm.c +0 -767
  451. data/lua-hooks/ext/lua/lvm.h +0 -36
  452. data/lua-hooks/ext/lua/lzio.c +0 -82
  453. data/lua-hooks/ext/lua/lzio.h +0 -67
  454. data/lua-hooks/ext/lua/print.c +0 -227
@@ -1,110 +0,0 @@
1
- /*
2
- ** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $
3
- ** Garbage Collector
4
- ** See Copyright Notice in lua.h
5
- */
6
-
7
- #ifndef lgc_h
8
- #define lgc_h
9
-
10
-
11
- #include "lobject.h"
12
-
13
-
14
- /*
15
- ** Possible states of the Garbage Collector
16
- */
17
- #define GCSpause 0
18
- #define GCSpropagate 1
19
- #define GCSsweepstring 2
20
- #define GCSsweep 3
21
- #define GCSfinalize 4
22
-
23
-
24
- /*
25
- ** some userful bit tricks
26
- */
27
- #define resetbits(x,m) ((x) &= cast(lu_byte, ~(m)))
28
- #define setbits(x,m) ((x) |= (m))
29
- #define testbits(x,m) ((x) & (m))
30
- #define bitmask(b) (1<<(b))
31
- #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
32
- #define l_setbit(x,b) setbits(x, bitmask(b))
33
- #define resetbit(x,b) resetbits(x, bitmask(b))
34
- #define testbit(x,b) testbits(x, bitmask(b))
35
- #define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2)))
36
- #define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2)))
37
- #define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2)))
38
-
39
-
40
-
41
- /*
42
- ** Layout for bit use in `marked' field:
43
- ** bit 0 - object is white (type 0)
44
- ** bit 1 - object is white (type 1)
45
- ** bit 2 - object is black
46
- ** bit 3 - for userdata: has been finalized
47
- ** bit 3 - for tables: has weak keys
48
- ** bit 4 - for tables: has weak values
49
- ** bit 5 - object is fixed (should not be collected)
50
- ** bit 6 - object is "super" fixed (only the main thread)
51
- */
52
-
53
-
54
- #define WHITE0BIT 0
55
- #define WHITE1BIT 1
56
- #define BLACKBIT 2
57
- #define FINALIZEDBIT 3
58
- #define KEYWEAKBIT 3
59
- #define VALUEWEAKBIT 4
60
- #define FIXEDBIT 5
61
- #define SFIXEDBIT 6
62
- #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
63
-
64
-
65
- #define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
66
- #define isblack(x) testbit((x)->gch.marked, BLACKBIT)
67
- #define isgray(x) (!isblack(x) && !iswhite(x))
68
-
69
- #define otherwhite(g) (g->currentwhite ^ WHITEBITS)
70
- #define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS)
71
-
72
- #define changewhite(x) ((x)->gch.marked ^= WHITEBITS)
73
- #define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT)
74
-
75
- #define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x)))
76
-
77
- #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS)
78
-
79
-
80
- #define luaC_checkGC(L) { \
81
- condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \
82
- if (G(L)->totalbytes >= G(L)->GCthreshold) \
83
- luaC_step(L); }
84
-
85
-
86
- #define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
87
- luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
88
-
89
- #define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \
90
- luaC_barrierback(L,t); }
91
-
92
- #define luaC_objbarrier(L,p,o) \
93
- { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
94
- luaC_barrierf(L,obj2gco(p),obj2gco(o)); }
95
-
96
- #define luaC_objbarriert(L,t,o) \
97
- { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }
98
-
99
- LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all);
100
- LUAI_FUNC void luaC_callGCTM (lua_State *L);
101
- LUAI_FUNC void luaC_freeall (lua_State *L);
102
- LUAI_FUNC void luaC_step (lua_State *L);
103
- LUAI_FUNC void luaC_fullgc (lua_State *L);
104
- LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
105
- LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);
106
- LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);
107
- LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t);
108
-
109
-
110
- #endif
@@ -1,38 +0,0 @@
1
- /*
2
- ** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $
3
- ** Initialization of libraries for lua.c
4
- ** See Copyright Notice in lua.h
5
- */
6
-
7
-
8
- #define linit_c
9
- #define LUA_LIB
10
-
11
- #include "lua.h"
12
-
13
- #include "lualib.h"
14
- #include "lauxlib.h"
15
-
16
- // This is customised in ../lua.c
17
- // static const luaL_Reg lualibs[] = {
18
- // {"", luaopen_base},
19
- // {LUA_LOADLIBNAME, luaopen_package},
20
- // {LUA_TABLIBNAME, luaopen_table},
21
- // {LUA_IOLIBNAME, luaopen_io},
22
- // {LUA_OSLIBNAME, luaopen_os},
23
- // {LUA_STRLIBNAME, luaopen_string},
24
- // {LUA_MATHLIBNAME, luaopen_math},
25
- // {LUA_DBLIBNAME, luaopen_debug},
26
- // {NULL, NULL}
27
- // };
28
-
29
-
30
- LUALIB_API void luaL_openlibs (lua_State *L) {
31
- const luaL_Reg *lib = lualibs;
32
- for (; lib->func; lib++) {
33
- lua_pushcfunction(L, lib->func);
34
- lua_pushstring(L, lib->name);
35
- lua_call(L, 1, 0);
36
- }
37
- }
38
-
@@ -1,556 +0,0 @@
1
- /*
2
- ** $Id: liolib.c,v 2.73.1.4 2010/05/14 15:33:51 roberto Exp $
3
- ** Standard I/O (and system) library
4
- ** See Copyright Notice in lua.h
5
- */
6
-
7
-
8
- #include <errno.h>
9
- #include <stdio.h>
10
- #include <stdlib.h>
11
- #include <string.h>
12
-
13
- #define liolib_c
14
- #define LUA_LIB
15
-
16
- #include "lua.h"
17
-
18
- #include "lauxlib.h"
19
- #include "lualib.h"
20
-
21
-
22
-
23
- #define IO_INPUT 1
24
- #define IO_OUTPUT 2
25
-
26
-
27
- static const char *const fnames[] = {"input", "output"};
28
-
29
-
30
- static int pushresult (lua_State *L, int i, const char *filename) {
31
- int en = errno; /* calls to Lua API may change this value */
32
- if (i) {
33
- lua_pushboolean(L, 1);
34
- return 1;
35
- }
36
- else {
37
- lua_pushnil(L);
38
- if (filename)
39
- lua_pushfstring(L, "%s: %s", filename, strerror(en));
40
- else
41
- lua_pushfstring(L, "%s", strerror(en));
42
- lua_pushinteger(L, en);
43
- return 3;
44
- }
45
- }
46
-
47
-
48
- static void fileerror (lua_State *L, int arg, const char *filename) {
49
- lua_pushfstring(L, "%s: %s", filename, strerror(errno));
50
- luaL_argerror(L, arg, lua_tostring(L, -1));
51
- }
52
-
53
-
54
- #define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE))
55
-
56
-
57
- static int io_type (lua_State *L) {
58
- void *ud;
59
- luaL_checkany(L, 1);
60
- ud = lua_touserdata(L, 1);
61
- lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE);
62
- if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1))
63
- lua_pushnil(L); /* not a file */
64
- else if (*((FILE **)ud) == NULL)
65
- lua_pushliteral(L, "closed file");
66
- else
67
- lua_pushliteral(L, "file");
68
- return 1;
69
- }
70
-
71
-
72
- static FILE *tofile (lua_State *L) {
73
- FILE **f = tofilep(L);
74
- if (*f == NULL)
75
- luaL_error(L, "attempt to use a closed file");
76
- return *f;
77
- }
78
-
79
-
80
-
81
- /*
82
- ** When creating file handles, always creates a `closed' file handle
83
- ** before opening the actual file; so, if there is a memory error, the
84
- ** file is not left opened.
85
- */
86
- static FILE **newfile (lua_State *L) {
87
- FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));
88
- *pf = NULL; /* file handle is currently `closed' */
89
- luaL_getmetatable(L, LUA_FILEHANDLE);
90
- lua_setmetatable(L, -2);
91
- return pf;
92
- }
93
-
94
-
95
- /*
96
- ** function to (not) close the standard files stdin, stdout, and stderr
97
- */
98
- static int io_noclose (lua_State *L) {
99
- lua_pushnil(L);
100
- lua_pushliteral(L, "cannot close standard file");
101
- return 2;
102
- }
103
-
104
-
105
- /*
106
- ** function to close 'popen' files
107
- */
108
- static int io_pclose (lua_State *L) {
109
- FILE **p = tofilep(L);
110
- int ok = lua_pclose(L, *p);
111
- *p = NULL;
112
- return pushresult(L, ok, NULL);
113
- }
114
-
115
-
116
- /*
117
- ** function to close regular files
118
- */
119
- static int io_fclose (lua_State *L) {
120
- FILE **p = tofilep(L);
121
- int ok = (fclose(*p) == 0);
122
- *p = NULL;
123
- return pushresult(L, ok, NULL);
124
- }
125
-
126
-
127
- static int aux_close (lua_State *L) {
128
- lua_getfenv(L, 1);
129
- lua_getfield(L, -1, "__close");
130
- return (lua_tocfunction(L, -1))(L);
131
- }
132
-
133
-
134
- static int io_close (lua_State *L) {
135
- if (lua_isnone(L, 1))
136
- lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT);
137
- tofile(L); /* make sure argument is a file */
138
- return aux_close(L);
139
- }
140
-
141
-
142
- static int io_gc (lua_State *L) {
143
- FILE *f = *tofilep(L);
144
- /* ignore closed files */
145
- if (f != NULL)
146
- aux_close(L);
147
- return 0;
148
- }
149
-
150
-
151
- static int io_tostring (lua_State *L) {
152
- FILE *f = *tofilep(L);
153
- if (f == NULL)
154
- lua_pushliteral(L, "file (closed)");
155
- else
156
- lua_pushfstring(L, "file (%p)", f);
157
- return 1;
158
- }
159
-
160
-
161
- static int io_open (lua_State *L) {
162
- const char *filename = luaL_checkstring(L, 1);
163
- const char *mode = luaL_optstring(L, 2, "r");
164
- FILE **pf = newfile(L);
165
- *pf = fopen(filename, mode);
166
- return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
167
- }
168
-
169
-
170
- /*
171
- ** this function has a separated environment, which defines the
172
- ** correct __close for 'popen' files
173
- */
174
- static int io_popen (lua_State *L) {
175
- const char *filename = luaL_checkstring(L, 1);
176
- const char *mode = luaL_optstring(L, 2, "r");
177
- FILE **pf = newfile(L);
178
- *pf = lua_popen(L, filename, mode);
179
- return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
180
- }
181
-
182
-
183
- static int io_tmpfile (lua_State *L) {
184
- FILE **pf = newfile(L);
185
- *pf = tmpfile();
186
- return (*pf == NULL) ? pushresult(L, 0, NULL) : 1;
187
- }
188
-
189
-
190
- static FILE *getiofile (lua_State *L, int findex) {
191
- FILE *f;
192
- lua_rawgeti(L, LUA_ENVIRONINDEX, findex);
193
- f = *(FILE **)lua_touserdata(L, -1);
194
- if (f == NULL)
195
- luaL_error(L, "standard %s file is closed", fnames[findex - 1]);
196
- return f;
197
- }
198
-
199
-
200
- static int g_iofile (lua_State *L, int f, const char *mode) {
201
- if (!lua_isnoneornil(L, 1)) {
202
- const char *filename = lua_tostring(L, 1);
203
- if (filename) {
204
- FILE **pf = newfile(L);
205
- *pf = fopen(filename, mode);
206
- if (*pf == NULL)
207
- fileerror(L, 1, filename);
208
- }
209
- else {
210
- tofile(L); /* check that it's a valid file handle */
211
- lua_pushvalue(L, 1);
212
- }
213
- lua_rawseti(L, LUA_ENVIRONINDEX, f);
214
- }
215
- /* return current value */
216
- lua_rawgeti(L, LUA_ENVIRONINDEX, f);
217
- return 1;
218
- }
219
-
220
-
221
- static int io_input (lua_State *L) {
222
- return g_iofile(L, IO_INPUT, "r");
223
- }
224
-
225
-
226
- static int io_output (lua_State *L) {
227
- return g_iofile(L, IO_OUTPUT, "w");
228
- }
229
-
230
-
231
- static int io_readline (lua_State *L);
232
-
233
-
234
- static void aux_lines (lua_State *L, int idx, int toclose) {
235
- lua_pushvalue(L, idx);
236
- lua_pushboolean(L, toclose); /* close/not close file when finished */
237
- lua_pushcclosure(L, io_readline, 2);
238
- }
239
-
240
-
241
- static int f_lines (lua_State *L) {
242
- tofile(L); /* check that it's a valid file handle */
243
- aux_lines(L, 1, 0);
244
- return 1;
245
- }
246
-
247
-
248
- static int io_lines (lua_State *L) {
249
- if (lua_isnoneornil(L, 1)) { /* no arguments? */
250
- /* will iterate over default input */
251
- lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT);
252
- return f_lines(L);
253
- }
254
- else {
255
- const char *filename = luaL_checkstring(L, 1);
256
- FILE **pf = newfile(L);
257
- *pf = fopen(filename, "r");
258
- if (*pf == NULL)
259
- fileerror(L, 1, filename);
260
- aux_lines(L, lua_gettop(L), 1);
261
- return 1;
262
- }
263
- }
264
-
265
-
266
- /*
267
- ** {======================================================
268
- ** READ
269
- ** =======================================================
270
- */
271
-
272
-
273
- static int read_number (lua_State *L, FILE *f) {
274
- lua_Number d;
275
- if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
276
- lua_pushnumber(L, d);
277
- return 1;
278
- }
279
- else {
280
- lua_pushnil(L); /* "result" to be removed */
281
- return 0; /* read fails */
282
- }
283
- }
284
-
285
-
286
- static int test_eof (lua_State *L, FILE *f) {
287
- int c = getc(f);
288
- ungetc(c, f);
289
- lua_pushlstring(L, NULL, 0);
290
- return (c != EOF);
291
- }
292
-
293
-
294
- static int read_line (lua_State *L, FILE *f) {
295
- luaL_Buffer b;
296
- luaL_buffinit(L, &b);
297
- for (;;) {
298
- size_t l;
299
- char *p = luaL_prepbuffer(&b);
300
- if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
301
- luaL_pushresult(&b); /* close buffer */
302
- return (lua_objlen(L, -1) > 0); /* check whether read something */
303
- }
304
- l = strlen(p);
305
- if (l == 0 || p[l-1] != '\n')
306
- luaL_addsize(&b, l);
307
- else {
308
- luaL_addsize(&b, l - 1); /* do not include `eol' */
309
- luaL_pushresult(&b); /* close buffer */
310
- return 1; /* read at least an `eol' */
311
- }
312
- }
313
- }
314
-
315
-
316
- static int read_chars (lua_State *L, FILE *f, size_t n) {
317
- size_t rlen; /* how much to read */
318
- size_t nr; /* number of chars actually read */
319
- luaL_Buffer b;
320
- luaL_buffinit(L, &b);
321
- rlen = LUAL_BUFFERSIZE; /* try to read that much each time */
322
- do {
323
- char *p = luaL_prepbuffer(&b);
324
- if (rlen > n) rlen = n; /* cannot read more than asked */
325
- nr = fread(p, sizeof(char), rlen, f);
326
- luaL_addsize(&b, nr);
327
- n -= nr; /* still have to read `n' chars */
328
- } while (n > 0 && nr == rlen); /* until end of count or eof */
329
- luaL_pushresult(&b); /* close buffer */
330
- return (n == 0 || lua_objlen(L, -1) > 0);
331
- }
332
-
333
-
334
- static int g_read (lua_State *L, FILE *f, int first) {
335
- int nargs = lua_gettop(L) - 1;
336
- int success;
337
- int n;
338
- clearerr(f);
339
- if (nargs == 0) { /* no arguments? */
340
- success = read_line(L, f);
341
- n = first+1; /* to return 1 result */
342
- }
343
- else { /* ensure stack space for all results and for auxlib's buffer */
344
- luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
345
- success = 1;
346
- for (n = first; nargs-- && success; n++) {
347
- if (lua_type(L, n) == LUA_TNUMBER) {
348
- size_t l = (size_t)lua_tointeger(L, n);
349
- success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
350
- }
351
- else {
352
- const char *p = lua_tostring(L, n);
353
- luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
354
- switch (p[1]) {
355
- case 'n': /* number */
356
- success = read_number(L, f);
357
- break;
358
- case 'l': /* line */
359
- success = read_line(L, f);
360
- break;
361
- case 'a': /* file */
362
- read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */
363
- success = 1; /* always success */
364
- break;
365
- default:
366
- return luaL_argerror(L, n, "invalid format");
367
- }
368
- }
369
- }
370
- }
371
- if (ferror(f))
372
- return pushresult(L, 0, NULL);
373
- if (!success) {
374
- lua_pop(L, 1); /* remove last result */
375
- lua_pushnil(L); /* push nil instead */
376
- }
377
- return n - first;
378
- }
379
-
380
-
381
- static int io_read (lua_State *L) {
382
- return g_read(L, getiofile(L, IO_INPUT), 1);
383
- }
384
-
385
-
386
- static int f_read (lua_State *L) {
387
- return g_read(L, tofile(L), 2);
388
- }
389
-
390
-
391
- static int io_readline (lua_State *L) {
392
- FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1));
393
- int sucess;
394
- if (f == NULL) /* file is already closed? */
395
- luaL_error(L, "file is already closed");
396
- sucess = read_line(L, f);
397
- if (ferror(f))
398
- return luaL_error(L, "%s", strerror(errno));
399
- if (sucess) return 1;
400
- else { /* EOF */
401
- if (lua_toboolean(L, lua_upvalueindex(2))) { /* generator created file? */
402
- lua_settop(L, 0);
403
- lua_pushvalue(L, lua_upvalueindex(1));
404
- aux_close(L); /* close it */
405
- }
406
- return 0;
407
- }
408
- }
409
-
410
- /* }====================================================== */
411
-
412
-
413
- static int g_write (lua_State *L, FILE *f, int arg) {
414
- int nargs = lua_gettop(L) - 1;
415
- int status = 1;
416
- for (; nargs--; arg++) {
417
- if (lua_type(L, arg) == LUA_TNUMBER) {
418
- /* optimization: could be done exactly as for strings */
419
- status = status &&
420
- fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;
421
- }
422
- else {
423
- size_t l;
424
- const char *s = luaL_checklstring(L, arg, &l);
425
- status = status && (fwrite(s, sizeof(char), l, f) == l);
426
- }
427
- }
428
- return pushresult(L, status, NULL);
429
- }
430
-
431
-
432
- static int io_write (lua_State *L) {
433
- return g_write(L, getiofile(L, IO_OUTPUT), 1);
434
- }
435
-
436
-
437
- static int f_write (lua_State *L) {
438
- return g_write(L, tofile(L), 2);
439
- }
440
-
441
-
442
- static int f_seek (lua_State *L) {
443
- static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
444
- static const char *const modenames[] = {"set", "cur", "end", NULL};
445
- FILE *f = tofile(L);
446
- int op = luaL_checkoption(L, 2, "cur", modenames);
447
- long offset = luaL_optlong(L, 3, 0);
448
- op = fseek(f, offset, mode[op]);
449
- if (op)
450
- return pushresult(L, 0, NULL); /* error */
451
- else {
452
- lua_pushinteger(L, ftell(f));
453
- return 1;
454
- }
455
- }
456
-
457
-
458
- static int f_setvbuf (lua_State *L) {
459
- static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
460
- static const char *const modenames[] = {"no", "full", "line", NULL};
461
- FILE *f = tofile(L);
462
- int op = luaL_checkoption(L, 2, NULL, modenames);
463
- lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);
464
- int res = setvbuf(f, NULL, mode[op], sz);
465
- return pushresult(L, res == 0, NULL);
466
- }
467
-
468
-
469
-
470
- static int io_flush (lua_State *L) {
471
- return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
472
- }
473
-
474
-
475
- static int f_flush (lua_State *L) {
476
- return pushresult(L, fflush(tofile(L)) == 0, NULL);
477
- }
478
-
479
-
480
- static const luaL_Reg iolib[] = {
481
- {"close", io_close},
482
- {"flush", io_flush},
483
- {"input", io_input},
484
- {"lines", io_lines},
485
- {"open", io_open},
486
- {"output", io_output},
487
- {"popen", io_popen},
488
- {"read", io_read},
489
- {"tmpfile", io_tmpfile},
490
- {"type", io_type},
491
- {"write", io_write},
492
- {NULL, NULL}
493
- };
494
-
495
-
496
- static const luaL_Reg flib[] = {
497
- {"close", io_close},
498
- {"flush", f_flush},
499
- {"lines", f_lines},
500
- {"read", f_read},
501
- {"seek", f_seek},
502
- {"setvbuf", f_setvbuf},
503
- {"write", f_write},
504
- {"__gc", io_gc},
505
- {"__tostring", io_tostring},
506
- {NULL, NULL}
507
- };
508
-
509
-
510
- static void createmeta (lua_State *L) {
511
- luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
512
- lua_pushvalue(L, -1); /* push metatable */
513
- lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
514
- luaL_register(L, NULL, flib); /* file methods */
515
- }
516
-
517
-
518
- static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {
519
- *newfile(L) = f;
520
- if (k > 0) {
521
- lua_pushvalue(L, -1);
522
- lua_rawseti(L, LUA_ENVIRONINDEX, k);
523
- }
524
- lua_pushvalue(L, -2); /* copy environment */
525
- lua_setfenv(L, -2); /* set it */
526
- lua_setfield(L, -3, fname);
527
- }
528
-
529
-
530
- static void newfenv (lua_State *L, lua_CFunction cls) {
531
- lua_createtable(L, 0, 1);
532
- lua_pushcfunction(L, cls);
533
- lua_setfield(L, -2, "__close");
534
- }
535
-
536
-
537
- LUALIB_API int luaopen_io (lua_State *L) {
538
- createmeta(L);
539
- /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
540
- newfenv(L, io_fclose);
541
- lua_replace(L, LUA_ENVIRONINDEX);
542
- /* open library */
543
- luaL_register(L, LUA_IOLIBNAME, iolib);
544
- /* create (and set) default files */
545
- newfenv(L, io_noclose); /* close function for default files */
546
- createstdfile(L, stdin, IO_INPUT, "stdin");
547
- createstdfile(L, stdout, IO_OUTPUT, "stdout");
548
- createstdfile(L, stderr, 0, "stderr");
549
- lua_pop(L, 1); /* pop environment for default files */
550
- lua_getfield(L, -1, "popen");
551
- newfenv(L, io_pclose); /* create environment for 'popen' */
552
- lua_setfenv(L, -2); /* set fenv for 'popen' */
553
- lua_pop(L, 1); /* pop 'popen' */
554
- return 1;
555
- }
556
-