TcLux is a Tcl extension which embeds Lua into Tcl. 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 8, 2001: This binding is now able to manage data and callbacks in both directions. Here is a Lua script driving Tk (requires the latest build of Lux):

  #!/usr/bin/env wish

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

  set auto_path [linsert $auto_path 0 .]
  package require tclux

  # Shorthand to run a Lua script with "lux <script>"
  proc lux {script} {
    uplevel 1 [list tclux gs dostring $script]
  }

  # Make Tcl's "eval" command available to Lua as "tcl"
  tclux gsc setglobal tcl eval

  set luxGlobals {}
  lux {
    for i,v in globals() do
      tcl('lappend','luxGlobals',i)
    end
  }
  puts [lsort $luxGlobals]

  proc xbutton {args} {
    puts [llength $args]
    puts $args
  }

  lux {
    -- define a "tk" namespace with a couple of functions
    tk = {
      button =  function (t)
                  local x={'button'}
                  for i=1,getn(t) do
                    tinsert(x,t[i])
                  end
                  for i,v in t do
                    if type(i)=="string" then
                      tinsert(x,'-'..i)
                      tinsert(x,'{'..v..'}')
                    end
                  end
                  call(tcl,x)
                  return t[1]
                end,
      pack = function (t) tinsert(t,1,'pack'); call(tcl,t) end,
    }

    -- now call them
    tk.pack {
      tk.button { '.a'; text='Hello world!', command='bell; exit' }
    }
  }

Explanation: the Lua system, plus a number of libraries, has been built as a dynamically loadable Tcl extension. The result is a single shared library, called tclux.so/tclux.dll - the above demo starts up a Tcl/Tk system, 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