local function vtable_entry(instance, index, type)
return ffi.cast(type, (ffi.cast("void***", instance)[0])[index])
end
local function vtable_thunk(index, typestring)
local t = ffi.typeof(typestring)
return function(instance, ...)
assert(instance ~= nil)
if instance then
return vtable_entry(instance, index, t)(instance, ...)
end
end
end
local function vtable_bind(module, interface, index, typestring)
local instance = Utils.CreateInterface(module, interface) or error("invalid interface")
local fnptr = vtable_entry(instance, index, ffi.typeof(typestring)) or error("invalid vtable")
return function(...)
return fnptr(instance, ...)
end
end