lua-users home
lua-l archive

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

On Wed, Jun 29, 2011 at 9:31 AM, Lorenzo Donati
<> wrote:
> So why it is not deemed useful to have the possibility to define custom data
> types in this way directly in Lua (not using C API, I mean)?

It is very useful to have in the language - this is exactly what
LuaJIT's FFI is all about.  Alien allows similar stuff with vanilla
Lua and allows you to manipulate buffers as userdata.

But it is tricky to bring such low-level stuff into a high-level
language. It's often easier just to do it in C, since the _actual
layout_ of a structure depends on so many things, endianness, word
size, alignment, and so forth.  Something like Roberto's struct
library knows about this stuff and can be used to unpack a given bit
of binary data in Lua.

Things like fast binary arrays are possible but really belong in a library.

steve d.