I need to make a const char* system, but there're some problems.
I registering const char like this:
void ConstructConstCharString(string* thisPointer, const char* ptr)
{
new(thisPointer) string(ptr);
}
const char* StringToConstChar(string& str)
{
return str.c_str();
}
RegisterStdString(engine);
engine->RegisterObjectType("charptr", sizeof(const char*), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_PRIMITIVE);
engine->RegisterObjectBehaviour("string", asBEHAVE_CONSTRUCT, "void f(charptr)", asFUNCTION(ConstructConstCharString), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod("string", "charptr opImplConv() const", asFUNCTION(StringToConstChar), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod("string", "charptr opConv() const", asFUNCTION(StringToConstChar), asCALL_CDECL_OBJFIRST);
After performing the conversion, the string is cleared for some reason and as a result, an empty string appears in the print (AngelScript):
void test()
{
print("String1"); // Works
print("String1" + "String2"); // Print empty string
print("String1" + "String2" + "String3"); // Works for some reason
}
print func:
void print(const char* str)
{
std::cout << str << "\n";
}
How to fix this?