lua-users home
lua-l archive

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


Good news everyone,

I made a small patch (with diff -uN, attached) for alien, based on my
experience with some bindings I made recently. Hope is ok to post it
here, also hope it will make it into the alien "tree" (I'd like to
release a firebird driver that would love this patch).

List of changes:

- added "ushort", "uint", "ulong", and "ref uint" types along with
alien.toushort(), alien. touint(), alien.toulong();
- added optional arg. offset to buf:topointer() making it
buf:topointer([offset]);
- added optional arg. offset to buf:tostring() making it
buf:tostring([size],[offset]) -- setting size to nil will call
strlen();
- added struct.offset(layout, record_number) which gives you a byte
offset given a record offset -- as with struct.size(), it only works
with fixed-size structures.
- added type 'p' for struct.pack() for packing up a pointer (userdata
or lightuserdata), and to struct.unpack() for unpacking it (gets you a
light userdata); struct.size('p') == sizeof(void*); the 'p' type is
not affected by the endianness of the layout.
- added test file.

Limitations:
- only tested on 32bit linux

My questions for Fabio and/or others interested:
1) I need a way to copy a string into a buffer at some offset -- I'd
rather not summon memcpy() and co., instead this should be built-in
into alien. Some ideas:
  - alien.memcpy(dst_buf, src_buf or light_userdata, size)
  - buf:get() and buf:set() applied with the "string" type, which
currently don't have clear semantics.
What do you think?

2) What's the point of "ref" types for buffers? any semantics planned for them?

3) What do I need to make "luarocks make" work with the alien recipe
in Windows? Or what is the preferred method to build alien on diff.
platforms with min. of fuss?

Thank you all,
Cosmin.

Attachment: patch.struct.c
Description: Binary data

Attachment: patch.core.c
Description: Binary data

Attachment: test_alien_new.lua
Description: Binary data