Prev | Current Page 1036 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

Lib.haxeToNeko( ???Hello, World!??? ) );
This now has the benefit of being a valid type, which is not null, yet it is also not a value that can be
processed as such, except to have its reference exchanged or duplicated. This proves perfect for using
an abstract value, as the only purpose it will serve is to pass back to further C/C++ functions for
processing.
Here is a simple, but complete, example of an abstract in use:
#include ???neko.h???
#include < stdio.h >
#include < stdlib.h >
DEFINE_KIND( k_str_struct );
struct _strings {
char *str1;
char *str2;
};
typedef struct _strings strings;
value GetAbstract( value str )
{
val_check( str, string );
strings* strStruct = (strings*)malloc(sizeof(strings));
strStruct- > str1 = ???Howdy???;
strStruct- > str2 = val_string( str );
return alloc_abstract( k_str_struct, strStruct );
}
value PrintAbstract( value abstract )
{
val_check_kind( abstract, k_str_struct );
strings* strStruct = (strings*)val_data( abstract );
printf( ???%s %s???, strStruct- > str1, strStruct- > str2 );
return val_null;
}
DEFINE_PRIM( GetAbstract, 1 );
DEFINE_PRIM( PrintAbstract, 1 );
And the haXe class to manage this library:
class AbstractHandler
{
static var __a : Void;
public static function main()
{
Chapter 20: Extending ha X e with C/C++
565
__a = getAbstract( neko.


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