lua-users home
lua-l archive

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


> >1. it's very clear from the documentation how to call lua from c and
> >register callbacks for lua to call.  but i don't see how to have lua
> >load and call functions in an external shared library that isn't part of
> >the host.  for example, how do i call a win32 function in the msvcrt.dll
> >or expat.dll?  is this possible?  or do i have to proxy every call
> >through a callback in the host?
> 
> In Lua 5.0 use loadlib.

No. AFAIK, loadlib can only be used to load a DLL of Lua functions, ie. with
the "int F(lua_State *L)" 
signature.

To call a native Win32 function, you must either wrap it in such function,
by hand or using a tool like toLua 
or GLuaX, or use a FFI (foreign function interface) allowing to call any
function by pushing parameters in 
the stack, calling the function, and retrieving result on the stack.

This topic has been invoqued several time on this mailing list, including by
myself, and useful links has 
been given.

The problem is that you can hardly make a portable FFI, because of the
differences between calling 
conventions of languages or compilers. There is a method in pure C, but
quite limited. Most of the time, 
you must use some lines of assembly to manipulate the stack.

HTH.

-- 
--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://jove.prohosting.com/~philho/
--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage!