lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> On Feb 21, 2017, at 1:21 AM, 云风 Cloud Wu <> wrote:
> string.unpack is a power tool to process the binary data. Sometimes, we use userdata as a string (binary data) buffer. I think if string.unpack support userdata as parameter would be better for this case.
> And, if the userdata is a C struct, we can simply use string.unpack to extract the data from the C struct, otherwise we should copy it (by lua_pushlstring) to a string first.

One problem with this is that it violates the principle that userdata is opaque to Lua. The cycle userdata -> string -> userdata allows Lua to manipulate the contents of userdata, which is currently not allowed.