mirror of
https://github.com/janet-lang/janet
synced 2024-12-29 01:40:26 +00:00
Allow 1 argument call of debug/stacktrace
Since fibers now track the last value signaled.
This commit is contained in:
parent
96262e7d87
commit
bd2e335063
@ -299,9 +299,11 @@ static Janet cfun_debug_stack(int32_t argc, Janet *argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_debug_stacktrace(int32_t argc, Janet *argv) {
|
static Janet cfun_debug_stacktrace(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 2);
|
janet_arity(argc, 1, 2);
|
||||||
JanetFiber *fiber = janet_getfiber(argv, 0);
|
JanetFiber *fiber = janet_getfiber(argv, 0);
|
||||||
janet_stacktrace(fiber, argv[1]);
|
Janet x = argc == 1 ? janet_wrap_nil() : argv[1];
|
||||||
|
x = janet_checktype(x, JANET_NIL) ? fiber->last_value : x;
|
||||||
|
janet_stacktrace(fiber, x);
|
||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,10 +379,10 @@ static const JanetReg debug_cfuns[] = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"debug/stacktrace", cfun_debug_stacktrace,
|
"debug/stacktrace", cfun_debug_stacktrace,
|
||||||
JDOC("(debug/stacktrace fiber err)\n\n"
|
JDOC("(debug/stacktrace fiber &opt err)\n\n"
|
||||||
"Prints a nice looking stacktrace for a fiber. The error message "
|
"Prints a nice looking stacktrace for a fiber. Can optionally provide "
|
||||||
"err must be passed to the function as fiber's do not keep track of "
|
"an error value to print the stack trace with. If `err` is nil or not "
|
||||||
"the last error they have thrown. Returns the fiber.")
|
"provided, will default to `(fiber/last-value fiber)`. Returns the fiber.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"debug/lineage", cfun_debug_lineage,
|
"debug/lineage", cfun_debug_lineage,
|
||||||
|
@ -1065,8 +1065,12 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) {
|
|||||||
janet_status_names[sub_status]);
|
janet_status_names[sub_status]);
|
||||||
}
|
}
|
||||||
fiber->child = f;
|
fiber->child = f;
|
||||||
|
if (janet_checktype(stack[B], JANET_NIL)) {
|
||||||
|
vm_return((int) sub_status, f->last_value);
|
||||||
|
} else {
|
||||||
vm_return((int) sub_status, stack[B]);
|
vm_return((int) sub_status, stack[B]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
VM_OP(JOP_CANCEL) {
|
VM_OP(JOP_CANCEL) {
|
||||||
Janet retreg;
|
Janet retreg;
|
||||||
|
Loading…
Reference in New Issue
Block a user