Added EV_TOSTR and EV_TOSTRLEN

Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
2022-05-17 22:48:13 +02:00
parent 8e0bce6a53
commit d8981dbb49
3 changed files with 100 additions and 23 deletions

40
tostr_test.c Normal file
View File

@@ -0,0 +1,40 @@
#include <stdio.h>
#include "ev_types.h"
#include "ev_numeric.h"
typedef struct {
char *name;
int age;
char *desc;
} Person;
DEFINE_TOSTR_FUNCTION(Person, PERSON_PRINT)
{
sprintf(out, "%s:\n\tage: %d\n\tdesc: %s", self->name, self->age, self->desc);
}
TYPEDATA_GEN(Person,
TOSTR(PERSON_PRINT),
DEFAULT(
.name = "sisyphus",
.age = 9999,
.desc = "One can only imagine him happy"
),
INVALID(
.name = NULL,
.age = -1,
.desc = NULL
)
);
int main()
{
puts("");
char out[256] = {};
Person sisyphue = EV_DEFAULT(Person);
EV_TOSTR(Person)(&sisyphue, out);
puts(out);
return 0;
}