This Neko function is then managed by the Neko garbage collector, so it is only fully
released sometime after a request to free the data has been made and, thus remains at your disposal for
as long as you need it.
The storage medium is a pointer to a value struct, or value* . As this is static, you ??™ ll need to declare this
outside of any C/C++ function scope:
value* function_callback = NULL;
Part III: Extending the Possibilities
572
When you assign a function value to this store, you will need to allocate memory to it using the
alloc_root Neko helper function. This also ensures that it is registered with the Neko garbage collector,
making the function safe:
value set_callback( value f ) {
val_check_function(f,1); // checks that f has 1 argument
if( function_callback == NULL )
function_callback = alloc_root(1); // allocate memory
*function_callback = f; // assign the function to the stores address
}
As the static function store variable is a pointer, you can essentially store multiple functions using this
pointer as you would with an Array.
Pages:
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065