lua-users home
lua-l archive

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


>if(lua_dofile(L, fileName) != 0){
>
>  lua_Debug ar;
>
>  lua_getstack (L, 1, &ar);
>
>  printf("Error\nLine: %d\nText: %s", 
>	ar.linedefined,
>	ar.source); 
>}
>I just can't get the right values of linedefine or currentline or 
>source!

You need to call lua_getinfo after lua_getstack. But in Lua 4.0, the error
will be reported automatically by lua_dofile. If you want to intercept this,
redefine _ERRORMESSAGE to your own function. See liolib.c or lbaselib.c for
a simpler solution that may be what you want.

In Lua 5.0, all this has been simplified and both lua_load and lua_pcall
leave a nicely formatted errormessage on the stack in case of errors.
--lhf