format_to
int format_to(var self, int pos, const char* fmt, ...);
int format_to_va(var self, int pos, const char* fmt, va_list va);
Write a formatted string fmt
to the object self
at position pos
.
format_from
int format_from(var self, int pos, const char* fmt, ...);
int format_from_va(var self, int pos, const char* fmt, va_list va);
Read a formatted string fmt
from the object self
at position pos
.
Usage
/* printf("Hello my name is %s, I'm %i\n", "Dan", 23); */
format_to($(File, stdout), 0,
"Hello my name is %s, I'm %i\n", "Dan", 23);
Read or Write with Format String
Format abstracts the class of operations such as scanf
, sprintf
and fprintf
with matching semantics. It provides general printf
and scanf
functionality for several different types objects in a uniform way. This class is essentially an in-between class, used by the Show
class to read and write output.
It is important to note that the semantics of these operations match printf
and not the newly defined Show
class. For example it is perfectly valid to pass a C int
to these functions, while the println
function from Show
must be passed only var
objects.
struct Format {
int (*format_to)(var,int,const char*,va_list);
int (*format_from)(var,int,const char*,va_list);
};