[ANN] Lupa 0.17 released - Lua in Python

S

Stefan Behnel

Hi all,

I am happy to announce the release of Lupa 0.17, Lua in Python.

http://pypi.python.org/pypi/lupa/0.17

Have fun,

Stefan


What is Lupa?
--------------

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

This release features iteration support for Python objects in Lua.

Changes in this release:

0.17 (2010-11-05)

* new helper function "python.enumerate()" in Lua that returns a Lua
iterator for a Python object and adds the 0-based index to each item.
* new helper function "python.iterex()" in Lua that returns a Lua
iterator for a Python object and unpacks any tuples that the
iterator yields into separate Lua arguments.
* new helper function "python.iter()" in Lua that returns a Lua
iterator for a Python object.
* resurrected the "python.as_function()" helper function for Lua code
as it can be needed in cases where Lua cannot determine how to run a
Python function.

[1] LuaJIT2: http://luajit.org/


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
* iteration support for Python objects in Lua and Lua objects in Python
* 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-beta5)
* easy to hack on and extend as it is written in Cython, not C


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 for computational code. 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, the Lua ecosystem lacks many of the batteries that Python readily
includes, either directly in its standard library or as third party
packages. This makes real-world Lua applications harder to write than
equivalent Python applications. Lua is therefore not commonly used as
primary language for large applications, but it makes for a fast,
high-level and resource-friendly backup language inside of Python when raw
speed is required and the edit-compile-run cycle of binary extension
modules is too heavy and too static for agile development or hot-deployment.

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.


Examples
---------
.... function(N)
.... for i=0,N do
.... coroutine.yield( i%2 )
.... end
.... end
.... '''[(0, 0), (1, 1), (2, 0), (3, 1), (4, 0)]

.... function(L)
.... for item in python.iter(L) do
.... if item == 3 then return 1 end
.... end
.... return 0
.... end
.... '''
f = lua.eval(lua_code)
f([1,2,3]) 1
f([1,2])
0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top