-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout d’une page de doc pour les primitives
- Loading branch information
Showing
5 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Exemple | ||
# Example | ||
|
||
```d | ||
// Libraries | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
``` |