Hi all, I'm happy to announce the release of Lupa 0.10. http://pypi.python.org/pypi/lupa/0.10 What is Lupa? -------------- Lupa integrates the LuaJIT2 runtime [1] into CPython. It is a rewrite of LunaticPython in Cython. Features --------- * separate Lua runtime states through a LuaRuntime class * frees the GIL and supports threading in separate runtimes when calling into Lua * Python compatible coroutine wrapper for Lua coroutines * proper encoding and decoding of strings (configurable per runtime, UTF-8 by default) * supports Python 2.x and 3.x, potentially starting with Python 2.3 (currently untested) * written for LuaJIT2, as opposed to the Lua interpreter (tested with LuaJIT 2.0.0-beta4) * easy to hack on and extend as it is written in Cython, not C This release features much faster locking of the LuaRuntime instance, especially in the single threaded case. It uses the FastRLock class that I posted as a Python Cookbook recipe [2]. Lupa 0.10 also fixes several issues in error handling cases when calling back into Python from Lua. Updating is recommended. Examples ---------
from lupa import LuaRuntime lua = LuaRuntime()
lua.eval('1+1') 2
lua_func = lua.eval('function(f, n) return f(n) end')
def py_add1(n): return n+1 lua_func(py_add1, 2) 3
lua_code = '''\ ... function(N) ... for i=0,N do ... coroutine.yield( i%2 ) ... end ... end ... ''' lua = LuaRuntime() f = lua.eval(lua_code)
gen = f.coroutine(4) list(enumerate(gen)) [(0, 0), (1, 1), (2, 0), (3, 1), (4, 0)]
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 [3]. The language runtime is extremely small and 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://code.activestate.com/recipes/577336-fast-re-entrant-optimistic-lock-i... [3] http://shootout.alioth.debian.org/u64/performance.php?test=mandelbrot
participants (1)
-
Stefan Behnel