Allow to create tasks with symbol name in addition to numeric ID

This commit is contained in:
Konstantin Nazarov 2024-09-28 20:09:22 +01:00
parent 4945a86c2e
commit 69e2403c93
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22

View file

@ -378,12 +378,19 @@ Result<StackFrame> stdlib_task(const StackFrame& stack) {
if (size == 0) return ERROR(ArgumentCountMismatch);
Value task_id = TRY(params_array.get(0));
if (!task_id.is<Int64>()) return ERROR(TypeMismatch);
uint64_t num_task_id = 0;
if (task_id.is<Int64>()) {
num_task_id = (uint64_t)task_id.to<Int64>()->value();
} else if (task_id.is<Symbol>()) {
num_task_id = (uint64_t)TRY(get_stdlib_task(*task_id.to<Symbol>()));
} else {
return ERROR(TypeMismatch);
}
Value task_params = TRY(params_array.slice(1, size));
auto val = Value(TRY(Task::create((uint64_t)task_id.to<Int64>()->value(),
*task_params.to<Array>())));
auto val = Value(TRY(Task::create(num_task_id, *task_params.to<Array>())));
auto res = TRY(stack.set(0, val));