Here is an example of how a native function can access a 'Buf' object passed from a component function:
Cell MyNativeFcn_print(SedonaVM* vm, Cell* params)
{
Cell retval;
uint8_t* s = params[0].aval;
/*
* Format of the passed 'Buf' object seems to be:
* s[0..1] uint16_t Unknown; probably a 'handle'.
* s[2..3] uint16_t Number of bytes.
* s[4..n] uint8_t[] Array of bytes.
*
* Data is LITTLE ENDIAN.
*
* In the case of a string, the last character is '0', so
* you can do a printf on s[4]. Note that '123' shows up as
* an array of length 4, with '0' as the 4th byte.
*/
// Print the string.
printf("%s\n" , &s[4]);
// And return.
retval.ival = 0;
return retval;
}
Bob Wirka