lua-users home
lua-l archive

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


This is another of those interesting library functions with
optional arguments not at the end.

([thread,] [message [, level]])

It looks for types thread, string and number.

Now 0 is not a thread, so it knows you did not
supply the first agument. So it looks for a string.
Aha! 0 can be coerced to a string. It's the message!
Let's look for "level': what ugly string is this that
can't be coerced to a number?

If you quickly want a valid thread for testing this,
use debug.getregistry{}[1]. Otherwise, the coroutine
library needs to get in on the act.

You have not possibly been confusing 'thread' and
'level, have you?


2014-11-02 5:54 GMT+02:00 Andrew Starks <andrew.starks@trms.com>:
> The function definition in the reference manual for debug.traceback is:
>
> debug.traceback ([thread,] [message [, level]])
>
> if I do:
> `debug.traceback(0,( msg.mc_reason or ""), 0)`
>
> i get
> -->
> test_error_object.lua:56: bad argument #2 to 'traceback' (number expected,
> got string)
>
> The only way that i can correct this is flip the message and the first
> parameter.
>
> Am i missing something? It looks like ([thread,] [message [, level]]) is
> telling me to put it in the second position...
>
> Also, a quick verification on thread vs. level:
>
> thread is the position to run the traceback argument from. The level is
> where to start the stack trace? I'm having trouble making the second number
> do anything and trouble understanding the problem that they both need to
> solve. (I use level and know what that is for. I just don't know how it
> stands apart thread...
>
> -Andrew