Prev | Current Page 1033 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Chapter 20: Extending ha X e with C/C++
563
Each of these functions leaves the original value intact, meaning copies of the data are made where
necessary. To see the Hello World example returning a value, the following could be possible:
#include ???neko.h???
#include < stdio.h >
value PrintHelloWorld( value str )
{
val_check( str, string );
printf( val_string( str ) );
return alloc_string( ???Hello to you, too, Neko!??? );
}
DEFINE_PRIM( PrintHelloWorld, 1 );
Abstract Types
One of the most likely reasons for creating a Neko library will be to provide bindings for an existing
library in C/C++ offering features that Neko doesn ??™ t currently support. When dealing with such
libraries, it will become likely that passing standard string or number type values between C/C++ and
Neko will be insufficient for your needs. A probable reason for this is that a data type used by the library
that requires persisting within Neko is not of a type that Neko will recognize.
Allocating Abstract Values
Be it a C struct or other such data, you can deal with these occurrences by wrapping a pointer to the
value within a value struct and labeling the value as an abstract type.


Pages:
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045