From 7b1b3750cdb368b41deab802797014e74fad3580 Mon Sep 17 00:00:00 2001 From: Maxwell Date: Thu, 22 Jan 2026 21:25:30 +1100 Subject: [PATCH] Update External Libraries --- External-Libraries.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/External-Libraries.md b/External-Libraries.md index 8afaab1..6d0e169 100644 --- a/External-Libraries.md +++ b/External-Libraries.md @@ -10,7 +10,7 @@ Our ground syntax will be `call !Example_GreetUser $username &greet` ## C code First, import `groundext.h`. Then, start a new function. For our example, we will call it `greetUser`. ```c -#include "groundext.h" +#include GroundValue greetUser(GroundScope* scope, List args) { @@ -19,7 +19,7 @@ GroundValue greetUser(GroundScope* scope, List args) { To create our function, we need to access our arguments. Use `args.values[idx]` for an argument. `args.values[0]` is the first argument, `args.values[1]` is the second argument, etc. ```c -#include "groundext.h" +#include GroundValue greetUser(GroundScope* scope, List args) { const char* argument = args.values[0].data.stringVal; @@ -30,7 +30,7 @@ The function expects us to return a `GroundValue`. After we create our string, w All together, we can write our function like this: ```c -#include "groundext.h" +#include #include #include @@ -51,7 +51,7 @@ void ground_init(GroundScope* scope) { ``` For our example, it would look something like this: ```c -#include "groundext.h" +#include #include #include @@ -89,4 +89,14 @@ println $out # Prints "Hello, DiamondNether90!" ## Best practices - Namespacing is done with an underscore (`libName_FunctionName`). -- Use camelCase for the library name and PascalCase for the function name. \ No newline at end of file +- Use camelCase for the library name and PascalCase for the function name. + +## Throwing Errors + +If your library encounters an error during execution, you can throw an error with the ERROR() macro. The syntax is this: + +```c +ERROR("Friendly description of how the error happened", "ErrorCode"); +``` + +The `ErrorCode` is what users of your library will be able to catch errors with. If the error is not caught, the friendly description will be shown to the user. \ No newline at end of file