lua-users home
lua-l archive

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


On Mon, Nov 14, 2011 at 11:27 PM, Mike Pall <mikelu-1111@mike.de> 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. :-)
>
> --Mike
>

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
test case:

  local ffi = require("ffi")

  ffi.cdef [[
  uint32_t GetLastError();
  void SetLastError(uint32_t code);
  ]]

  ffi.C.SetLastError(0)
  print(ffi.C.GetLastError()) -- 127
  ffi.C.SetLastError(0)
  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
call RegisterClassExA().)

-Duncan