Update External Libraries

2026-01-22 21:25:30 +11:00
parent 2349124f6f
commit 7b1b3750cd

@@ -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 <groundext.h>
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 <groundext.h>
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 <groundext.h>
#include <stdio.h>
#include <string.h>
@@ -51,7 +51,7 @@ void ground_init(GroundScope* scope) {
```
For our example, it would look something like this:
```c
#include "groundext.h"
#include <groundext.h>
#include <stdio.h>
#include <string.h>
@@ -90,3 +90,13 @@ 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.
## 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.