lua-users home
lua-l archive

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


> From: Bryan Weingarten
> 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

It looks interesting but its hardly "transparent". It just looks like
you're shifting the binding layer from C to Python, which albeit may be
less work and probably is more portable, but slower.


> wouldn't this be possible in lua?  or maybe a better

I believe libFFI exists somewhere and there are struct libraries for Lua
so it is possible. I'd ask the LuaCheia team, a module to do this could
cut down on C maintainance, but then you still need binding code.


--Nick

------------------

nick, 

this doesn't look too bad at all.  copied from the ctypes tutorial,
here's how to call time and printf.  i believe the binding layer is
still in c.  so the actual call and c_double() probably still are all c
code, so it should be very fast.  it might not be entirely "transparent"
as you say, but it's definitely "translucent" and the python coder
doesn't have to worry about a binding layer which is a big win.  there
is a lot of noise in the python news group about ctypes and it's already
very popular.  maybe lua can model after this.

>>> from ctypes import *
>>> print cdll.msvcrt.time(None)
1048777320

>>> from ctypes import *
>>> printf = cdll.msvcrt.printf
>>> printf("An int %d, a double %f\n", 1234, c_double(3.14))
Integer 1234, double 3.140000104934
>>>


bryan