[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A question about table's length
- From: Javier Guerra <javier@...>
- Date: Thu, 31 Dec 2009 14:58:50 -0500
Mike Pall wrote:
> I haven't given much thought to the API yet, but it might look
> something like this:
>
> ffi.def[[
> struct foo {
> uint16_t bar, baz;
> int i;
> double d;
> };
> struct foo *foo_in(void);
> void foo_out(struct foo *);
> ]]
> local lib = ffi.bindlib("myfoolib")
>
> local a = lib.foo_in()
> local b = ffi.new("struct foo")
> b.i = a.i + 10
> b.bar = bit.bxor(a.bar, a.baz)
> b.baz = 0x1234
> b.d = a.d - 1.5
> lib.foo_out(b)
>
> -- Nice side-effect: efficient, mutable buffers for Lua.
> local buf = ffi.new("uint8_t[?]", n)
> for i=0,n-1 do
> buf[i] = i
> end
> io.write(buf) -- Extended to understand binary data.
Wow!!! wanna!
--
Javier