C数据
C Data是LuaJIT FFI转换为C String的简单包装。 这主要用于将Lua表序列化为可网络传输的数据。
值得注意的是,如果对不完整的表进行编码(缺少密钥),则在解码数据包时,它将具有值为0的丢失密钥。
例子
注册数据包
local cdata = require " cdata "
local packets = {}
-- all structs get a type field so we don't lose our minds.
function add_struct ( name , fields , map )
local struct = string.format ( " typedef struct { uint8_t type; %s } %s; " , fields, name)
cdata: new_struct (na