diff --git a/docs/en/api/_sidebar.md b/docs/en/api/_sidebar.md index 822413d..5e8f282 100644 --- a/docs/en/api/_sidebar.md +++ b/docs/en/api/_sidebar.md @@ -5,4 +5,5 @@ 1. [Run](/en/api/run) 1. [Example](/en/api/example) 1. [Library](/en/api/library) + 1. [Primitive](/en/api/primitive) * [Standard library](/en/lib/) \ No newline at end of file diff --git a/docs/en/api/example.md b/docs/en/api/example.md index 959e6d3..68a0940 100644 --- a/docs/en/api/example.md +++ b/docs/en/api/example.md @@ -1,4 +1,4 @@ -# Exemple +# Example ```d // Libraries diff --git a/docs/en/api/primitive.md b/docs/en/api/primitive.md new file mode 100644 index 0000000..6997b0b --- /dev/null +++ b/docs/en/api/primitive.md @@ -0,0 +1,55 @@ +# Primitive + +Primitives added in `GrLibrary` are defined as `void function(GrCall)`. + +```grimoire +void myPrimitive(GrCall call) { + +} +``` + +## Input parameters + +A primitive fetches its parameters with `get` functions from `GrCall`, the index matches the order of the parameters. + +```grimoire +void myPrimitive(GrCall call) { + call.getInt(0) + call.getInt(1); +} +``` + +## Output parameters + +Sams as `get` functions, we returns values with `set` functions from `GrCall`. +We are to call those the same order as its output parameters. + +```grimoire +void myPrimitive(GrCall call) { + call.setInt(12); +} +``` + +## Parameters' types + +We can dynamically know the type of the parameters with `getInType` and `getOutType`. +Those parameters are in a mangled form (use `grUnmangle` to obtain a `GrType`). + +```grimoire +void myPrimitive(GrCall call) { + call.getInType(0); + call.getOutType(0); +} +``` + +## Error handling + +In case of error, we call `raise`. It's recommanded to exit the primitive and to not do any operation after `raise`. + +```grimoire +void myPrimitive(GrCall call) { + if(call.isNull(0)) { + call.raise("Error"); + return; + } +} +``` \ No newline at end of file diff --git a/docs/fr/api/_sidebar.md b/docs/fr/api/_sidebar.md index e9b67e0..51394ed 100644 --- a/docs/fr/api/_sidebar.md +++ b/docs/fr/api/_sidebar.md @@ -5,4 +5,5 @@ 1. [Exécution](/fr/api/run) 1. [Exemple](/fr/api/example) 1. [Bibliothèque](/fr/api/library) + 1. [Primitive](/fr/api/primitive) * [Bibliothèque standard](/fr/lib/) \ No newline at end of file diff --git a/docs/fr/api/primitive.md b/docs/fr/api/primitive.md new file mode 100644 index 0000000..4559e3b --- /dev/null +++ b/docs/fr/api/primitive.md @@ -0,0 +1,55 @@ +# Primitive + +Les primitives ajoutées dans `GrLibrary` se présentent sous la forme `void function(GrCall)`. + +```grimoire +void maPrimitive(GrCall call) { + +} +``` + +## Paramètres d’entrée + +Une primitive récupère ses paramètres avec les fonctions `get` de `GrCall`, l’index correspond à l’ordre des paramètres. + +```grimoire +void maPrimitive(GrCall call) { + call.getInt(0) + call.getInt(1); +} +``` + +## Paramètres de sortie + +Comme les fonctions `get`, on retourne des valeurs avec les fonctions `set` de `GrCall`. +Ces derniers sont à appeler dans l’ordre des paramètres de sortie. + +```grimoire +void maPrimitive(GrCall call) { + call.setInt(12); +} +``` + +## Types des paramètres + +Il est possible de connaître dynamiquement le type des paramètres grâce à `getInType` et `getOutType`. +Ces paramètres sont sous la forme décoré (utilisez `grUnmangle` pour obtenir un `GrType`). + +```grimoire +void maPrimitive(GrCall call) { + call.getInType(0); + call.getOutType(0); +} +``` + +## Gestion d’erreur + +En cas d’erreur, on appelle `raise`. Il est recommandé de quitter la primitive et de ne plus faire d’opération après `raise`. + +```grimoire +void maPrimitive(GrCall call) { + if(call.isNull(0)) { + call.raise("Erreur"); + return; + } +} +``` \ No newline at end of file