The luasup
package contians support routines for use when
interacting with and embedded Lua interpreter. In particular, it eases
argument checking.
Many of the routines will return an error message via a user
defined function (with a typedef of SLua_ErrFunc
:
typedef void(*SLua_ErrFunc)( char *fmt, ... );
Generally the function is passed in to the luasup
function.
It is not required to return. luasup
functions will return
an error status if it does, however.
Typically, an error function will use the lua_error
routine
so that the line number at which the error ocurred will be printed.
Here's a simple one:
/* --8<--8<--8<--8<-- * * Copyright (C) 2006 Smithsonian Astrophysical Observatory * * This file is part of luasup * * luasup is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * luasup is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301, USA * * -->8-->8-->8-->8-- */ #include <stdarg.h> #include <lua.h> void errfunc( const char *fmt, ... ) { va_list ap; char buffer[1024]; va_start( ap, fmt ); vsprintf( buffer, fmt, ap ); va_end( ap ); /* this doesn't return */ lua_error( buffer ); }