C functions that return c strings

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

teamonkey(Posted 2005) [#1]
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?


Todd(Posted 2005) [#2]
Hi,

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

TheString$ = String.FromCString(getBuffer())




skidracer(Posted 2005) [#3]
or easier still:

Extern
Function GetBuffer$z()
End Function


Kanati(Posted 2005) [#4]
not sure I understand the syntax on that skid...

Function GetBuffer$z()


What's the z ??


teamonkey(Posted 2005) [#5]
@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?