lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Try luaL_error, declared in lauxlib.h:

LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...);

> 
> Hi
>   As you have guessed from the subject I have just started to 
> use Lua, I
> am trying to work out how to stop Lua upon an error, in a custom
> registered function I tried lua_error but that just displayed the last
> item in the stack.
> 
> <code snippet>
> 
> int Add_Object_To_Array( lua_State* luaVM )
> {
>   printf( "Adding object '%s' to array\n", lua_tostring(luaVM, -1) );
> 
>   // Force an error to see if this works
>   lua_pushstring( luaVM, "Add_Object_To_Array :: Failed" );
>   lua_error( luaVM );
> 
>   return 0;
> }
> 
> </code snippet>
> 
> Many thanks
> 
> Paul
>