lua-users home
lua-l archive

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

Eric Tetz wrote:
> I built Lua 4.1 for Window CE yesterday, for use on my Pocket PC. 
> Now I want to provide full 
> access the Window API.  I can
> think of a couple major options:
> The first is expose the Win32 API via C code, either by totally 
> by hand or mechanically assisted
> (ToLua).  It seems like exposing even a small percentage of the 
> Window API will require a huge
> amount of C "wrapper" code.  The runtime will be huge.  Parts of 
> the API that I *don't* get around
> to exposing will be totally unavailable to Lua. I don't really 
> like this option.

You tell me! Actually, I am working on a small Windows library wrapping some
API calls (mainly filesystem operations), with an eye on the NTLua library.
I am not ambitious, and I won't go to the GUI side yet (except for a MsgBox
or similar).

> The second is to find a Window GUI library that has already been 
> integrated with Lua, that is
> fairly small and *Unicode aware*, which I can port to Windows CE.

There is a fresh FLTK library. FLTK is Windows compatible, but I don't know
about its CE compatibility. Same for the Tk library and the GTK+ one.
Anybody for a wxWindows library? At least, this one uses native APIs.

> The third is to provide a generic mechanism for prototyping C 
> functions and data structures, and
> directly calling into arbitrary DLLs from Lua. If you wanted a 
> more "Lua-ized" interface to the
> Win32 API, you could write it directly in Lua. This is how the 
> Pocket-PC Forth and Scheme
> interpreters work. I like this option best of all.

Me too, I am thinking about this for quite some time, I even asked some
advice about this here. Search the mailing list archive for FFI to find some
answers. I had no time to dig this problem yet, but I still keep an eye on
similar implementations.

Some URLs for quick investigation:

WDJ's A DynaCall() Function for Win32 (the most promising one, as it is
directly Windows related):

Calling the C world from the Scheme World:

The libffi homepage:

Most libraries uses some assembly language to build a call stack (stacking
the parameters) before calling the functions, one (SiodFFI, I think) simulates
this in pure C.
There is also the problem of callbacks.

> So my questions: has this been done?  Are there fundamental 
> problems/limitations/gotchas?  Is
> there another approach I haven't thought of?

If you are working on this, I would like to hear from your investigations. I
can try and help as time allows.

An approach in the Visual Badic spirit would be nice:
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd
As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Of course, it must be in the Lua spirit and syntax. Probably a table is more

		{ name="hWnd", inout='i', type='long' },
		{ name="wMsg", inout='i', type='long' },
		{ name="wParam", inout='i', type='long' },
		{ name="lParam", inout='io', type='long' },
Or something like this.
And of course, we must find a way to build correctly aligned structures,


Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist

Sent through GMX FreeMail -