lua-users home
lua-l archive

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


have you seen the new python ctypes library?  it's a cross-platform library to call c functions directly in python without needing to create an extension module or do the marshalling yourself.
http://starship.python.net/crew/theller/ctypes.html

wouldn't this be possible in lua?  or maybe a better question... is this something that lua programmers want?  to me, when i hear the words "glue language" it means that i can directly call a shared language.   anyways, it's not the end of the world for me that loadlib can only load a lua extension library.  i was just curious.

thanks,

bryan


-----Original Message-----
From: Philippe Lhoste [mailto:PhiLho@gmx.net] 
Sent: Wednesday, May 21, 2003 2:00 AM
To: lua@bazar2.conectiva.com.br
Subject: Re: some lua questions


> >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!