Hi all,
I have rather newbie question.
I in need to replace one character in an gm string.
I've figured out, that I can't simply write in the script:
Code:
a[0]='b';
So I decided to write my own library function putChar(myChar,index):
Code:
static int GM_CDECL gm_putChar(gmThread * a_thread)
{
/* type checking omitted */
GM_CHECK_INT_PARAM(myChar,0);
GM_CHECK_INT_PARAM(index,1);
/* code ripped from gmStringLib.cpp */
const gmVariable * var = a_thread->GetThis();
GM_ASSERT(var->m_type == GM_STRING);
gmStringObject * strObj = (gmStringObject *) GM_OBJECT(var->m_value.m_ref);
const char * str = (const char *) *strObj;
char *s=(char*)str;
int length = strObj->GetLength();
if(index>=length) {
a_thread->GetMachine()->GetLog().LogEntry("ERROR: index exceeds string length.","");
return GM_EXCEPTION;
}
s[index]=(char)myChar;
return GM_OK;
}
When I run this code, the function works fine, character is replaced but
I'm getting error message, which is generated in gmMachine destructor on line 305:
Code:
GM_ASSERT(m_strings.Count() == 0);
The m_strings.Count() is equal to 1 (should be 0).
When I remove this line:
Code:
s[index]=(char)myChar;
from my function, I'm not getting any errors, however I'm not getting the desired result
So my question is: Have I missed something?
Is there an easy way to replace particular character in the gm string?
Thanks,
Mike