Contact: zeng  @      Last update: 10 May 2011

Embedding ZeScript in wxWindows

The wxWidnows library is one of the best open source libraries for developing cross-platform user interface. Its API for event handling makes it very easy to embed a scripting language for creating widgets.

Upon startup, the widget program "zsw.exe" creates a main frame window and then executes the ZeScript file "zsw.zs". The script should first obtain the main frame and then add menubar, toolbar, or controls in it. For instance,

frame = wxframe();

a = frame.menubar("&File", "&Item-1\tCtrl-I", "_", "I&tem-2\tCtrl-t",
                  ">", "Submenu", "&Sub-1\tCtrl-S", "S&ub-2\tCtrl-u",
                  "<", "It&em-3\tCtrl-e");

b = frame.menubar("&Help", "&About\tCtrl-A");

na = size(a);
nb = size(b);
for (i = 0; i < nb; i++) a[na+i] = b[i];

frame = wxcast(frame);
frame.push("event_handler", "menu", a);

function event_handler(id)
    s = " " + id;

You may have noticed that in the reference the function push() is registered to the base window; therefore if we want to push a event-handling callback function to handle menu event in the main frame, we have to cast the frame from the top window type to the base window type.