Hi! I have an function which returns a std::string as an out parameter, and this is causing me some problems. I am using 2.1.0 WIP4. The string registration is taken more or less directly from the code provided with the library
std::string StringFactory (asUINT length, const char *s)
{
return std::string (s);
}
void ConstructString (std::string *thisPointer)
{
new(thisPointer) std::string ();
}
void DestructString (std::string *thisPointer)
{
thisPointer->~string ();
}
std::string &AssignString (const std::string &other, std::string *thisPointer)
{
new(thisPointer) std::string (other);
return *thisPointer;
}
engine->RegisterObjectType ("String", sizeof (std::string), asOBJ_CLASS_CDA);
engine->RegisterStringFactory ("String", asFUNCTION(StringFactory), asCALL_CDECL);
engine->RegisterObjectBehaviour ("String", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructString), asCALL_CDECL_OBJLAST);
engine->RegisterObjectBehaviour ("String", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructString), asCALL_CDECL_OBJLAST);
engine->RegisterObjectBehaviour ("String", asBEHAVE_ASSIGNMENT, "String &f(String &in)", asFUNCTION(AssignString), asCALL_CDECL_OBJLAST);
In fact there are some more parts to it, but i don't think they should have any effect for this (if you suspect so, ask and i provide the rest of it). Then i have my method returning the reference
static bool Get (PropType &value, Property *property)
{
value = "hi";
return true;
}
engine->RegisterObjectType ("Property", sizeof (Property), asOBJ_CLASS);
engine->RegisterObjectMethod ("Property", "void Get (String &out)", asFUNCTION(GetString), asCALL_CDECL_OBJLAST);
The problem arises when i have code like this (in a method in my AS-script)
String outval;
property.Get (outval);
The method is called, and after that it tries to use my AssignString, but the first parameter is totaly bogus (0). Anyone else experiencing this? Is this a bug which can be confirmed, or am I doing something totaly wrong? Last piece of info, here is the output from the offending line (outputed by AS_DEBUG-compilation) (ok, in fact the line is a bit more complicated.. it gets the property handle on same line, but that does work so I did not include that above)
178 37 * SUSPEND
182 37 * PSF 4
188 38 * ALLOC 9, -23
200 37 * RDSF4 3
206 38 * RDSF4 4
212 39 * CALLSYS -25 (String& ?(String&))
220 37 * SET4 0x4 (i:4, f:5.60519e-045)
228 38 * GETOBJREF 0
234 38 * STR 2 (l:5 s:"Title")
240 40 * CALLSYS -22 (String ?(int, const uint8&))
248 38 * STOREOBJ 4
254 38 * SET4 0x4 (i:4, f:5.60519e-045)
262 39 * GETOBJ 0
268 39 * RDSF4 0
274 40 * CHKREF
278 40 * CALLSYS -148 (Entity@ CastToEntity())
286 39 * STOREOBJ 5
292 39 * RDSF4 5
298 40 * CHKREF
302 40 * CALLSYS -79 (Property@ GetProperty(String))
310 38 * STOREOBJ 6
316 38 * PSF 6
322 39 * PSF 5
328 40 * FREE 1
336 39 * RD4
340 39 * CHKREF
344 39 * CALLSYS -44 (void Get(String&))
352 37 * SET4 0x4 (i:4, f:5.60519e-045)
360 38 * RDSF4 3
366 39 * GETOBJREF 1
372 39 * CALLSYS -25 (String& ?(String&))
380 37 * PSF 4
386 38 * FREE 9
394 37 * PSF 6
400 38 * FREE 13
BR Mårten Svanfeldt