26.12.2013, 05:16
pawn Code:
// Many thanks to Y_Less, Nero, RyDeR for teaching me some assembly tips.
// Based on the SYSREQ.C calling method by Zeex - credits to him also.
forward @concat_fix(); @concat_fix()
{
format("", 1, "");
}
stock concat(output[], len, const str[], {Float,_}:...)
{
static
string[512],
start,
end,
args;
args = numargs() * 4;
if (args >= 16)
{
// Load the address of the last static parameter.
#emit ADDR.pri str
#emit STOR.pri start
for (end = start + (args - 12); end > start; end -= 4)
{
// Load the parameter address of this function.
#emit LREF.alt end
// Push it onto the stack.
#emit PUSH.alt
}
// Push the other arguments into "format".
#emit PUSH.S str
#emit PUSH.C 512
#emit PUSH.C string
// Push the number of arguments (in bytes).
#emit PUSH.C args
// Call the function.
#emit SYSREQ.C format
strcat(output, string, len);
// Clear the stack. This is done by loading the previous stack
// level before the function call.
#emit LCTRL 5
#emit SCTRL 4
// Return the function and clean up the local variables.
#emit RETN
}
return strcat(output, str, len);
}
pawn Code:
new str[64];
concat(str, sizeof(str), "I like to eat");
concat(str, sizeof(str), " %s and %s.", "bread", "butter");
print(str);
Code:
I like to eat bread and butter.