Definition of the links between Scol language and DLL functions » History » Version 1
ModularMix, 10/14/2011 03:53 PM
1 | 1 | ModularMix | h1. Definition of the links between Scol language and DLL functions |
---|---|---|---|
2 | |||
3 | This example shows the possibility to add new functions to Scol language using the integration of plugins written in C/C++ language. |
||
4 | |||
5 | h2. Création d'une fonction "HelloWorld" |
||
6 | Nous allons créer notre première fonction C qui pourra être appelée à partir du langage Scol. |
||
7 | Cette fonction, permettra d'afficher un petit message d'accueil "Hello World" qui apparaitra dans la console Scol. |
||
8 | Commencez par écrire la fonction C. Notez la signature de la fonction, elle doit prendre comme paramètre un objet '''mmachine''', et retourner un entier. |
||
9 | |||
10 | Notez également la fonction de l'API Scol '''MMechostr'''. Cette fonction prend deux paramètre, le niveau de log ('''MSKFOO''', '''MSKRUNTIME''', '''MSKWARNING''', '''MSKTRACE''' ou '''MSKDEBUG'''), et le message à loguer en second argument. |
||
11 | |||
12 | Enfin, notez la fonction '''MMSet''', qui permet comme nous l'avons déjà vu d'assigner une valeur au premier élément de la pile Scol (en l'occurrence un entier de valeur 0), celle-ci correspondant '''à la valeur de retour de la fonction Scol''', conformément au prototype Scol attendu ('''fun [ ] I''', soit une fonction sans aucun paramètre, et retournant un entier). |
||
13 | <code> |
||
14 | /*! @ingroup group1 |
||
15 | * \brief _HelloWorld : Log a "Hello World" message in the console |
||
16 | * |
||
17 | * <b>Prototype:</b> fun [] I |
||
18 | * |
||
19 | * \return I : 0 in all cases. |
||
20 | **/ |
||
21 | int _HelloWorld(mmachine m) |
||
22 | { |
||
23 | // Show the message |
||
24 | MMechostr(MSKRUNTIME, "Hello World!"); |
||
25 | |||
26 | // Scol return value. |
||
27 | MMset(m,0,0); |
||
28 | |||
29 | return 0; |
||
30 | } |
||
31 | </code> |