mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-18 13:49:59 +01:00
Small tweaks to error handling. (#762)
* wren/primitive: Remove duplicated declaration introduced in 9f64c05fa.
* wren/primitive: Allow RETURN_ERROR_FMT to have any number of arguments.
* wren/vm: Remove extra validateApiSlot in wrenGetVariable.
(The slot validation is guaranted by setSlot later in the function.)
* wren/primitive: Use RETURN_ERROR_FMT in validateFn.
This commit is contained in:
@ -23,9 +23,7 @@ static uint32_t validateIndexValue(WrenVM* vm, uint32_t count, double value,
|
|||||||
bool validateFn(WrenVM* vm, Value arg, const char* argName)
|
bool validateFn(WrenVM* vm, Value arg, const char* argName)
|
||||||
{
|
{
|
||||||
if (IS_CLOSURE(arg)) return true;
|
if (IS_CLOSURE(arg)) return true;
|
||||||
|
RETURN_ERROR_FMT("$ must be a function.", argName);
|
||||||
vm->fiber->error = wrenStringFormat(vm, "$ must be a function.", argName);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool validateNum(WrenVM* vm, Value arg, const char* argName)
|
bool validateNum(WrenVM* vm, Value arg, const char* argName)
|
||||||
|
|||||||
@ -43,17 +43,16 @@
|
|||||||
return false; \
|
return false; \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
#define RETURN_ERROR_FMT(msg, arg) \
|
#define RETURN_ERROR_FMT(...) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
vm->fiber->error = wrenStringFormat(vm, msg, arg); \
|
vm->fiber->error = wrenStringFormat(vm, __VA_ARGS__); \
|
||||||
return false; \
|
return false; \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
// Validates that the given [arg] is a function. Returns true if it is. If not,
|
// Validates that the given [arg] is a function. Returns true if it is. If not,
|
||||||
// reports an error and returns false.
|
// reports an error and returns false.
|
||||||
bool validateFn(WrenVM* vm, Value arg, const char* argName);
|
bool validateFn(WrenVM* vm, Value arg, const char* argName);
|
||||||
bool validateFn(WrenVM* vm, Value arg, const char* argName);
|
|
||||||
|
|
||||||
// Validates that the given [arg] is a Num. Returns true if it is. If not,
|
// Validates that the given [arg] is a Num. Returns true if it is. If not,
|
||||||
// reports an error and returns false.
|
// reports an error and returns false.
|
||||||
|
|||||||
@ -1835,8 +1835,7 @@ void wrenGetVariable(WrenVM* vm, const char* module, const char* name,
|
|||||||
{
|
{
|
||||||
ASSERT(module != NULL, "Module cannot be NULL.");
|
ASSERT(module != NULL, "Module cannot be NULL.");
|
||||||
ASSERT(name != NULL, "Variable name cannot be NULL.");
|
ASSERT(name != NULL, "Variable name cannot be NULL.");
|
||||||
validateApiSlot(vm, slot);
|
|
||||||
|
|
||||||
Value moduleName = wrenStringFormat(vm, "$", module);
|
Value moduleName = wrenStringFormat(vm, "$", module);
|
||||||
wrenPushRoot(vm, AS_OBJ(moduleName));
|
wrenPushRoot(vm, AS_OBJ(moduleName));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user