mascarenhas / alien

A C FFI for Lua
http://mascarenhas.github.com/alien/
143 stars 45 forks source link

Allow (NUL-terminated) array of chars inside a def_struct #45

Open 1linux opened 8 years ago

1linux commented 8 years ago

Example:

SMsgError = alien.defstruct{ {"cmdLen", "ulong"}, {"cmd", "ulong"}, {"deviceType","byte"}, {"deviceNo","byte"}, {"errNo","short"}, {"errStr", "char",256}, {"errType","byte"} } Note the optional third element in the struct´s definition.

Now you can:

local instance=SMsgError:new()
instance.errStr="This is a severe error..."

errStr is padded with NUL-bytes. You can also

print( instance.errStr )