Advertisement

asBEHAVE_CONSTRUCT with custom POD string type requires 'const'

Started by January 17, 2025 11:35 AM
1 comment, last by WitchLord 1 week, 6 days ago

I use RegisterStringFactory to register my own string type, basically something similar to std::string_view.

So AS will see them as “const string_view” after creation.

The type is registerd with asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<T>().

Now usually I pass my strings to functions by copy.

RegisterObjectMethod("obj", "void SetName(string_view)", asMETHOD(obj, SetName, asCALL_THISCALL);

->

obj.SetName("Jonny"); // works fine

So even though the string constant “Jonny” is treated as “const string_view”, this works.

EXCEPT in constrctors.

RegisterObjectBehaviour("obj", asBEHAVE_CONSTRUCT, "void f(string_view)", asFUNCTION(obj_ConstructView), asCALL_CDECL_OBJFIRST);

obj b("Jonny"); // DESON'T work

I get the error message, that there is no overload that takes “const string_view”. So if I change the behavior to this declaration, I get it to work:

RegisterObjectBehaviour("obj", asBEHAVE_CONSTRUCT, "void f(const string_view)", asFUNCTION(obj_ConstructView), asCALL_CDECL_OBJFIRST);

I really just add the “const” in the declaration.

Could this be an oversight? As far as I understand it, the constructor should also work without the const, since string_view should just be copied anyway.

Indeed. This looks like a bug in the compiler.

I'll investigate and have it fixed as soon as possible.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement