lua-users home
lua-l archive

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


On Fri, May 22, 2009 at 1:01 AM, Marco Antonio Abreu
<mabreu.ti@gmail.com> wrote:
> I didn't know Alien, it's excelent. Congratulations!
>
> I read the doc at LuaForge and like Alien very much. It can give us so much
> power, so easily. Sorry, but I didn't find how can we free the memory
> allocated by the methods alien.buffer and aline.array. Can you tell us?

Quick look at the code - the buffer metatable doesn't have a __c
metamethod (unlike functions or libraries) so I don't know. It
allocates the data as user data - probably gets lost!  Not difficult
to fix.

Yes, one can do _very_ cool things with Alien!

This uses the Windows API to iterate over all top-level windows:

require 'alien'
local user = alien.load 'user32.dll'

-- Iterating over all top-level windows.
--  note the abi for both EnumWindows and the callback! EnumWindows is
-- expecting an _integer_ back from the callback, where 1 means 'true' means
-- 'continue going'
function each_hwnd (hwnd,p)
    print(hwnd)
    return 1
end

--- note: not explicit in the docs that callback can take a table...
each_hwnd_callback = alien.callback(each_hwnd,{"int","pointer",abi="stdcall"})

user.EnumWindows:types {"callback","pointer",abi="stdcall"}

user.EnumWindows(each_hwnd_callback,nil)

steve d.