[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Suggestion: let string.unpack support userdata
- From: Tim Hill <drtimhill@...>
- Date: Tue, 21 Feb 2017 12:56:03 -0800
> On Feb 21, 2017, at 1:21 AM, 云风 Cloud Wu <cloudwu@gmail.com> 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.
—Tim