[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Lua 4.0 and loadlib
- From: "Dirk Ringe" <dirk.ringe@...>
- Date: Wed, 21 Nov 2001 15:37:57 +0100
About generic script bindings to C++ (not plain C!) functions, there is an
articel in the game development community from Scott Bilas about it's FuBi
(=Function Binding) stuff. This article was presented at the GDC 2001 and it
the book Game Programming Gems. I am not that familiar with this topic so I
don't know if it is a good resource for binding to generic DLL's. But it is
worth to take a look:
[mailto:firstname.lastname@example.org]On Behalf Of Philippe Lhoste
Sent: Wednesday, November 21, 2001 3:15 PM
To: Multiple recipients of list
Subject: Re: Lua 4.0 and loadlib
> Short update on my progress:
> It compiled ok, the lua.exe interpreter works.
> I tried the following script:
> lib, errmsg = loadlib( "expat" )
> if lib then
> callfromlib( lib, "XML_ParserCreate" )
> error( errmsg )
> which gets the lib loaded ok, but when I get to actually doing
> it crashes with an application error, a memory violation
> when I do this with a 'bogus' functionname (a name that doesn't exist in
> lib) I get an normal lua error 'error: The specified procedure could not
> found', as would be expected...
> so far, still digging,
> > Also I just found a newer version of name loadlib (loadlib.c,v 1.2
> > 2001/01/11 17:59:38 ana) here: http://angg.twu.net/lua-4.0/src/libdllua/
> > which I could actually compile without changes!!
> > I still need to test and verify if it actually work, but so far I'm all
Actually, Lua's loadlibrary is originally made to allow calling void f(void)
functions only, ie. functions that don't need arguments (XML_ParserCreate
expects one parameter) and don't return a value.
The modified version found in CGILua is modified to accomodate Lua 4.0
calling conventions, ie. it gives the current Lua stack as parameter.
It is mostly made to allow calling functions like lua_xxxlibopen(L), ie.
DLLs of Lua libraries.
And that's all... What you really want is a FFI, aka. Foreign Function
Interface, ie. a way to call any function with any number and type of
in a Windows DLL (in your case).
AFAIK, there is not yet such a thing for Windows. There is a FFI for Gnome.
I am trying to find some time to work on this Windows' FFI thingy, using
SIOD FFI, since it does its call in pure C. Other FFI libraries, like
libffi or DynaCall (see archives of this ML, names from memory, which is bad
;-) uses assembly code to manipulate the call and return stacks.
There are also a lot of issues, like defining a good Lua interface to
describe structures and functions, managing the return values, etc.
Anyway, if I even get a viable result, I will of course post it here. And if
somebody beats me on this release, all the better :-)
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
Sent through GMX FreeMail - http://www.gmx.net