I’m try to translate some C code to Julia, but I’m a little stumped with how to tackle this. First, there is this macro as well as two global variables:
// Shared buffer for variadic text
static char* fc_buffer = NULL;
static unsigned int fc_buffer_size = 1024;
#define FC_EXTRACT_VARARGS(buffer, start_args) \
{ \
va_list lst; \
va_start(lst, start_args); \
vsnprintf(buffer, fc_buffer_size, start_args, lst); \
va_end(lst); \
}
and here is an example of it being used:
FC_Rect FC_Draw(FC_Font* font, FC_Target* dest, float x, float y, const char* formatted_text, ...)
{
if(formatted_text == NULL || font == NULL)
return FC_MakeRect(x, y, 0, 0);
FC_EXTRACT_VARARGS(fc_buffer, formatted_text);
set_color_for_all_caches(font, font->default_color);
return FC_RenderLeft(font, dest, x, y, FC_MakeScale(1,1), fc_buffer);
}
It’s from a C file called “SDL_FontCache.c”, and the function is supposed to allow you to draw formated text on the screen (a graphical printf). For example:
FC_Draw(font, renderer, 0, 0, "This is %s.\n It works.", "example text");
I think what is throwing me is (1) I’m unfamiliar with vsnprintf(), (2) I’m unfamiliar with the whole va_list macro stuff. I’m sure there is a simple answer using a varargs function and the @sprintf macro, but I’m stumped.