[ANN] Lupa 0.9 - Lua in Python

Stefan Behnel stefan_ml at behnel.de
Fri Jul 23 23:12:53 CEST 2010

Hi all,

I'm happy to announce the release of Lupa 0.9.


What is Lupa?

Lupa integrates the LuaJIT2 runtime [1] into CPython.  It is a rewrite of 
LunaticPython in Cython with a couple of additional features.

The major new feature in this release is coroutine support for Lua 
functions that follows the Python coroutine protocol (next/send).


 >>> from lupa import LuaRuntime
 >>> lua = LuaRuntime()

 >>> lua.eval('1+1')

 >>> lua_func = lua.eval('function(f, n) return f(n) end')

 >>> def py_add1(n): return n+1
 >>> lua_func(py_add1, 2)

 >>> lua_func = lua.eval('''
...   function(N)
...       for i=0,N do coroutine.yield(i%2) end
...   end
... ''')
 >>> co = lua_func.coroutine(3)
 >>> list(co)

Why use it?

It complements Python very well.  Lua is a language as dynamic as
Python, but LuaJIT compiles it to very fast machine code, sometimes
faster than many other compiled languages [2].  The language runtime is
extremely small, has a small memory footprint and is carefully designed for 
embedding.  The complete binary module of Lupa, including a statically 
linked LuaJIT2 runtime, is only some 500KB on a 64 bit machine.

However, Lua code is harder to write than Python code as the language
lacks most of the batteries that Python includes.  Writing large
programs in Lua is rather futile, but it provides a perfect backup
language when raw speed is more important than simplicity.

Lupa is a very fast and thin wrapper around LuaJIT.  It makes it easy
to write dynamic Lua code that accompanies dynamic Python code by
switching between the two languages at runtime, based on the tradeoff
between simplicity and speed.

[1] LuaJIT2: http://luajit.org/
[2] http://shootout.alioth.debian.org/u64/performance.php?test=mandelbrot

More information about the Python-announce-list mailing list