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,22 +0,0 @@
1
- README for Lua BitOp 1.0.2
2
- --------------------------
3
-
4
- Lua BitOp is a C extension module for Lua 5.1/5.2 which adds
5
- bitwise operations on numbers.
6
-
7
- Homepage: http://bitop.luajit.org/
8
-
9
- Lua BitOp is Copyright (C) 2008-2012 Mike Pall.
10
- Lua BitOp is free software, released under the MIT license.
11
-
12
- --------------------------
13
-
14
- Full documentation for Lua BitOp is available in HTML format.
15
- Please point your favourite browser to:
16
-
17
- doc/index.html
18
-
19
- Detailed installation instructions are here:
20
-
21
- doc/install.html
22
-
@@ -1,189 +0,0 @@
1
- /*
2
- ** Lua BitOp -- a bit operations library for Lua 5.1/5.2.
3
- ** http://bitop.luajit.org/
4
- **
5
- ** Copyright (C) 2008-2012 Mike Pall. All rights reserved.
6
- **
7
- ** Permission is hereby granted, free of charge, to any person obtaining
8
- ** a copy of this software and associated documentation files (the
9
- ** "Software"), to deal in the Software without restriction, including
10
- ** without limitation the rights to use, copy, modify, merge, publish,
11
- ** distribute, sublicense, and/or sell copies of the Software, and to
12
- ** permit persons to whom the Software is furnished to do so, subject to
13
- ** the following conditions:
14
- **
15
- ** The above copyright notice and this permission notice shall be
16
- ** included in all copies or substantial portions of the Software.
17
- **
18
- ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
- ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
- ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
- ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22
- ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
- ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
- ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
- **
26
- ** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
27
- */
28
-
29
- #define LUA_BITOP_VERSION "1.0.2"
30
-
31
- #define LUA_LIB
32
- #include "lua/lua.h"
33
- #include "lua/lauxlib.h"
34
-
35
- #ifdef _MSC_VER
36
- /* MSVC is stuck in the last century and doesn't have C99's stdint.h. */
37
- typedef __int32 int32_t;
38
- typedef unsigned __int32 uint32_t;
39
- typedef unsigned __int64 uint64_t;
40
- #else
41
- #include <stdint.h>
42
- #endif
43
-
44
- typedef int32_t SBits;
45
- typedef uint32_t UBits;
46
-
47
- typedef union {
48
- lua_Number n;
49
- #ifdef LUA_NUMBER_DOUBLE
50
- uint64_t b;
51
- #else
52
- UBits b;
53
- #endif
54
- } BitNum;
55
-
56
- /* Convert argument to bit type. */
57
- static UBits barg(lua_State *L, int idx)
58
- {
59
- BitNum bn;
60
- UBits b;
61
- #if LUA_VERSION_NUM < 502
62
- bn.n = lua_tonumber(L, idx);
63
- #else
64
- bn.n = luaL_checknumber(L, idx);
65
- #endif
66
- #if defined(LUA_NUMBER_DOUBLE)
67
- bn.n += 6755399441055744.0; /* 2^52+2^51 */
68
- #ifdef SWAPPED_DOUBLE
69
- b = (UBits)(bn.b >> 32);
70
- #else
71
- b = (UBits)bn.b;
72
- #endif
73
- #elif defined(LUA_NUMBER_INT) || defined(LUA_NUMBER_LONG) || \
74
- defined(LUA_NUMBER_LONGLONG) || defined(LUA_NUMBER_LONG_LONG) || \
75
- defined(LUA_NUMBER_LLONG)
76
- if (sizeof(UBits) == sizeof(lua_Number))
77
- b = bn.b;
78
- else
79
- b = (UBits)(SBits)bn.n;
80
- #elif defined(LUA_NUMBER_FLOAT)
81
- #error "A 'float' lua_Number type is incompatible with this library"
82
- #else
83
- #error "Unknown number type, check LUA_NUMBER_* in luaconf.h"
84
- #endif
85
- #if LUA_VERSION_NUM < 502
86
- if (b == 0 && !lua_isnumber(L, idx)) {
87
- luaL_typerror(L, idx, "number");
88
- }
89
- #endif
90
- return b;
91
- }
92
-
93
- /* Return bit type. */
94
- #define BRET(b) lua_pushnumber(L, (lua_Number)(SBits)(b)); return 1;
95
-
96
- static int bit_tobit(lua_State *L) { BRET(barg(L, 1)) }
97
- static int bit_bnot(lua_State *L) { BRET(~barg(L, 1)) }
98
-
99
- #define BIT_OP(func, opr) \
100
- static int func(lua_State *L) { int i; UBits b = barg(L, 1); \
101
- for (i = lua_gettop(L); i > 1; i--) b opr barg(L, i); BRET(b) }
102
- BIT_OP(bit_band, &=)
103
- BIT_OP(bit_bor, |=)
104
- BIT_OP(bit_bxor, ^=)
105
-
106
- #define bshl(b, n) (b << n)
107
- #define bshr(b, n) (b >> n)
108
- #define bsar(b, n) ((SBits)b >> n)
109
- #define brol(b, n) ((b << n) | (b >> (32-n)))
110
- #define bror(b, n) ((b << (32-n)) | (b >> n))
111
- #define BIT_SH(func, fn) \
112
- static int func(lua_State *L) { \
113
- UBits b = barg(L, 1); UBits n = barg(L, 2) & 31; BRET(fn(b, n)) }
114
- BIT_SH(bit_lshift, bshl)
115
- BIT_SH(bit_rshift, bshr)
116
- BIT_SH(bit_arshift, bsar)
117
- BIT_SH(bit_rol, brol)
118
- BIT_SH(bit_ror, bror)
119
-
120
- static int bit_bswap(lua_State *L)
121
- {
122
- UBits b = barg(L, 1);
123
- b = (b >> 24) | ((b >> 8) & 0xff00) | ((b & 0xff00) << 8) | (b << 24);
124
- BRET(b)
125
- }
126
-
127
- static int bit_tohex(lua_State *L)
128
- {
129
- UBits b = barg(L, 1);
130
- SBits n = lua_isnone(L, 2) ? 8 : (SBits)barg(L, 2);
131
- const char *hexdigits = "0123456789abcdef";
132
- char buf[8];
133
- int i;
134
- if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; }
135
- if (n > 8) n = 8;
136
- for (i = (int)n; --i >= 0; ) { buf[i] = hexdigits[b & 15]; b >>= 4; }
137
- lua_pushlstring(L, buf, (size_t)n);
138
- return 1;
139
- }
140
-
141
- static const struct luaL_Reg bit_funcs[] = {
142
- { "tobit", bit_tobit },
143
- { "bnot", bit_bnot },
144
- { "band", bit_band },
145
- { "bor", bit_bor },
146
- { "bxor", bit_bxor },
147
- { "lshift", bit_lshift },
148
- { "rshift", bit_rshift },
149
- { "arshift", bit_arshift },
150
- { "rol", bit_rol },
151
- { "ror", bit_ror },
152
- { "bswap", bit_bswap },
153
- { "tohex", bit_tohex },
154
- { NULL, NULL }
155
- };
156
-
157
- /* Signed right-shifts are implementation-defined per C89/C99.
158
- ** But the de facto standard are arithmetic right-shifts on two's
159
- ** complement CPUs. This behaviour is required here, so test for it.
160
- */
161
- #define BAD_SAR (bsar(-8, 2) != (SBits)-2)
162
-
163
- LUALIB_API int luaopen_bit(lua_State *L)
164
- {
165
- UBits b;
166
- lua_pushnumber(L, (lua_Number)1437217655L);
167
- b = barg(L, -1);
168
- if (b != (UBits)1437217655L || BAD_SAR) { /* Perform a simple self-test. */
169
- const char *msg = "compiled with incompatible luaconf.h";
170
- #ifdef LUA_NUMBER_DOUBLE
171
- #ifdef _WIN32
172
- if (b == (UBits)1610612736L)
173
- msg = "use D3DCREATE_FPU_PRESERVE with DirectX";
174
- #endif
175
- if (b == (UBits)1127743488L)
176
- msg = "not compiled with SWAPPED_DOUBLE";
177
- #endif
178
- if (BAD_SAR)
179
- msg = "arithmetic right-shift broken";
180
- luaL_error(L, "bit library self-test failed (%s)", msg);
181
- }
182
- #if LUA_VERSION_NUM < 502
183
- luaL_register(L, "bit", bit_funcs);
184
- #else
185
- luaL_newlib(L, bit_funcs);
186
- #endif
187
- return 1;
188
- }
189
-
@@ -1,38 +0,0 @@
1
- # Used by Ruby to compile the extension.
2
- require 'mkmf'
3
-
4
-
5
- # libinjection doesn't support `#include`ing all the .c files directly
6
- # in the source, since it has symbols which conflict. Instead the `$objs`
7
- # list below compiles each file separately then links them in the final
8
- # step.
9
- $objs = [
10
- "all.o",
11
- "libinjection/libinjection_html5.o",
12
- "libinjection/libinjection_xss.o",
13
- "libinjection/libinjection_sqli.o",
14
- #Compile in LPEG
15
- "lpeg/lpcap.o",
16
- "lpeg/lpcode.o",
17
- "lpeg/lpprint.o",
18
- "lpeg/lpvm.o",
19
- # "lpeg/lptree.o",
20
- ]
21
-
22
- # The created Makefile puts the compiled .o files into the `libinjection`
23
- # subdirectory, but it doesn't create it. Make sure it exists.
24
- xsystem "mkdir -p libinjection"
25
- xsystem "mkdir -p lpeg"
26
-
27
- # Build init hook, only used when running agent in dev mode
28
- STDERR.puts `make -C ../../../../lua-hooks hooks/__init__.lua`
29
-
30
- #!!! PLEASE ALWAYS make sure the flags here match the Lua Makefile so our tests are valid
31
- # Enable safety assertions
32
- $CFLAGS << " -DLUA_USE_APICHECK -Dlua_assert=assert "
33
- # Enable omptimisation
34
- $CFLAGS << " -O3 "
35
- # Without this flag, I get this error when trying to compile in agent-java:
36
- # relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
37
- $CFLAGS << " -fPIC "
38
- create_makefile 'immunio/lua-hooks'
@@ -1,34 +0,0 @@
1
- Lua License
2
- -----------
3
-
4
- Lua is licensed under the terms of the MIT license reproduced below.
5
- This means that Lua is free software and can be used for both academic
6
- and commercial purposes at absolutely no cost.
7
-
8
- For details and rationale, see http://www.lua.org/license.html .
9
-
10
- ===============================================================================
11
-
12
- Copyright (C) 1994-2008 Lua.org, PUC-Rio.
13
-
14
- Permission is hereby granted, free of charge, to any person obtaining a copy
15
- of this software and associated documentation files (the "Software"), to deal
16
- in the Software without restriction, including without limitation the rights
17
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
- copies of the Software, and to permit persons to whom the Software is
19
- furnished to do so, subject to the following conditions:
20
-
21
- The above copyright notice and this permission notice shall be included in
22
- all copies or substantial portions of the Software.
23
-
24
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
- THE SOFTWARE.
31
-
32
- ===============================================================================
33
-
34
- (end of COPYRIGHT)
@@ -1,1087 +0,0 @@
1
- /*
2
- ** $Id: lapi.c,v 2.55.1.5 2008/07/04 18:41:18 roberto Exp $
3
- ** Lua API
4
- ** See Copyright Notice in lua.h
5
- */
6
-
7
-
8
- #include <assert.h>
9
- #include <math.h>
10
- #include <stdarg.h>
11
- #include <string.h>
12
-
13
- #define lapi_c
14
- #define LUA_CORE
15
-
16
- #include "lua.h"
17
-
18
- #include "lapi.h"
19
- #include "ldebug.h"
20
- #include "ldo.h"
21
- #include "lfunc.h"
22
- #include "lgc.h"
23
- #include "lmem.h"
24
- #include "lobject.h"
25
- #include "lstate.h"
26
- #include "lstring.h"
27
- #include "ltable.h"
28
- #include "ltm.h"
29
- #include "lundump.h"
30
- #include "lvm.h"
31
-
32
-
33
-
34
- const char lua_ident[] =
35
- "$Lua: " LUA_RELEASE " " LUA_COPYRIGHT " $\n"
36
- "$Authors: " LUA_AUTHORS " $\n"
37
- "$URL: www.lua.org $\n";
38
-
39
-
40
-
41
- #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base))
42
-
43
- #define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject)
44
-
45
- #define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;}
46
-
47
-
48
-
49
- static TValue *index2adr (lua_State *L, int idx) {
50
- if (idx > 0) {
51
- TValue *o = L->base + (idx - 1);
52
- api_check(L, idx <= L->ci->top - L->base);
53
- if (o >= L->top) return cast(TValue *, luaO_nilobject);
54
- else return o;
55
- }
56
- else if (idx > LUA_REGISTRYINDEX) {
57
- api_check(L, idx != 0 && -idx <= L->top - L->base);
58
- return L->top + idx;
59
- }
60
- else switch (idx) { /* pseudo-indices */
61
- case LUA_REGISTRYINDEX: return registry(L);
62
- case LUA_ENVIRONINDEX: {
63
- Closure *func = curr_func(L);
64
- sethvalue(L, &L->env, func->c.env);
65
- return &L->env;
66
- }
67
- case LUA_GLOBALSINDEX: return gt(L);
68
- default: {
69
- Closure *func = curr_func(L);
70
- idx = LUA_GLOBALSINDEX - idx;
71
- return (idx <= func->c.nupvalues)
72
- ? &func->c.upvalue[idx-1]
73
- : cast(TValue *, luaO_nilobject);
74
- }
75
- }
76
- }
77
-
78
-
79
- static Table *getcurrenv (lua_State *L) {
80
- if (L->ci == L->base_ci) /* no enclosing function? */
81
- return hvalue(gt(L)); /* use global table as environment */
82
- else {
83
- Closure *func = curr_func(L);
84
- return func->c.env;
85
- }
86
- }
87
-
88
-
89
- void luaA_pushobject (lua_State *L, const TValue *o) {
90
- setobj2s(L, L->top, o);
91
- api_incr_top(L);
92
- }
93
-
94
-
95
- LUA_API int lua_checkstack (lua_State *L, int size) {
96
- int res = 1;
97
- lua_lock(L);
98
- if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK)
99
- res = 0; /* stack overflow */
100
- else if (size > 0) {
101
- luaD_checkstack(L, size);
102
- if (L->ci->top < L->top + size)
103
- L->ci->top = L->top + size;
104
- }
105
- lua_unlock(L);
106
- return res;
107
- }
108
-
109
-
110
- LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {
111
- int i;
112
- if (from == to) return;
113
- lua_lock(to);
114
- api_checknelems(from, n);
115
- api_check(from, G(from) == G(to));
116
- api_check(from, to->ci->top - to->top >= n);
117
- from->top -= n;
118
- for (i = 0; i < n; i++) {
119
- setobj2s(to, to->top++, from->top + i);
120
- }
121
- lua_unlock(to);
122
- }
123
-
124
-
125
- LUA_API void lua_setlevel (lua_State *from, lua_State *to) {
126
- to->nCcalls = from->nCcalls;
127
- }
128
-
129
-
130
- LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {
131
- lua_CFunction old;
132
- lua_lock(L);
133
- old = G(L)->panic;
134
- G(L)->panic = panicf;
135
- lua_unlock(L);
136
- return old;
137
- }
138
-
139
-
140
- LUA_API lua_State *lua_newthread (lua_State *L) {
141
- lua_State *L1;
142
- lua_lock(L);
143
- luaC_checkGC(L);
144
- L1 = luaE_newthread(L);
145
- setthvalue(L, L->top, L1);
146
- api_incr_top(L);
147
- lua_unlock(L);
148
- luai_userstatethread(L, L1);
149
- return L1;
150
- }
151
-
152
-
153
-
154
- /*
155
- ** basic stack manipulation
156
- */
157
-
158
-
159
- LUA_API int lua_gettop (lua_State *L) {
160
- return cast_int(L->top - L->base);
161
- }
162
-
163
-
164
- LUA_API void lua_settop (lua_State *L, int idx) {
165
- lua_lock(L);
166
- if (idx >= 0) {
167
- api_check(L, idx <= L->stack_last - L->base);
168
- while (L->top < L->base + idx)
169
- setnilvalue(L->top++);
170
- L->top = L->base + idx;
171
- }
172
- else {
173
- api_check(L, -(idx+1) <= (L->top - L->base));
174
- L->top += idx+1; /* `subtract' index (index is negative) */
175
- }
176
- lua_unlock(L);
177
- }
178
-
179
-
180
- LUA_API void lua_remove (lua_State *L, int idx) {
181
- StkId p;
182
- lua_lock(L);
183
- p = index2adr(L, idx);
184
- api_checkvalidindex(L, p);
185
- while (++p < L->top) setobjs2s(L, p-1, p);
186
- L->top--;
187
- lua_unlock(L);
188
- }
189
-
190
-
191
- LUA_API void lua_insert (lua_State *L, int idx) {
192
- StkId p;
193
- StkId q;
194
- lua_lock(L);
195
- p = index2adr(L, idx);
196
- api_checkvalidindex(L, p);
197
- for (q = L->top; q>p; q--) setobjs2s(L, q, q-1);
198
- setobjs2s(L, p, L->top);
199
- lua_unlock(L);
200
- }
201
-
202
-
203
- LUA_API void lua_replace (lua_State *L, int idx) {
204
- StkId o;
205
- lua_lock(L);
206
- /* explicit test for incompatible code */
207
- if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci)
208
- luaG_runerror(L, "no calling environment");
209
- api_checknelems(L, 1);
210
- o = index2adr(L, idx);
211
- api_checkvalidindex(L, o);
212
- if (idx == LUA_ENVIRONINDEX) {
213
- Closure *func = curr_func(L);
214
- api_check(L, ttistable(L->top - 1));
215
- func->c.env = hvalue(L->top - 1);
216
- luaC_barrier(L, func, L->top - 1);
217
- }
218
- else {
219
- setobj(L, o, L->top - 1);
220
- if (idx < LUA_GLOBALSINDEX) /* function upvalue? */
221
- luaC_barrier(L, curr_func(L), L->top - 1);
222
- }
223
- L->top--;
224
- lua_unlock(L);
225
- }
226
-
227
-
228
- LUA_API void lua_pushvalue (lua_State *L, int idx) {
229
- lua_lock(L);
230
- setobj2s(L, L->top, index2adr(L, idx));
231
- api_incr_top(L);
232
- lua_unlock(L);
233
- }
234
-
235
-
236
-
237
- /*
238
- ** access functions (stack -> C)
239
- */
240
-
241
-
242
- LUA_API int lua_type (lua_State *L, int idx) {
243
- StkId o = index2adr(L, idx);
244
- return (o == luaO_nilobject) ? LUA_TNONE : ttype(o);
245
- }
246
-
247
-
248
- LUA_API const char *lua_typename (lua_State *L, int t) {
249
- UNUSED(L);
250
- return (t == LUA_TNONE) ? "no value" : luaT_typenames[t];
251
- }
252
-
253
-
254
- LUA_API int lua_iscfunction (lua_State *L, int idx) {
255
- StkId o = index2adr(L, idx);
256
- return iscfunction(o);
257
- }
258
-
259
-
260
- LUA_API int lua_isnumber (lua_State *L, int idx) {
261
- TValue n;
262
- const TValue *o = index2adr(L, idx);
263
- return tonumber(o, &n);
264
- }
265
-
266
-
267
- LUA_API int lua_isstring (lua_State *L, int idx) {
268
- int t = lua_type(L, idx);
269
- return (t == LUA_TSTRING || t == LUA_TNUMBER);
270
- }
271
-
272
-
273
- LUA_API int lua_isuserdata (lua_State *L, int idx) {
274
- const TValue *o = index2adr(L, idx);
275
- return (ttisuserdata(o) || ttislightuserdata(o));
276
- }
277
-
278
-
279
- LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
280
- StkId o1 = index2adr(L, index1);
281
- StkId o2 = index2adr(L, index2);
282
- return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
283
- : luaO_rawequalObj(o1, o2);
284
- }
285
-
286
-
287
- LUA_API int lua_equal (lua_State *L, int index1, int index2) {
288
- StkId o1, o2;
289
- int i;
290
- lua_lock(L); /* may call tag method */
291
- o1 = index2adr(L, index1);
292
- o2 = index2adr(L, index2);
293
- i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2);
294
- lua_unlock(L);
295
- return i;
296
- }
297
-
298
-
299
- LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
300
- StkId o1, o2;
301
- int i;
302
- lua_lock(L); /* may call tag method */
303
- o1 = index2adr(L, index1);
304
- o2 = index2adr(L, index2);
305
- i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
306
- : luaV_lessthan(L, o1, o2);
307
- lua_unlock(L);
308
- return i;
309
- }
310
-
311
-
312
-
313
- LUA_API lua_Number lua_tonumber (lua_State *L, int idx) {
314
- TValue n;
315
- const TValue *o = index2adr(L, idx);
316
- if (tonumber(o, &n))
317
- return nvalue(o);
318
- else
319
- return 0;
320
- }
321
-
322
-
323
- LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {
324
- TValue n;
325
- const TValue *o = index2adr(L, idx);
326
- if (tonumber(o, &n)) {
327
- lua_Integer res;
328
- lua_Number num = nvalue(o);
329
- lua_number2integer(res, num);
330
- return res;
331
- }
332
- else
333
- return 0;
334
- }
335
-
336
-
337
- LUA_API int lua_toboolean (lua_State *L, int idx) {
338
- const TValue *o = index2adr(L, idx);
339
- return !l_isfalse(o);
340
- }
341
-
342
-
343
- LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
344
- StkId o = index2adr(L, idx);
345
- if (!ttisstring(o)) {
346
- lua_lock(L); /* `luaV_tostring' may create a new string */
347
- if (!luaV_tostring(L, o)) { /* conversion failed? */
348
- if (len != NULL) *len = 0;
349
- lua_unlock(L);
350
- return NULL;
351
- }
352
- luaC_checkGC(L);
353
- o = index2adr(L, idx); /* previous call may reallocate the stack */
354
- lua_unlock(L);
355
- }
356
- if (len != NULL) *len = tsvalue(o)->len;
357
- return svalue(o);
358
- }
359
-
360
-
361
- LUA_API size_t lua_objlen (lua_State *L, int idx) {
362
- StkId o = index2adr(L, idx);
363
- switch (ttype(o)) {
364
- case LUA_TSTRING: return tsvalue(o)->len;
365
- case LUA_TUSERDATA: return uvalue(o)->len;
366
- case LUA_TTABLE: return luaH_getn(hvalue(o));
367
- case LUA_TNUMBER: {
368
- size_t l;
369
- lua_lock(L); /* `luaV_tostring' may create a new string */
370
- l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0);
371
- lua_unlock(L);
372
- return l;
373
- }
374
- default: return 0;
375
- }
376
- }
377
-
378
-
379
- LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
380
- StkId o = index2adr(L, idx);
381
- return (!iscfunction(o)) ? NULL : clvalue(o)->c.f;
382
- }
383
-
384
-
385
- LUA_API void *lua_touserdata (lua_State *L, int idx) {
386
- StkId o = index2adr(L, idx);
387
- switch (ttype(o)) {
388
- case LUA_TUSERDATA: return (rawuvalue(o) + 1);
389
- case LUA_TLIGHTUSERDATA: return pvalue(o);
390
- default: return NULL;
391
- }
392
- }
393
-
394
-
395
- LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
396
- StkId o = index2adr(L, idx);
397
- return (!ttisthread(o)) ? NULL : thvalue(o);
398
- }
399
-
400
-
401
- LUA_API const void *lua_topointer (lua_State *L, int idx) {
402
- StkId o = index2adr(L, idx);
403
- switch (ttype(o)) {
404
- case LUA_TTABLE: return hvalue(o);
405
- case LUA_TFUNCTION: return clvalue(o);
406
- case LUA_TTHREAD: return thvalue(o);
407
- case LUA_TUSERDATA:
408
- case LUA_TLIGHTUSERDATA:
409
- return lua_touserdata(L, idx);
410
- default: return NULL;
411
- }
412
- }
413
-
414
-
415
-
416
- /*
417
- ** push functions (C -> stack)
418
- */
419
-
420
-
421
- LUA_API void lua_pushnil (lua_State *L) {
422
- lua_lock(L);
423
- setnilvalue(L->top);
424
- api_incr_top(L);
425
- lua_unlock(L);
426
- }
427
-
428
-
429
- LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
430
- lua_lock(L);
431
- setnvalue(L->top, n);
432
- api_incr_top(L);
433
- lua_unlock(L);
434
- }
435
-
436
-
437
- LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
438
- lua_lock(L);
439
- setnvalue(L->top, cast_num(n));
440
- api_incr_top(L);
441
- lua_unlock(L);
442
- }
443
-
444
-
445
- LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
446
- lua_lock(L);
447
- luaC_checkGC(L);
448
- setsvalue2s(L, L->top, luaS_newlstr(L, s, len));
449
- api_incr_top(L);
450
- lua_unlock(L);
451
- }
452
-
453
-
454
- LUA_API void lua_pushstring (lua_State *L, const char *s) {
455
- if (s == NULL)
456
- lua_pushnil(L);
457
- else
458
- lua_pushlstring(L, s, strlen(s));
459
- }
460
-
461
-
462
- LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,
463
- va_list argp) {
464
- const char *ret;
465
- lua_lock(L);
466
- luaC_checkGC(L);
467
- ret = luaO_pushvfstring(L, fmt, argp);
468
- lua_unlock(L);
469
- return ret;
470
- }
471
-
472
-
473
- LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {
474
- const char *ret;
475
- va_list argp;
476
- lua_lock(L);
477
- luaC_checkGC(L);
478
- va_start(argp, fmt);
479
- ret = luaO_pushvfstring(L, fmt, argp);
480
- va_end(argp);
481
- lua_unlock(L);
482
- return ret;
483
- }
484
-
485
-
486
- LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
487
- Closure *cl;
488
- lua_lock(L);
489
- luaC_checkGC(L);
490
- api_checknelems(L, n);
491
- cl = luaF_newCclosure(L, n, getcurrenv(L));
492
- cl->c.f = fn;
493
- L->top -= n;
494
- while (n--)
495
- setobj2n(L, &cl->c.upvalue[n], L->top+n);
496
- setclvalue(L, L->top, cl);
497
- lua_assert(iswhite(obj2gco(cl)));
498
- api_incr_top(L);
499
- lua_unlock(L);
500
- }
501
-
502
-
503
- LUA_API void lua_pushboolean (lua_State *L, int b) {
504
- lua_lock(L);
505
- setbvalue(L->top, (b != 0)); /* ensure that true is 1 */
506
- api_incr_top(L);
507
- lua_unlock(L);
508
- }
509
-
510
-
511
- LUA_API void lua_pushlightuserdata (lua_State *L, void *p) {
512
- lua_lock(L);
513
- setpvalue(L->top, p);
514
- api_incr_top(L);
515
- lua_unlock(L);
516
- }
517
-
518
-
519
- LUA_API int lua_pushthread (lua_State *L) {
520
- lua_lock(L);
521
- setthvalue(L, L->top, L);
522
- api_incr_top(L);
523
- lua_unlock(L);
524
- return (G(L)->mainthread == L);
525
- }
526
-
527
-
528
-
529
- /*
530
- ** get functions (Lua -> stack)
531
- */
532
-
533
-
534
- LUA_API void lua_gettable (lua_State *L, int idx) {
535
- StkId t;
536
- lua_lock(L);
537
- t = index2adr(L, idx);
538
- api_checkvalidindex(L, t);
539
- luaV_gettable(L, t, L->top - 1, L->top - 1);
540
- lua_unlock(L);
541
- }
542
-
543
-
544
- LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
545
- StkId t;
546
- TValue key;
547
- lua_lock(L);
548
- t = index2adr(L, idx);
549
- api_checkvalidindex(L, t);
550
- setsvalue(L, &key, luaS_new(L, k));
551
- luaV_gettable(L, t, &key, L->top);
552
- api_incr_top(L);
553
- lua_unlock(L);
554
- }
555
-
556
-
557
- LUA_API void lua_rawget (lua_State *L, int idx) {
558
- StkId t;
559
- lua_lock(L);
560
- t = index2adr(L, idx);
561
- api_check(L, ttistable(t));
562
- setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
563
- lua_unlock(L);
564
- }
565
-
566
-
567
- LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
568
- StkId o;
569
- lua_lock(L);
570
- o = index2adr(L, idx);
571
- api_check(L, ttistable(o));
572
- setobj2s(L, L->top, luaH_getnum(hvalue(o), n));
573
- api_incr_top(L);
574
- lua_unlock(L);
575
- }
576
-
577
-
578
- LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {
579
- lua_lock(L);
580
- luaC_checkGC(L);
581
- sethvalue(L, L->top, luaH_new(L, narray, nrec));
582
- api_incr_top(L);
583
- lua_unlock(L);
584
- }
585
-
586
-
587
- LUA_API int lua_getmetatable (lua_State *L, int objindex) {
588
- const TValue *obj;
589
- Table *mt = NULL;
590
- int res;
591
- lua_lock(L);
592
- obj = index2adr(L, objindex);
593
- switch (ttype(obj)) {
594
- case LUA_TTABLE:
595
- mt = hvalue(obj)->metatable;
596
- break;
597
- case LUA_TUSERDATA:
598
- mt = uvalue(obj)->metatable;
599
- break;
600
- default:
601
- mt = G(L)->mt[ttype(obj)];
602
- break;
603
- }
604
- if (mt == NULL)
605
- res = 0;
606
- else {
607
- sethvalue(L, L->top, mt);
608
- api_incr_top(L);
609
- res = 1;
610
- }
611
- lua_unlock(L);
612
- return res;
613
- }
614
-
615
-
616
- LUA_API void lua_getfenv (lua_State *L, int idx) {
617
- StkId o;
618
- lua_lock(L);
619
- o = index2adr(L, idx);
620
- api_checkvalidindex(L, o);
621
- switch (ttype(o)) {
622
- case LUA_TFUNCTION:
623
- sethvalue(L, L->top, clvalue(o)->c.env);
624
- break;
625
- case LUA_TUSERDATA:
626
- sethvalue(L, L->top, uvalue(o)->env);
627
- break;
628
- case LUA_TTHREAD:
629
- setobj2s(L, L->top, gt(thvalue(o)));
630
- break;
631
- default:
632
- setnilvalue(L->top);
633
- break;
634
- }
635
- api_incr_top(L);
636
- lua_unlock(L);
637
- }
638
-
639
-
640
- /*
641
- ** set functions (stack -> Lua)
642
- */
643
-
644
-
645
- LUA_API void lua_settable (lua_State *L, int idx) {
646
- StkId t;
647
- lua_lock(L);
648
- api_checknelems(L, 2);
649
- t = index2adr(L, idx);
650
- api_checkvalidindex(L, t);
651
- luaV_settable(L, t, L->top - 2, L->top - 1);
652
- L->top -= 2; /* pop index and value */
653
- lua_unlock(L);
654
- }
655
-
656
-
657
- LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
658
- StkId t;
659
- TValue key;
660
- lua_lock(L);
661
- api_checknelems(L, 1);
662
- t = index2adr(L, idx);
663
- api_checkvalidindex(L, t);
664
- setsvalue(L, &key, luaS_new(L, k));
665
- luaV_settable(L, t, &key, L->top - 1);
666
- L->top--; /* pop value */
667
- lua_unlock(L);
668
- }
669
-
670
-
671
- LUA_API void lua_rawset (lua_State *L, int idx) {
672
- StkId t;
673
- lua_lock(L);
674
- api_checknelems(L, 2);
675
- t = index2adr(L, idx);
676
- api_check(L, ttistable(t));
677
- setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
678
- luaC_barriert(L, hvalue(t), L->top-1);
679
- L->top -= 2;
680
- lua_unlock(L);
681
- }
682
-
683
-
684
- LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
685
- StkId o;
686
- lua_lock(L);
687
- api_checknelems(L, 1);
688
- o = index2adr(L, idx);
689
- api_check(L, ttistable(o));
690
- setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1);
691
- luaC_barriert(L, hvalue(o), L->top-1);
692
- L->top--;
693
- lua_unlock(L);
694
- }
695
-
696
-
697
- LUA_API int lua_setmetatable (lua_State *L, int objindex) {
698
- TValue *obj;
699
- Table *mt;
700
- lua_lock(L);
701
- api_checknelems(L, 1);
702
- obj = index2adr(L, objindex);
703
- api_checkvalidindex(L, obj);
704
- if (ttisnil(L->top - 1))
705
- mt = NULL;
706
- else {
707
- api_check(L, ttistable(L->top - 1));
708
- mt = hvalue(L->top - 1);
709
- }
710
- switch (ttype(obj)) {
711
- case LUA_TTABLE: {
712
- hvalue(obj)->metatable = mt;
713
- if (mt)
714
- luaC_objbarriert(L, hvalue(obj), mt);
715
- break;
716
- }
717
- case LUA_TUSERDATA: {
718
- uvalue(obj)->metatable = mt;
719
- if (mt)
720
- luaC_objbarrier(L, rawuvalue(obj), mt);
721
- break;
722
- }
723
- default: {
724
- G(L)->mt[ttype(obj)] = mt;
725
- break;
726
- }
727
- }
728
- L->top--;
729
- lua_unlock(L);
730
- return 1;
731
- }
732
-
733
-
734
- LUA_API int lua_setfenv (lua_State *L, int idx) {
735
- StkId o;
736
- int res = 1;
737
- lua_lock(L);
738
- api_checknelems(L, 1);
739
- o = index2adr(L, idx);
740
- api_checkvalidindex(L, o);
741
- api_check(L, ttistable(L->top - 1));
742
- switch (ttype(o)) {
743
- case LUA_TFUNCTION:
744
- clvalue(o)->c.env = hvalue(L->top - 1);
745
- break;
746
- case LUA_TUSERDATA:
747
- uvalue(o)->env = hvalue(L->top - 1);
748
- break;
749
- case LUA_TTHREAD:
750
- sethvalue(L, gt(thvalue(o)), hvalue(L->top - 1));
751
- break;
752
- default:
753
- res = 0;
754
- break;
755
- }
756
- if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
757
- L->top--;
758
- lua_unlock(L);
759
- return res;
760
- }
761
-
762
-
763
- /*
764
- ** `load' and `call' functions (run Lua code)
765
- */
766
-
767
-
768
- #define adjustresults(L,nres) \
769
- { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; }
770
-
771
-
772
- #define checkresults(L,na,nr) \
773
- api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)))
774
-
775
-
776
- LUA_API void lua_call (lua_State *L, int nargs, int nresults) {
777
- StkId func;
778
- lua_lock(L);
779
- api_checknelems(L, nargs+1);
780
- checkresults(L, nargs, nresults);
781
- func = L->top - (nargs+1);
782
- luaD_call(L, func, nresults);
783
- adjustresults(L, nresults);
784
- lua_unlock(L);
785
- }
786
-
787
-
788
-
789
- /*
790
- ** Execute a protected call.
791
- */
792
- struct CallS { /* data to `f_call' */
793
- StkId func;
794
- int nresults;
795
- };
796
-
797
-
798
- static void f_call (lua_State *L, void *ud) {
799
- struct CallS *c = cast(struct CallS *, ud);
800
- luaD_call(L, c->func, c->nresults);
801
- }
802
-
803
-
804
-
805
- LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) {
806
- struct CallS c;
807
- int status;
808
- ptrdiff_t func;
809
- lua_lock(L);
810
- api_checknelems(L, nargs+1);
811
- checkresults(L, nargs, nresults);
812
- if (errfunc == 0)
813
- func = 0;
814
- else {
815
- StkId o = index2adr(L, errfunc);
816
- api_checkvalidindex(L, o);
817
- func = savestack(L, o);
818
- }
819
- c.func = L->top - (nargs+1); /* function to be called */
820
- c.nresults = nresults;
821
- status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
822
- adjustresults(L, nresults);
823
- lua_unlock(L);
824
- return status;
825
- }
826
-
827
-
828
- /*
829
- ** Execute a protected C call.
830
- */
831
- struct CCallS { /* data to `f_Ccall' */
832
- lua_CFunction func;
833
- void *ud;
834
- };
835
-
836
-
837
- static void f_Ccall (lua_State *L, void *ud) {
838
- struct CCallS *c = cast(struct CCallS *, ud);
839
- Closure *cl;
840
- cl = luaF_newCclosure(L, 0, getcurrenv(L));
841
- cl->c.f = c->func;
842
- setclvalue(L, L->top, cl); /* push function */
843
- api_incr_top(L);
844
- setpvalue(L->top, c->ud); /* push only argument */
845
- api_incr_top(L);
846
- luaD_call(L, L->top - 2, 0);
847
- }
848
-
849
-
850
- LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) {
851
- struct CCallS c;
852
- int status;
853
- lua_lock(L);
854
- c.func = func;
855
- c.ud = ud;
856
- status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0);
857
- lua_unlock(L);
858
- return status;
859
- }
860
-
861
-
862
- LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
863
- const char *chunkname) {
864
- ZIO z;
865
- int status;
866
- lua_lock(L);
867
- if (!chunkname) chunkname = "?";
868
- luaZ_init(L, &z, reader, data);
869
- status = luaD_protectedparser(L, &z, chunkname);
870
- lua_unlock(L);
871
- return status;
872
- }
873
-
874
-
875
- LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) {
876
- int status;
877
- TValue *o;
878
- lua_lock(L);
879
- api_checknelems(L, 1);
880
- o = L->top - 1;
881
- if (isLfunction(o))
882
- status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0);
883
- else
884
- status = 1;
885
- lua_unlock(L);
886
- return status;
887
- }
888
-
889
-
890
- LUA_API int lua_status (lua_State *L) {
891
- return L->status;
892
- }
893
-
894
-
895
- /*
896
- ** Garbage-collection function
897
- */
898
-
899
- LUA_API int lua_gc (lua_State *L, int what, int data) {
900
- int res = 0;
901
- global_State *g;
902
- lua_lock(L);
903
- g = G(L);
904
- switch (what) {
905
- case LUA_GCSTOP: {
906
- g->GCthreshold = MAX_LUMEM;
907
- break;
908
- }
909
- case LUA_GCRESTART: {
910
- g->GCthreshold = g->totalbytes;
911
- break;
912
- }
913
- case LUA_GCCOLLECT: {
914
- luaC_fullgc(L);
915
- break;
916
- }
917
- case LUA_GCCOUNT: {
918
- /* GC values are expressed in Kbytes: #bytes/2^10 */
919
- res = cast_int(g->totalbytes >> 10);
920
- break;
921
- }
922
- case LUA_GCCOUNTB: {
923
- res = cast_int(g->totalbytes & 0x3ff);
924
- break;
925
- }
926
- case LUA_GCSTEP: {
927
- lu_mem a = (cast(lu_mem, data) << 10);
928
- if (a <= g->totalbytes)
929
- g->GCthreshold = g->totalbytes - a;
930
- else
931
- g->GCthreshold = 0;
932
- while (g->GCthreshold <= g->totalbytes) {
933
- luaC_step(L);
934
- if (g->gcstate == GCSpause) { /* end of cycle? */
935
- res = 1; /* signal it */
936
- break;
937
- }
938
- }
939
- break;
940
- }
941
- case LUA_GCSETPAUSE: {
942
- res = g->gcpause;
943
- g->gcpause = data;
944
- break;
945
- }
946
- case LUA_GCSETSTEPMUL: {
947
- res = g->gcstepmul;
948
- g->gcstepmul = data;
949
- break;
950
- }
951
- default: res = -1; /* invalid option */
952
- }
953
- lua_unlock(L);
954
- return res;
955
- }
956
-
957
-
958
-
959
- /*
960
- ** miscellaneous functions
961
- */
962
-
963
-
964
- LUA_API int lua_error (lua_State *L) {
965
- lua_lock(L);
966
- api_checknelems(L, 1);
967
- luaG_errormsg(L);
968
- lua_unlock(L);
969
- return 0; /* to avoid warnings */
970
- }
971
-
972
-
973
- LUA_API int lua_next (lua_State *L, int idx) {
974
- StkId t;
975
- int more;
976
- lua_lock(L);
977
- t = index2adr(L, idx);
978
- api_check(L, ttistable(t));
979
- more = luaH_next(L, hvalue(t), L->top - 1);
980
- if (more) {
981
- api_incr_top(L);
982
- }
983
- else /* no more elements */
984
- L->top -= 1; /* remove key */
985
- lua_unlock(L);
986
- return more;
987
- }
988
-
989
-
990
- LUA_API void lua_concat (lua_State *L, int n) {
991
- lua_lock(L);
992
- api_checknelems(L, n);
993
- if (n >= 2) {
994
- luaC_checkGC(L);
995
- luaV_concat(L, n, cast_int(L->top - L->base) - 1);
996
- L->top -= (n-1);
997
- }
998
- else if (n == 0) { /* push empty string */
999
- setsvalue2s(L, L->top, luaS_newlstr(L, "", 0));
1000
- api_incr_top(L);
1001
- }
1002
- /* else n == 1; nothing to do */
1003
- lua_unlock(L);
1004
- }
1005
-
1006
-
1007
- LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {
1008
- lua_Alloc f;
1009
- lua_lock(L);
1010
- if (ud) *ud = G(L)->ud;
1011
- f = G(L)->frealloc;
1012
- lua_unlock(L);
1013
- return f;
1014
- }
1015
-
1016
-
1017
- LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {
1018
- lua_lock(L);
1019
- G(L)->ud = ud;
1020
- G(L)->frealloc = f;
1021
- lua_unlock(L);
1022
- }
1023
-
1024
-
1025
- LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
1026
- Udata *u;
1027
- lua_lock(L);
1028
- luaC_checkGC(L);
1029
- u = luaS_newudata(L, size, getcurrenv(L));
1030
- setuvalue(L, L->top, u);
1031
- api_incr_top(L);
1032
- lua_unlock(L);
1033
- return u + 1;
1034
- }
1035
-
1036
-
1037
-
1038
-
1039
- static const char *aux_upvalue (StkId fi, int n, TValue **val) {
1040
- Closure *f;
1041
- if (!ttisfunction(fi)) return NULL;
1042
- f = clvalue(fi);
1043
- if (f->c.isC) {
1044
- if (!(1 <= n && n <= f->c.nupvalues)) return NULL;
1045
- *val = &f->c.upvalue[n-1];
1046
- return "";
1047
- }
1048
- else {
1049
- Proto *p = f->l.p;
1050
- if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
1051
- *val = f->l.upvals[n-1]->v;
1052
- return getstr(p->upvalues[n-1]);
1053
- }
1054
- }
1055
-
1056
-
1057
- LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
1058
- const char *name;
1059
- TValue *val;
1060
- lua_lock(L);
1061
- name = aux_upvalue(index2adr(L, funcindex), n, &val);
1062
- if (name) {
1063
- setobj2s(L, L->top, val);
1064
- api_incr_top(L);
1065
- }
1066
- lua_unlock(L);
1067
- return name;
1068
- }
1069
-
1070
-
1071
- LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
1072
- const char *name;
1073
- TValue *val;
1074
- StkId fi;
1075
- lua_lock(L);
1076
- fi = index2adr(L, funcindex);
1077
- api_checknelems(L, 1);
1078
- name = aux_upvalue(fi, n, &val);
1079
- if (name) {
1080
- L->top--;
1081
- setobj(L, val, L->top);
1082
- luaC_barrier(L, clvalue(fi), L->top);
1083
- }
1084
- lua_unlock(L);
1085
- return name;
1086
- }
1087
-