The gplus module supplied with Glu provides additional functions that make it easier to write scripts. The module consists of a set of .lua files stored in the Modules/gplus directory (see init.lua for the implementation details). The best way to learn how to use gplus is to look at some of the scripts supplied with Glu.

Here's a description of each function available after a script calls local gp = require "gplus":

gp.int(x)
  Return the integer part of the given floating point number. (The result matches Python's int function.)

gp.round(x)
  Return the rounded integer for the given floating point number. (The result matches Python's round function.)

gp.min(a)
  Return the minimum value in the given array.

gp.max(a)
  Return the maximum value in the given array.

gp.equal(a1, a2)
  Return true if the given arrays have the same values.

gp.split(s, delimiter)
  Split the given string into one or more substrings that are separated by the given delimiter. If the delimiter is not supplied then it defaults to a space. (The result matches Python's split function.)

gp.validint(s)
  Return true if the given string is a valid integer.

gp.timerstart(name)
  Start a named timer.

gp.timersave(name)
  Save the current elapsed time of the named timer.

gp.timervalue(name)
  Return the last saved value of the named timer in milliseconds.

gp.timervalueall(precision)
  Return a formatted string with a list of all saved timer names and their values in milliseconds, then reset all timers. The given precision specifies the number of digits after a decimal point.

gp.timerresetall()
  Reset all of the timers.

gp.trace(msg)
  Pass this into xpcall so a runtime error will generate a nicely formatted stack trace.

Most of the supplied Lua scripts use gplus, but it isn't compulsory. You might prefer to create your own module for use in the scripts you write. If a script calls require "foo" then Glu will look for foo.lua in the same directory as the script, then it looks for foo/init.lua. If a script calls require "foo.bar" then Glu looks for foo/bar.lua. If none of those files exist in the script's directory then Glu will look in the supplied Modules directory, so scripts can always use the gplus module no matter where they are located.

The gplus directory also contains strict.lua. When writing a big, complicated script it's a good idea to add the line require "gplus.strict" near the top. This will catch any undeclared global variables. When the script is working just remove or comment out that line.