diff --git a/test/dynamic-object.c b/test/dynamic-object.c new file mode 100644 index 0000000..47db389 --- /dev/null +++ b/test/dynamic-object.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include + +extern fx_assembly *fx_runtime_assembly_get(void); + +static fx_string *create_string(const fx_type *ty) +{ + const fx_function *string_create = fx_type_get_function( + ty, + "create_from_cstr"); + if (!string_create) { + printf("cannot find create_from_cstr()\n"); + return NULL; + } + + printf("found fx.string.create_from_cstr()\n"); + fx_value args[] = {FX_VALUE_CSTR("Hello, world!")}; + fx_value result = FX_VALUE_EMPTY; + fx_status status = fx_function_invoke( + string_create, + args, + sizeof args / sizeof args[0], + &result); + if (!FX_OK(status)) { + printf("call to fx.string.create_from_cstr() failed (%s)\n", + fx_status_description(status)); + return NULL; + } + + fx_string *str = result.v_pointer; + return str; +} + +static const char *get_cstr(const fx_type *ty, fx_string *str) +{ + const fx_function *get_cstr = fx_type_get_function(ty, "get_cstr"); + if (!get_cstr) { + printf("cannot find get_cstr()\n"); + return NULL; + } + + printf("found fx.string.get_cstr()\n"); + fx_value args[] = {FX_VALUE_POINTER(str)}; + fx_value result = FX_VALUE_EMPTY; + fx_status status = fx_function_invoke( + get_cstr, + args, + sizeof args / sizeof args[0], + &result); + if (!FX_OK(status)) { + printf("call to fx.string.get_cstr() failed (%s)\n", + fx_status_description(status)); + return NULL; + } + + const char *cstr = result.v_cstr; + return cstr; +} + +int main(int argc, const char **argv) +{ + fx_assembly *fx_runtime = fx_runtime_assembly_get(); + fx_assembly_dump(fx_runtime); + + const fx_type *ty = fx_type_get_by_name("fx.string"); + if (!ty) { + printf("cannot find type\n"); + return -1; + } + + printf("found type '%s'\n", fx_type_get_name(ty)); + fx_string *str = create_string(ty); + if (!str) { + return -1; + } + + const char *cstr = get_cstr(ty, str); + if (!cstr) { + return -1; + } + + printf("created string '%s'\n", cstr); + return 0; +} diff --git a/test/dynamic-printf.c b/test/dynamic-printf.c index 8956fbc..2d711dc 100644 --- a/test/dynamic-printf.c +++ b/test/dynamic-printf.c @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/test/dynamic-strings.c b/test/dynamic-strings.c new file mode 100644 index 0000000..da17437 --- /dev/null +++ b/test/dynamic-strings.c @@ -0,0 +1,8 @@ +#include +#include +#include + +int main(int argc, const char **argv) +{ + return 0; +}