umka-lang
umka-lang copied to clipboard
format function that just returns a string
The language provides sprintf but it requires a whole load of tax work to actually use because of it's similarity to C. With Umka a better formatting function can be made that simply returns an already formatted string to you.
The API is format("%d", 123)
What is the exact difference between sprintf() and format()? Returning the string as the function result rather than an output parameter?
sprintf requires you to allocate the string yourself and set the max cap.
buf := str(make([]char, 256))
sprintf(buf, "%d", i)
ui.putButton(buf)
this bit of code can be condensed into
ui.putButton(format("%d", i))
Couldn't the current sprintf just be reworked?
i second that ^
@marekmaskarinec @skejeton My current idea is to change the sprintf signature from
fn sprintf(buf, format: str, a1: T1, a2: T2...): int
to
fn sprintf(format: str, a1: T1, a2: T2...): str
which is obviously incompatible with the existing code. Are you ready for this change?