C functions that return c strings

BlitzMax Forums/BlitzMax Beginners Area/C functions that return c strings

Is there any elegant way of converting a c char* to a bmx String on the fly?

For example,
C:
char buffer[100];

char* getBuffer(void) {
    return buffer;
}


BMX:
Extern
    Function getBuffer:String()
End Extern


Obviously you can't do that. How would I go about getting something that acted like a "Function getBuffer:String()" from that C code?

Hi,

Try this:
Extern
	Function getBuffer:Byte Ptr()
End Extern

TheString$ = String.FromCString(getBuffer())



or easier still:

Extern
Function GetBuffer$z()
End Function

not sure I understand the syntax on that skid...

Function GetBuffer$z()


What's the z ??

@Todd
Yeah, but I'd like it to be all wrapped up and tidy. I'd like it so that in Blitz the function name you call is exactly the same as the C function, but the Blitz version returns a string, if that's at all possible.

@skidracer
Eh?