🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
FAULT when passing reference parameter as a constant to function
string CheckNumber(string &nNum)
{
return nNum;
}
CheckNumber("2"); - fault, but should be a compile time syntax error
I'm very ashamed, but Is there any hope for a quick fix ?
How are you declaring the function? You don't want to be returning a string by value.
asCScriptString *CheckNumber(asCScriptString &nNum)
{
std::string &checkStr = nNum.buffer;
// do logic here
asCScriptString *retStr = new asCScriptString;
retStr.buffer = checkStr;
return retStr;
}
engine->RegisterGlobalFunction("string &CheckNumber(string ∈)", asFUNCTION(CheckNumber), asCALL_CDECL);
That should get you closer (note: untested)
asCScriptString *CheckNumber(asCScriptString &nNum)
{
std::string &checkStr = nNum.buffer;
// do logic here
asCScriptString *retStr = new asCScriptString;
retStr.buffer = checkStr;
return retStr;
}
engine->RegisterGlobalFunction("string &CheckNumber(string ∈)", asFUNCTION(CheckNumber), asCALL_CDECL);
That should get you closer (note: untested)
I can't reproduce the problem. I tested the following script:
The script code compiles and executes without any problem.
Can you send me a small sample that reproduces the problem?
static const char *script8 ="void test() \n""{ \n"" Func(\"test\"); \n""} \n""string Func(string & str) \n""{ \n"" return str; \n""} \n";
The script code compiles and executes without any problem.
Can you send me a small sample that reproduces the problem?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement