mirror of
https://github.com/CPunch/Cosmo.git
synced 2026-02-10 04:30:03 +00:00
Added CObjError, cosmoV_throw(), pcall(), and cosmoV_printError()
Errors are now handled very differently, parser errors and VM errors are now treated the same. When cosmoV_error is called, cosmoV_throw is also called, which formats the error object and sets the panic state. state->error now points to the latest CObjError when state->panic is true. To get a nice formatted Objection message, use cosmoV_printError() and pass the state->error. pcall() was added to the standard base library. When called, the first argument passed is called with the subsequent arguments given. If the call completed successfully, `true`,`nil` is returned. However when an error occurs during the call, `false`,`<error>` is returned. Simply print the `<error>` to retrieve the error string.
This commit is contained in:
@@ -40,8 +40,12 @@ static void interpret(CState *state, const char *script, const char *mod) {
|
||||
COSMOVMRESULT res = cosmoV_call(state, 0, 0); // 0 args being passed, 0 results expected
|
||||
|
||||
if (res == COSMOVM_RUNTIME_ERR)
|
||||
state->panic = false; // so our repl isn't broken
|
||||
cosmoV_printError(state, state->error);
|
||||
} else {
|
||||
cosmoV_printError(state, state->error);
|
||||
}
|
||||
|
||||
state->panic = false; // so our repl isn't broken
|
||||
}
|
||||
|
||||
static void repl() {
|
||||
|
||||
Reference in New Issue
Block a user