Method lfun::_sprintf()

Method _sprintf

string _sprintf(int conversion_type, mapping(string:int)|void params)


Sprintf callback.

This method is called by sprintf() to print objects. If it is not present, printing of the object will not be supported for any conversion-type except for the %O-conversion-type, which will output "object".

Parameter conversion_type

One of:


Signed binary integer.


Signed decimal integer.


Unsigned decimal integer.


Signed octal integer.


Lowercase signed hexadecimal integer.


Uppercase signed hexadecimal integer.


Character. If a fieldsize has been specified this will output the low-order bytes of the integer in network byte order.




Heuristically chosen representation of float.


Like %g, but uses uppercase E for exponent.


Exponential notation float.


Like %e, but uses uppercase E for exponent.




Any value (debug style).


Type of the argument.

Parameter params

Conversion parameters. The following parameters may be supplied:

"precision" : int


"width" : int

Field width.

"flag_left" : int(1)

Indicates that the output should be left-aligned.

"indent" : int

Indentation level in %O-mode.


Is expected to return a string describing the object formatted according to conversion_type.


_sprintf() is currently not called for the following conversion-types:


Binary IEEE representation of float (%4F gives single precision, %8F gives double precision.)


This function might be called at odd times, e.g. before lfun::create has been called or when an error has occurred. The reason is typically that it gets called when a backtrace is being formatted to report an error. It should therefore be very robust and not make any assumptions about its own internal state, at least not when conversion_type is 'O'.


It's assumed that this function is side-effect free.

See also