I am trying to get a char * equivalent from Haxe and I have found in the past that CastCharStar.fromString generally works. However, I’m not sure when this changed, but in some version of Haxe/hxcpp the generated code is now const HX_CHAR * even when using the above code.
Here is an example:
var value = "";
folder = CastCharStar.fromString(value);
You would expect this to work considering folder is type CastCharStar but it doesn’t. Instead, I get the following compilation error: 'initializing': cannot convert from 'const HX_CHAR *' to 'char *'
Well, I’m trying to use the linc_imgui library and I am having trouble with the function call for inputText. I looked at the extern definition and it was saying it required Array<Char> and then takes the length of the first part of the Array which made no sense to me. I also couldn’t find a way to convert a Haxe string to a Array<Char> without making wrapper functions to convert them. I tried that, but it didn’t work as I thought it wouldn’t.
I changed the function definition to take a CastCharStar because that’s the only class I know that takes the char * equivalent and has the functionality to convert from a Haxe string to itself. I’ve looked at the definition for Star<Char> but that’s a typedef to the type itself.
Just so you know, the InputText function takes a char * as it’s a reference, and ConstCharStar will therefore not work.
I would be more than interested to see if there is a way to make Array<Char> work properly with native Haxe strings and I will revert all the changes I made to the library.
I don’t think, that externs a written properly. At least it is not worked for me too with Array<cpp.Char>. Nothing showed, nothing can be inputted.
Here is a workaround which can be implemented as an extern or as some kind of wrapper:
Hello, library author here!
The intended use is to pre-allocate an array for use with the imgui text input controls. For example this:
var buf : Array<cpp.Char> = [ for (i in 0...16) 0x0 ];
Will create an array of 16 null characters which will allow you to type up to 16 characters into the text box. You would then pass buf to the input text function and it should work.
For my own projects I have a little text buffer class which handles converting to and from haxe strings and character arrays.
Maybe a little more info on the top in this issue comment.