Prev | Current Page 1058 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

The following is a simple example of
how failure might be used:
if ( error != NULL ) failure( ???Several errors have occurred??? );
Part III: Extending the Possibilities
574
This example would halt the Neko script, while printing Several errors have occurred in the command
console.
bfailure()
The bfailure function performs the same feat as failure , with the exception that, rather than a string
constant, it accepts a Neko buffer value.
Neko buffers are created with alloc_buffer , which as you might expect, allocates enough memory
for a buffer and registers the structure with the garbage collector. Once created, you can pass a Neko
string value to the buffer using val_buffer or a constant string ??” a value of type char* ??” using
buffer_append . At any time, you can convert the buffer to a Neko string using buffer_to_string :
value str1 = alloc_string( ???2 + 2??? );
value str2 = alloc_string( ???4??? );
buffer buf = alloc_buffer( ???The sum ??? );
val_buffer( buf, str1 );
buffer_append( buf, ??? = ??? );
val_buffer( buf, str2 );
return buffer_to_string( buf );
val_print()
val_print is a very useful function that could save you large amounts of hair pulling and certainly lots
of time wasted writing needless code.


Pages:
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070