Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Oct 04, 2007 2:43 am   

[2.04 Lua] Error messages
 
error("wow")

The error given is wow", notice the extra ". Not really a serious bug, just weird. Mainly, I'm posting to ask if we can have more detailed Lua error reports, including the stack traceback. It'd be very useful for debugging.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Oct 04, 2007 5:14 pm   
 
From what I have seen of the Lua error interface, it's pretty simple. It just raises a normal Delphi exception with an error message. Right now I parse the error message before displaying it and that's probably what is causing the extra quote. But I have no idea how to get stuff like a stack traceback. If you have info on how to do that, let me know.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Oct 04, 2007 5:48 pm   
 
I'd never looked into this before, so forgive me if I make a total hash of it :P Looks like lua_Debug, lua_getinfo and lua_getstack are what you're after.

I had a sneaky peek in the iLua code because its error handler produces errors very similar to those in normal Lua. I already had an alias that used loadstring() to run whatever code you entered, and so I used it to run error("lol!"), and this was the error report:

Code:
[ILua]: [string "error("lol!")"]:1: lol!
Traceback:
 [C]:-1: in function 'error'
 [string "error("lol!")"]:1: in main chunk
 playground.lua:53: in function '?'
 core.lua:108: in a Lua function
Error in the 'client_aliases' callback.


The numbers between the colons are line numbers in the files in question. Here's the code that generates the error:

Code:
static int ilua_errorhandler( lua_State *L )
{
   lua_Debug ar;
   const char *errmsg;
   char where[256];
   int level;
   
   errmsg = lua_tostring( L, -1 );
   if ( !errmsg )
     errmsg = "Untrapped error from Lua";
   
   clientff( "\r\n" ILUA_PREF "%s\r\n" C_0, errmsg );
   
   clientff( C_R "Traceback:\r\n" C_0 );
   level = 1;
   while ( lua_getstack( L, level++, &ar ) )
     {
        lua_getinfo( L, "nSl", &ar );
       
        if ( ar.name )
          snprintf( where, 256, "in function '%s'", ar.name);
        else if ( ar.what[0] == 'm' )
          snprintf( where, 256, "in main chunk" );
        else if ( ar.what[0] == 't' )
          snprintf( where, 256, "in a tail call (I forgot the function)" );
        else if ( ar.what[0] == 'C' )
          snprintf( where, 256, "in a C function" );
        else
          snprintf( where, 256, "in a Lua function" );
       
        clientff( C_W " %s" C_0 ":" C_G "%d" C_0 ": %s\r\n", ar.short_src, ar.currentline, where );
     }
   
   return 1;
}

I'm not sure how functions can be integrated to handle when Lua raises an error; hopefully you've read about that.

PS. The C_W, C_0 etc variables are colours. C_W is bold white, C_w is normal white, C_0 is off, etc etc.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net