This page is almost the same as Embedding Lua in Tcl - it took about 15 minutes to get a first Python version going, once the Tcl extension existed...


PyLux is a Python extension which embeds Lua into Python. This extension is based on the single-C-file approach described on the Compiling via source includes page. See also Let there be Lux.


Feb 9, 2001: This binding is now able to manage data and callbacks in both directions. Here is a Lua script sending results back to Python:

  #!/usr/bin/env python

  # An example of the Python <-> Lux binding
  # 09/02/2001 jcw@equi4.com

  import pylux

  # Shorthand to run a Lua script with "lux('script')"
  def lux(script):
    pylux.eval("gv", "dostring", script)

  # Shorthand to define a Python proc as callback for Lua
  def luxcb(name,func):
    pylux.eval("gvc", "setglobal", name, func)

  luxGlobals=[]
  luxcb("luxAppend", luxGlobals.append)
  lux("""
    for i,v in globals() do
      luxAppend(i)
    end
  """)
  luxGlobals.sort()
  print luxGlobals

Explanation: the Lua system, plus a number of libraries, has been built as a dynamically loadable Python extension. The result is a single shared library, called pylux.so/pylux.dll - the above demo starts up a Python interpreter, loads Lux, and then switches into Lua scripting.


Last modified
2001-02-10

(216.232.136.19)

Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated