Prev | Current Page 1045 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

For example, here is a simple print replacement function written in Neko to be called from C/C++:
class FunctionPass
{
public static function main()
{
printReplacement( function( str : String ) { neko.Lib.print( str ); } );
}
static var printReplacement = neko.Lib.load( ???utils???, ???PrintReplacement???, 1 );
}
It is the same as writing:
class FunctionPass
{
public static function main()
{
var func = function( str : String )
{
neko.Lib.print( str );
}
printReplacement( func );
}
static var printReplacement = neko.Lib.load( ???utils???, ???PrintReplacement???, 1 );
}
Chapter 20: Extending ha X e with C/C++
569
When coding in haXe, you can choose to pass either class member functions or local functions, as both
should function in the same way. However, it sometimes is found that when passing a class member
function, the reference to the function can get lost, which can cause an application to fail; therefore it
would strongly be recommend using local functions where possible.
Passing Functions from C/C++ to haXe
As with all types in the C/C++ layer that are recognized by Neko, you package functions with an alloc
helper function, in this case ??” you guessed it ??” with alloc_function .


Pages:
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057