Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stock FormatQuery(Format[], va_args<>)
- {
- new
- out[512];
- va_format(out, sizeof(out), Format, va_start<1>);
- return out;
- }
- //--- used like this
- print( FormatQuery("%s - %s AW %d %d %d %f", "ABC", "yo", 1, 2, 3 , 5.5) );
- //=================
- #define BYTES_PER_CELL 4
- // HUGE credit to ZeeX for finally cracking this problem:
- // [url=http://forum.sa-mp.com/index.php?topic=79810.msg901721#msg901721]http://forum.sa-mp.com/index.php?topic=79810.msg901721#msg901721[/url]
- stock FormatQuery2( fstring[], {Float, _}:...)
- {
- // This is the number of parameters which are not variable that are passed
- // to this function (i.e. the number of named parameters).
- static const
- STATIC_ARGS = 3;
- // Get the number of variable arguments.
- new
- n = (numargs() - STATIC_ARGS) * BYTES_PER_CELL;
- if(n)
- {
- new
- message[144],
- arg_start,
- arg_end;
- // Load the real address of the last static parameter. Do this by
- // loading the address of the last known static parameter and then
- // adding the value of [FRM].
- #emit CONST.alt fstring
- #emit LCTRL 5
- #emit ADD
- #emit STOR.S.pri arg_start
- // Load the address of the last variable parameter. Do this by adding
- // the number of variable parameters on the value just loaded.
- #emit LOAD.S.alt n
- #emit ADD
- #emit STOR.S.pri arg_end
- // Push the variable arguments. This is done by loading the value of
- // each one in reverse order and pushing them. I'd love to be able to
- // rewrite this to use the values of pri and alt for comparison,
- // instead of having to constantly load and reload two variables.
- do
- {
- #emit LOAD.I
- #emit PUSH.pri
- arg_end -= BYTES_PER_CELL;
- #emit LOAD.S.pri arg_end
- }
- while(arg_end > arg_start);
- // Push the static format parameters.
- #emit PUSH.S fstring
- #emit PUSH.C 144
- #emit PUSH.ADR message
- // Now push the number of arguments passed to format, including both
- // static and variable ones and call the function.
- n += BYTES_PER_CELL * 3;
- #emit PUSH.S n
- #emit SYSREQ.C format
- // Remove all data, including the return value, from the stack.
- n += BYTES_PER_CELL;
- #emit LCTRL 4
- #emit LOAD.S.alt n
- #emit ADD
- #emit SCTRL 4
- return print(message); // here D:\...pwn(390) : error 079: inconsistent return types (array & non-array)
- }
- return fstring;
- }
Advertisement
Add Comment
Please, Sign In to add comment