Is the format of a BlitzMAX String the same as a C String? How can I return a BlitzMAX String from a C function?
returning a String
BlitzMax Forums/BlitzMax Programming/returning a String BlitzMax strings are 16bit.
Returning a string from C will probably be pretty hard. Check out blitz.mod and whatever .c file has string somewhere in the title. Perhaps there is a function there that can help you.
I'm guessing you would return something like a pointer to two integers (reference counter and length) followed by a pointer to a block of 16 bit unicode charachters.
I'm guessing you would return something like a pointer to two integers (reference counter and length) followed by a pointer to a block of 16 bit unicode charachters.
...Must learn to read properly...
You can either return null terminated char pointers by externing the functions using functionname$z() style or include some BRL C module code that gives you direct access to BlitzMax string handling mechanics.
testcstrings.bmx
testcstrings.bmx
Import "testc.c" Extern "C" Function cstringfunction$() Function czstringfunction$z() End Extern Print cstringfunction() Print czstringfunction()testc.c
// return fully constructed BlitzMax string version #include <brl.mod/blitz.mod/blitz_string.h> BBString *cstringfunction() { return bbStringFromCString("hello world\n"); } // return null terminated char pointer version char *zcstringfunction() { return "hello zworld\n"; }