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 some features and a lot of testing compared to LunaticPython, so it does yet make for a production-ready Lua integration.

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

Advantages over LunaticPython

  • separate Lua runtime states through a LuaRuntime class

  • frees the GIL and supports threading in separate runtimes 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

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. 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 400KB 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.

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.4 (2010-07-14)

  • attribute read access on Lua objects, e.g. to read Lua table values from Python

  • str() on Lua objects

  • include .hg repository in source downloads

  • added missing files to source distribution

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lupa-0.4.tar.gz (48.2 kB view details)

Uploaded Source

File details

Details for the file lupa-0.4.tar.gz.

File metadata

  • Download URL: lupa-0.4.tar.gz
  • Upload date:
  • Size: 48.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lupa-0.4.tar.gz
Algorithm Hash digest
SHA256 2d086e715e0f0378251d0efb3569ae4237810ebc2d51bb141df991e8ecb65c13
MD5 30a8d2a94f5bf661fa489507bc4bb330
BLAKE2b-256 6582d37c1774c17d0963af30e440af93206a1b23d6534523914c4d88035e80ca

See more details on using hashes here.

Supported by

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