returning a String

BlitzMax Forums/BlitzMax Programming/returning a String

Nigel Brown(Posted 2005) [#1]
Is the format of a BlitzMAX String the same as a C String? How can I return a BlitzMAX String from a C function?


Tibit(Posted 2005) [#2]
BlitzMax strings are 16bit.


Bot Builder(Posted 2005) [#3]
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.


Yan(Posted 2005) [#4]
...Must learn to read properly...


skidracer(Posted 2005) [#5]
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
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";
}