04.08.2013, 16:29
Here is the problem:
Somewhere in gamemode:
It seems that something is screwed up. If you pass more than one argument to that function it does not properly return an array and
it isn't the problem with code in my concat function, it can be:
And the problem still exists.
But, I've found a soultion:
And now:
Everything is working fine, but it isn't global solution.
You have to calculate how many bytes were pushed into stack.
Another example for str being local variable:
This issue is caused by compiler. It doesn't handle more than one argument in these kind of functions, so you have to do it by yourself.
pawn Код:
stock concat(...)
{
static str[256];
new it, NumArgs = numargs();
for (new idx, ch; it < (sizeof(str) - 1) && idx < NumArgs; idx++)
{
new index;
while ( it < (sizeof(str) - 1) && ( ch = getarg( idx, index++ ) ) != 0 )
str[it++] = ch;
}
str[it] = 0;
return str;
}
pawn Код:
print(concat("Hello!"));
//output: Hello!
pawn Код:
print(concat("Hello!", " My name is ", "bartekdvd."));
//output: (null)
it isn't the problem with code in my concat function, it can be:
pawn Код:
stock concat(...)
{
static string[] = "abcd";
return string;
}
But, I've found a soultion:
pawn Код:
stock FIX_concat(...)
{
static str[256];
new it, NumArgs = numargs();
for (new idx, ch; it < (sizeof(str) - 1) && idx < NumArgs; idx++)
{
new index;
while ( it < (sizeof(str) - 1) && ( ch = getarg( idx, index++ ) ) != 0 )
str[it++] = ch;
}
str[it] = 0;
#emit LOAD.S.PRI 0x8
#emit ADDR.ALT 0xC
#emit ADD
#emit LOAD.I
#emit MOVE.ALT
#emit CONST.PRI str
#emit MOVS 0x400
#emit STACK 0x8
#emit RETN
return str;
}
pawn Код:
print(FIX_concat("Hello!", " My name is ", "bartekdvd."));
//output: Hello! My name is bartekdvd.
You have to calculate how many bytes were pushed into stack.
Another example for str being local variable:
pawn Код:
stock FIX_S_concat(...)
{
new str[256];
new it, NumArgs = numargs();
for (new idx, ch; it < (sizeof(str) - 1) && idx < NumArgs; idx++)
{
new index;
while ( it < (sizeof(str) - 1) && ( ch = getarg( idx, index++ ) ) != 0 )
str[it++] = ch;
}
str[it] = 0;
#emit LOAD.S.PRI 0x8
#emit ADDR.ALT 0xC
#emit ADD
#emit LOAD.I
#emit MOVE.ALT
#emit ADDR.PRI str
#emit MOVS 0x400
#emit STACK 0x408
#emit RETN
return str;
}