[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: LuaJIT FFI callbacks (was Re: Calling lua functions from C when using luajit ffi.)
- From: Duncan Cross <duncan.cross@...>
- Date: Tue, 15 Nov 2011 00:30:40 +0000
On Mon, Nov 14, 2011 at 11:27 PM, Mike Pall <firstname.lastname@example.org> wrote:
> Dimiter 'malkia' Stanev wrote:
>> Mike just put support for callbacks for x86/x64
> Yep. Attached are two examples using FFI callbacks. You'll need
> LuaJIT git HEAD on x86 or x64 to run these.
> The first example is for Windows that lists all window titles, the
> other is a simple GTK+ demo (tested on Linux). Excuse the length
> of the GTK+ demo, but programming in GTK+ gets rather verbose.
> Docs are here: http://luajit.org/ext_ffi_semantics.html#callback
> tl;dr: Just pass a Lua function to a C function taking a callback
> argument and the FFI will do all the magic in the background.
> The FFI callback feature for x86/x64 has been sponsored by a
> corporate sponsor, who wishes to remain anonymous at this time.
> Ports to other architectures will follow, depending on sponsorship.
> Or if someone wants to grind their teeth at a really challenging
> assembler project for the CPU of your choice. :-)
This is fantastic news! Thanks so much for your work, and thanks too
to the anonymous sponsor.
One thing - I'm not certain this is related to the addition of
callbacks, but I was just experimenting with Win32 calls and found
that GetLastError() seems to return the wrong value (127,
ERROR_PROC_NOT_FOUND) the first time it's called. This is a minimal
local ffi = require("ffi")
void SetLastError(uint32_t code);
print(ffi.C.GetLastError()) -- 127
print(ffi.C.GetLastError()) -- 0
(I'm explicitly setting the error here, but I discovered it because it
was hiding a parameter error while I was experimenting with trying to