void math_max (void)
{
int i=1; /* number of arguments */
double d, dmax;
lua_Object o;
/* the function must get at least one argument */
if ((o = lua_getparam(i++)) == LUA_NOOBJECT)
lua_error ("too few arguments to function `max'");
/* and this argument must be a number */
if (!lua_isnumber(o))
lua_error ("incorrect argument to function `max'");
dmax = lua_getnumber (o);
/* loops until there is no more arguments */
while ((o = lua_getparam(i++)) != LUA_NOOBJECT)
{
if (!lua_isnumber(o))
lua_error ("incorrect argument to function `max'");
d = lua_getnumber (o);
if (d > dmax) dmax = d;
}
/* push the result to be returned */
lua_pushnumber (dmax);
}