Skip to content

Commit

Permalink
Ajout d’une page de doc pour les primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
Enalye committed Mar 6, 2023
1 parent 8dc6dff commit 0b1061e
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/en/api/_sidebar.md
Expand Up @@ -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/)
2 changes: 1 addition & 1 deletion docs/en/api/example.md
@@ -1,4 +1,4 @@
# Exemple
# Example

```d
// Libraries
Expand Down
55 changes: 55 additions & 0 deletions 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;
}
}
```
1 change: 1 addition & 0 deletions docs/fr/api/_sidebar.md
Expand Up @@ -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/)
55 changes: 55 additions & 0 deletions 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;
}
}
```

0 comments on commit 0b1061e

Please sign in to comment.