LuaWindow, a small lua package for text display in OpenViBE

When using the Lua Stimulator box (or any kind of Lua script actually), it could be useful to present some information to the user in some way. This box allows to send messages to the Log Manager thanks to the box:log function but there is no way to get that to the OpenViBE operator when it comes to useful information for the ongoing experiment. In such situation, it could be handy to have a new GTK window where the script can print some text. This is exactly the purpose of the luawindow package I have done recently. Nothing ambitious right now, just basics to have this feature of printing text in a window.

The luawindow sample script running

Installing luawindow :

  • Download and uncompress the luawindow source archive in the openvibe-externals folder (the code is licensed under the Lesser GPL v2 or any later version).
  • Edit your init_env_command script and add the OpenViBE_external_luawindow project to the build order.
  • Compile OpenViBE.
  • Congratulations !

Using luawindow :

In order to use luawindow, you have to tell lua where the package is. This could be done the same way as in the luasocket tutorial or you could add the following lines at the beginning of your script :

package.cpath = package.cpath..“;../lib/lib?”
luawindow = require(“luawindow”)

You’ll then be able to call the functions of the API :

luawindow.initialize(width, height)

This function creates the luawindow and initializes its size to width x height pixels. If you don’t call this function or omit the width or height parameters, a window with a default size will be created when needed (that is when you’ll print some text)


This function closes the already initialized window.

luawindow.print(id, x, y, text)

This function prints some text in the window. If the window is not created, it gets created after this call. The id parameter allows to partially refresh the displayed information, that is if the same id was used previously, the corresponding text is removed and replaced by the new text. The x and y specifies the position of the text in the window in pixels. The text parameter contains the text to display in the window. It should be noted that any pango markup tag could be used !


This function removes any existing text in the window.

Sample script :

The following script demonstrates how luawindow could be used :

package.cpath = package.cpath..“;../lib/lib?”
luawindow = require(“luawindow”)

function initialize(box)
  — optional
  luawindow.initialize(640, 128)

function uninitialize(box)
  — optional

function process(box)
  while true do
      0, 0, 0,
      “it works !”)
      1, 0, 32,
      “current time is “

Closing words :

This Lua package can also be used in non OpenViBE applications but the Lua script should be running in a GTK mainloop !
As I said previously, this Lua package could probably be extended much more. But it for sure fits the needs it’s been designed for so far… So it’s obviously time to share it :)

Comments are closed.