q66 / cffi-lua

A portable C FFI for Lua 5.1+
MIT License
176 stars 24 forks source link

Type comparison (istype) differs from LuaJIT #26

Closed niess closed 3 years ago

niess commented 3 years ago

Hello,

Thank your for your help on the previous issue.

this one might be intended? I came across the following difference between LuaJIT/ffi and cffi:

local ffi = jit and require('ffi') or require('cffi')

ffi.cdef([[
struct structure {
    double scalar;
    double vector[3];
};
]])

local structure = ffi.new('struct structure')
print(ffi.istype('double [3]', structure.vector))
print(ffi.istype('double (&)[3]', structure.vector))

the last istype returns true with LuaJIT/ffi but false with cffi, i.e. double [3] and double (&)[3] are considered as the same type in one case but different types in the second case.

q66 commented 3 years ago

you sure? it looks to me like the first istype returns false on cffi, and the last one returns true

niess commented 3 years ago

@q66 You are right I inverted both cases in the explanation. Sorry. Yet there is still a difference in behaviour. But mabye it is intended?*

So with cffi one gets false, true but with LuaJIT/ffi one gets true, true. I.e. double [] and double (&)[] seem to be equivalent istype in LuaJIT/ffi but not with cffi.

q66 commented 3 years ago

well, not anymore, should be fixed

niess commented 3 years ago

Thank you for the patch :)