From ce844dc1101087f8ba2cfa5ca21afe1d164cf033 Mon Sep 17 00:00:00 2001 From: Inversion <40722286+NeoInversion@users.noreply.github.com> Date: Wed, 10 Feb 2021 21:48:41 -0800 Subject: [PATCH] Added error to the base library --- src/cbaselib.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/cbaselib.c b/src/cbaselib.c index 7776836..5a5e7d8 100644 --- a/src/cbaselib.c +++ b/src/cbaselib.c @@ -110,6 +110,22 @@ int cosmoB_loadstring(CState *state, int nargs, CValue *args) { return 2; // , or } +int cosmoB_error(CState *state, int nargs, CValue *args) { + if (nargs < 1) { + cosmoV_error(state, "error() expected 1 argument, got %d!", nargs); + return 0; + } + + if (!IS_STRING(args[0])) { + cosmoV_typeError(state, "error()", "", "%s", cosmoV_typeStr(args[0])); + return 0; + } + + cosmoV_error(state, "%s", cosmoO_readCString(cosmoV_readString(args[0]))); + + return 0; +} + void cosmoB_loadLibrary(CState *state) { const char *identifiers[] = { "print", @@ -118,7 +134,8 @@ void cosmoB_loadLibrary(CState *state) { "pcall", "tonumber", "tostring", - "loadstring" + "loadstring", + "error" }; CosmoCFunction baseLib[] = { @@ -128,7 +145,8 @@ void cosmoB_loadLibrary(CState *state) { cosmoB_pcall, cosmoB_tonumber, cosmoB_tostring, - cosmoB_loadstring + cosmoB_loadstring, + cosmoB_error }; int i;