Skip to main content

Simple wrapper around LuaJIT

Project description

Lupa

Lupa integrates the LuaJIT2 runtime into CPython. It is a partial rewrite of LunaticPython in Cython. Note that it is currently lacking many features and a lot of testing compared to LunaticPython, so if you need a production-ready Lua integration, use that instead.

The advantages over LunaticPython are:

  • separate Lua runtime states through a LuaRuntime class

  • frees the GIL and supports threading when calling into Lua

  • 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)

  • much easier to hack on and extend as it is written in Cython, not C

Example usage:

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

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

>>> def add1(n): return n+1
>>> func = lua.eval('function(f, n) return f(n) end')
>>> func(add1, 2)
3

Installing lupa

  1. Download and unpack lupa

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

  2. Download LuaJIT2

    http://luajit.org/download.html

  3. Unpack the archive into the lupa base directory, e.g.:

    .../lupa-0.1/LuaJIT-2.0.0-beta4
  4. Build LuaJIT:

    cd LuaJIT-2.0.0-beta4
    make
    cd ..

    If you need specific C compiler flags, pass them to make as follows:

    make CFLAGS="..."
  5. Build lupa:

    python setup.py build

Lupa change log

0.3 (2010-07-13)

  • fix several threading issues

  • safely free the GIL when calling into Lua

0.2 (2010-07-13)

  • propagate Python exceptions through Lua calls

0.1 (2010-07-12)

  • first public release

Project details


Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page