Not currently supported. My current plan for transparent cdata support would require user code for all serialized ctypes:
Code: Select all
local ffi = require('ffi')
ffi.cdef('typedef struct { double x, y; } teststruct_t')
local ctype = ffi.typeof('teststruct_t')
ffi.metatype(ctype, {
__index = {
__typename = 'teststruct_t',
__serialize = function(self, writer)
return writer:number(self.x):number(self.y)
end,
__deserialize = function(ctype, reader)
return ctype(reader:number(), reader:number())
end,
}
})
Edit: cdata serialization as described above is now supported. Example code.
The __serialize() and __deserialize() functions are only required for complex structs with pointers, and for cases when ffi.sizeof() is not sufficient to get the true size of the data.
The __typename field is required, except when calling :cdata() manually with a type name, in which case the metatype is not required at all (e.g. when using brinevector).
Code: Select all
-- brinevector example (no __typename, __serialize, or __deserialize are defined in brinevector}
-- this works
writer:cdata('brinevector', vector)
...
vector = reader:cdata()
-- but this is not possible, because no type information is available (and metatypes are immutable)
writer:write(vector)
-- or
writer:table({ vector }) -- ditto