🎉 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

Started by
4 comments, last by WitchLord 16 years, 10 months ago
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 ?
Advertisement
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)
***rofl
This function is declared in script, but not in the app
What do you mean by 'fault'?

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

Exception
I can't reproduce the problem. I tested the following script:

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?

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

This topic is closed to new replies.

Advertisement