Method lfun::_sprintf()


Method _sprintf

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

Description

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:

'b'

Signed binary integer.

'd'

Signed decimal integer.

'u'

Unsigned decimal integer.

'o'

Signed octal integer.

'x'

Lowercase signed hexadecimal integer.

'X'

Uppercase signed hexadecimal integer.

'c'

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

'f'

Float.

'g'

Heuristically chosen representation of float.

'G'

Like %g, but uses uppercase E for exponent.

'e'

Exponential notation float.

'E'

Like %e, but uses uppercase E for exponent.

's'

String.

'O'

Any value (debug style).

't'

Type of the argument.

Parameter params

Conversion parameters. The following parameters may be supplied:

"precision" : int

Precision.

"width" : int

Field width.

"flag_left" : int(1..1)

Indicates that the output should be left-aligned.

"indent" : int

Indentation level in %O-mode.

Returns

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

Note

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

'F'

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

Note

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'.

Note

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

See also

sprintf()