I'm struggling to understand how to use the ref add-on both in script and across the script/c++ interface.
I understand the basics of pointers but am having a hard time wrapping my head around how angelscript interfaces with c++ for function calls.
Problem one: error when using refs with string.
script code
string str1;
string str2;
ref @strref1;
str1 = "hello world";
@strref1 = str1;
print(str1);
str6 = cast<string>(strref1);
When compiling the script, this returns: ERR : Illegal target type for reference cast.
Why can't a ref be case to to a string?
Problem two: problems passing refs to c++
declared a function:
//C++
void test_pass_ref(CScriptHandle *&arg){
void *ptr;
ptr = arg->GetRef();
cout << "ptr is " << ptr << endl;
cout<< "str passed is " << static_cast <char*> (ptr) << endl;
cout<< "exit"<<endl;
}
//registered like this
r = engine->RegisterGlobalFunction("void test_pass_ref(ref@ &in)", asFUNCTION(test_pass_ref), asCALL_CDECL);
Attempting to use it like this in a script
string str5;
ref @strref1;
str5 = "hello world";
@strref1 = str5;
test_pass_ref(strref1);
Get the following output:
ptr is 0
str passed is Segmentation fault
Why does GetRef() not return the pointer of the string? Any help in understanding would be appreciated.