Files
fx/test/dynamic-printf.c
T

37 lines
737 B
C
Raw Normal View History

2026-05-25 17:35:09 +01:00
#include <fx/cstr.h>
2026-05-04 16:37:06 +01:00
#include <fx/reflection/function.h>
2026-05-05 21:16:56 +01:00
#include <fx/string.h>
2026-05-04 16:37:06 +01:00
#include <fx/value.h>
#include <inttypes.h>
#include <stdio.h>
int main(int argc, const char **argv)
{
2026-05-25 17:35:09 +01:00
fx_type_id arg_types[] = {
FX_TYPE_CSTR,
2026-05-04 16:37:06 +01:00
};
fx_function *func = fx_function_create(
2026-05-04 22:54:02 +01:00
"printf",
2026-05-04 16:37:06 +01:00
FX_FUNCTION_F_VARARG,
(fx_function_impl)printf,
arg_types,
1,
2026-05-25 17:35:09 +01:00
FX_TYPE_INT);
2026-05-04 16:37:06 +01:00
2026-05-25 17:35:09 +01:00
fx_string *fmt = fx_string_create_from_cstr(
"Hello %s! You are number %lf\n");
2026-05-04 16:37:06 +01:00
fx_value args[] = {
2026-05-25 17:35:09 +01:00
FX_VALUE_OBJECT(fmt),
FX_CSTR("Jonh"),
FX_DOUBLE(2.5),
2026-05-04 16:37:06 +01:00
};
2026-05-04 22:54:02 +01:00
fx_function_bind(func, args, sizeof args / sizeof args[0]);
2026-05-04 16:37:06 +01:00
fx_value result = FX_VALUE_EMPTY;
2026-05-04 22:54:02 +01:00
int r = fx_function_invoke(func, NULL, 0, &result);
2026-05-25 17:35:09 +01:00
printf("%d\n", result.v_int);
2026-05-04 16:37:06 +01:00
return 0;
}