Is it possible to make a LuaJIT check a border?

LuaJIT knows the C types that it defines and the lengths of arrays, but it does not check the bounds:

ffi = require("ffi")

ten_ints = ffi.typeof("int [10]")
p1 = ten_ints()
print(ffi.sizeof(p1))  -- 40


var_ints = ffi.typeof("int [?]")
p2 = ffi.new(var_ints, 10)
print(ffi.sizeof(p2)) -- 40

p1[1000000] = 1 -- segfault
p2[1000000] = 1 -- segfault

Is there any way to do this, or is my only choice for writing wrappers?

+4
source share
1 answer

Short answer: there is no way, you have to write / find your own packaging.

Here is an explanation from luajit.org

No hands!

[...] FFI , Lua. NULL, C. , , , C . , C. , , . [...] . : FFI .

+4

All Articles