Take a look again at the HelloWorld example. This time, the C/C++ function will accept a string to be
displayed:
#include ???neko.h???
#include < stdio.h >
value PrintHelloWorld( value str )
{
val_check( str, string );
printf( val_string( str ) );
return val_null;
}
DEFINE_PRIM( PrintHelloWorld, 1 );
Chapter 20: Extending ha X e with C/C++
559
And again, with the modified haXe class:
class PrintHelloWorld
{
public static function main()
{
hello( neko.Lib.haxeToNeko( ???Hello, World!??? ) );
}
static var hello = neko.Lib.load( ???hello???, ???PrintHelloWorld???, 1 );
}
As you can see within the C/C++ code, the parameter str is passed to the function val_string() .
This function is necessary to extract the data contained inside the value struct. There is one of these
functions for each value type supported by the Neko Virtual Machine, and each are aptly named.
Table 20 - 1 details each function in turn.
Preparing Data for Transit from ha X e to C/C++
If you look closely at the haXe class in the preceding example, the string value being passed to the
C/C++ function also required wrapping inside a helper function, neko.
Pages:
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037