...
In some cases you don't know what kind of ID you are being passed. To determine whether a variable is an FFI-ID, you can use the follow code
Code Block |
---|
-- ffi setuplocal ffi = require("ffi")
ffi.cdef[[
typedef uint64_t UniverseID;
]]
[...]
local myUniverseID = [...]
[...]
local ffiIDType = ffi.typeof("UniverseID")
local isFFIID = ffi.istype(ffiIDType, myUniverseID)
-- isFFIID will be true, if myUniverseID is an FFIID, otherwise this will be false |
In exceptional cases you might also have to create FFI datatypes directly in the Lua script. Normally this is not necessary, since passing certain Lua values to FFI will be converted to the appropriate type directly. However, in cases where you have to construct objects of an FFI type, you can do so using ffi.new
Code Block |
---|
local myFFIObject = ffi.new("UniverseID", 123) |
The code above will create an object of type UniverseID and initialize it with the value of 123.