lua-users home
lua-l archive

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

Thatcher Ulrich wrote:
> I took the liberty of putting together the bare bones of a Binary
> Module system for Lua 4.0, based on Ignacio's uselib code.  I put up a
> page on the wiki, with a source patch and an interpreter binary for
> Linux (Win32 to come when I get a chance), and a list of ready-to-use
> modules.  (The list of modules consists of one thing at the moment: a
> version of luaSDL, which I've made available before in various forms.)
Hmmmm... not bad... I'm currently trying to get a similar though 
slightly different idea to work. My idea was to be able to say in 

libc = loadlib("c");
malloc = libc:declare("malloc","pointer","int")
-- declare function takes function name, return value and arguments
-- and creates an automagical lua wrapper for the raw C function.
-- using some dirty hacks, I reckon.
-- I'd like to to support "string","pointer","int", and "double" to
begin with.
free = libc:declare("free","void","pointer")
libc.declare = nil;
-- From now on, you cannot declare any new functions from 
-- libc for security reasons.  
block = malloc(1000)
-- Of course having a malloc in lua is pointless for now.

The fine point of this would be that you wouldn't need to 
write a wrappper C library anymore, and that you could call 
many C functions directly. I don't know whether it's possible, 
but I want to give it a shot anyway. I think it might work if
I use some arbitrary limitations on the type and number 
of the arguments a C function can have...

"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer