3 ms·
If you're just doing Lua to get to C it's much easier to call to C directly from Python.
by jules 16y ago
If you're just doing Lua to get to C it's much easier to call to C directly from Python.
- silentbicycle 16y agoYou can call C directly from Lua too, with alien (http://alien.luaforge.net/ http://alien.luaforge.net/). Generating the bindings really isn't that hard, though.
- nitrogen 16y agoBefore I read up on how Alien works, I have to guess: it uses dlsym() (or the Windows equivalent) to find a function by name, and has a number of prototypical function pointer types which it uses to call the symbol returned by dlsym(), based on the number and types of parameters passed in Lua. When calling C++ it could even check the parameter types, provided they know how name mangling works for whatever platform the run on. Now to see how close I was...
- jgalvez 16y agoNot to get to C, but simply to get somewhat better speed, /somewhere/ between Python and C, which is where Lua stands.
- weeksie 16y agoStrange, I haven't done a lot with Python but I've built a pretty big system in Lua and its FFI is incredibly nice, the nicest I've ever used, in fact.
- jules 16y agoAh, I misunderstood. I thought he was intending to call C from Python by calling Lua from Python and then C from Lua. Still, calling C from Python is trivial with ctypes. Most people do not realize how easy it is: from ctypes import CDLL libc = CDLL("libc.so.6") libc.printf("boo")
- olliesaunders 16y agoIt would surprise me if this was true because C interop and embeddability was part of the reason for the creation of Lua. I don't believe you could say the same was true for Python. Wikipedia: "Lua is intended to be embedded into other applications, and accordingly it provides a robust, easy to use C API. The API is divided into two parts: the Lua core and the Lua auxiliary library."