I'm trying to get an array<string> instance from a RegExp class I implemented on the C++ side and registered with the AS engine.
The AS side:
RegExp re;
int n = re.findall(response, matches);
Error message:
RegExp::findall(): Found -404223764 matches.
---
The script ended with an exception.
func: string getClientId()
modl:
sect: script
line: 32
desc: Index out of bounds
Method registration:
engine->RegisterObjectMethod("RegExp",
"int findall(string &in, array<string> &inout)",
asMETHODPR(RegExp, findall,
(const std::string &, CScriptArray* &), int),
asCALL_THISCALL);
Method:
int RegExp::findall(const std::string &subject, CScriptArray* &matches) {
if (!regexp) { return 0; }
Poco::RegularExpression::MatchVec matchesVector;
std::string::size_type offset = 0;
while (regexp->match(subject, offset, matchesVector)) {
std::string substr = subject.substr(matchesVector[1].offset, matchesVector[1].length);
matches->InsertLast(&substr);
offset = matchesVector[0].offset + matchesVector[0].length;
}
int n = matches->GetSize();
std::cout << "RegExp::findall(): Found " << n << " matches." << std::endl;
return n;
}
I have tried the method registration both with &out and &inout without any difference. Trying to create a new CScriptArray object in the C++ method leads to an exception and crash to debugger.
What is the correct way to do this?