What is wxLua ?

wxLua is a Lua scripting language wrapper around the wxWidgets cross-platform C++ GUI library. It consists of two IDE type editors that can edit, debug, and run Lua programs, an executable for running standalone wxLua scripts, a Lua module that may be loaded using require("wx") when using the standard Lua executable, and a library for extending C++ programs with a fast, small, fully embeddable scripting language.

Lua is a small scripting language written in ANSI C that can load and run interpreted scripts as either files or strings. The Lua language is fast, dynamic, and easy to learn. Lua contains a limited number of data types, mainly numbers, booleans, strings, functions, tables, and userdata. Perhaps the most powerful feature of the Lua language is that tables can be used as either numerically indexed arrays or associative arrays that can cross-reference any variable type to any other variable type.

wxLua adds to this small and elegant language nearly all of the functionality of the C++ wxWidgets cross-platform GUI library. This includes the ability to create complex user interface dialogs, file and image manipulation, drawing, network sockets, displaying HTML, and printing to name a few. You can use as much or as little of wxWidgets as you like and C++ developers can trim down the size of the bindings by turning off preprocessor directives.

wxLua can be built against wxWidgets 2.8.x, 2.9.x and Lua versions 5.1, 5.2, and LuaJIT.

The simple wxLua script below creates a wxFrame top-level window, with a menubar, and a statusbar. More examples of wxLua programs can be found in the samples directory of the wxLua distribution.

frame = wx.wxFrame(wx.NULL, wx.wxID_ANY, "wxLua Minimal Demo",
                   wx.wxDefaultPosition, wx.wxSize(450, 450),

-- create a simple file menu
local fileMenu = wx.wxMenu()
fileMenu:Append(wx.wxID_EXIT, "E&xit", "Quit the program")
-- create a simple help menu
local helpMenu = wx.wxMenu()
helpMenu:Append(wx.wxID_ABOUT, "&About",
                "About the wxLua Minimal Application")

-- create a menu bar and append the file and help menus
local menuBar = wx.wxMenuBar()
menuBar:Append(fileMenu, "&File")
menuBar:Append(helpMenu, "&Help")
-- attach the menu bar into the frame

-- create a simple status bar
frame:SetStatusText("Welcome to wxLua.")

-- connect the selection event of the exit menu item to an
-- event handler that closes the window
frame:Connect(wx.wxID_EXIT, wx.wxEVT_COMMAND_MENU_SELECTED,
              function (event) frame:Close(true) end )
-- connect the selection event of the about menu item
frame:Connect(wx.wxID_ABOUT, wx.wxEVT_COMMAND_MENU_SELECTED,
        function (event)
            wx.wxMessageBox('This is the "About" dialog of the Minimal wxLua sample.',
                            "About wxLua",
                            wx.wxOK + wx.wxICON_INFORMATION,
        end )

-- finally, show the frame window

Getting started

  1. Get wxLua:
    • There are binary packages for selected platforms on the download page. You will have to compile wxLua for other platforms as described in the install document.
    • Once installed, the wxLua and wxLuaEdit applications can be used to write, debug, and run your (wx)Lua programs.
  2. Learn Lua:
  3. Learn wxLua:
    • Read the wxLua Manual for a brief introduction to Lua, a description of the wxLua bindings to wxWidgets, the components of wxLua, how to interface to it in C++...
    • Further information can be found on the documentation page.
    • Read and run some of the wxLua samples.