In Lua, a function may return any number of values. tolua uses this feature to simulate values passed by reference. If a function parameter is specified as a pointer to or reference of a basic type or a pointer to or reference of a pointer to an user defined type, tolua accepts the corresponding type as input and returns, besides the conventional function returned value, if any, the updated parameter value.
For instance, consider a C function that swaps two values:
void swap (double* x, double* y);
or
void swap (double& x, double& y);
If such a function is declared in the package file, tolua binds it as a function receiving two numbers as input and returning two numbers. So, a valid Lua code would be:
x,y = swap(x,y)
If the input values are not used, the use of default parameter value allows calling the function from Lua without specifying them:
void getBox (double* xmin=0, double* xmax=0, double* ymin=0, double* ymax=0);
In Lua:
xmin, xmax, ymin, ymax = getBox()
With user defined types, we would have for instance:
void update (Point** p);
or
void update (Point*& p);