Update syntax.md

This commit is contained in:
2025-09-20 20:44:37 +10:00
parent d7b0c4d818
commit 0a962b569a

View File

@@ -252,7 +252,7 @@ Some symbols specific to this category:
* `!function`: A function reference
* `-type`: A type reference. Can be one of the following: "-string", "-char", "-int", "-double", "-bool"
* `-type`: A type reference. Can be one of the following: "-string", "-char", "-int", "-double", "-bool", or a custom struct (see "Custom data structures" below)
#### fun
@@ -286,9 +286,36 @@ Calls a function, with all the arguments in the argument list. The return value
Usage: `call !function &var
### Custom Data Structures
#### struct
Begins creation of a custom data structure, which can contain values and functions. Similar to a class or struct in other programming languages.
In between the `struct` and `endstruct` lines, you can insert the following:
* `init` statements, to initialize values
* `fun`/`endfun` statements, to add member functions to the struct
When calling a function from inside a struct, all members of the struct are avaliable to read from and write to.
Usage: `struct -structName`
#### endstruct
Ends creation of a custom data structure.
Usage: `endstruct`
#### init
Initialises a variable with the default value of a type.
Usage: `init &var -type`
### Interacting with Libraries
#### use (Experimental, please report bugs!)
#### use
Attempts to import another Ground program. Gets inserted wherever the use statement is. Any code (including code outside function declarations) will be executed. All functions from the library will be given a prefix, meaning functions will be registered as `!libName:functionName`.
@@ -296,7 +323,7 @@ Note: Ground will check the directory where the program is being run from when t
Usage: `use $stringvalue`
#### extern (Experimental, please report bugs!)
#### extern
Attempts to import a shared object library written for Ground. All functions in the external library will be usable with `call`. All functions from the library will be given a prefix, meaning functions will be registered as `!libName:functionName`.