From 84ad096896e9948c722a957d07ed6868e252a9f7 Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Thu, 29 Aug 2024 17:00:11 +0200 Subject: Initial commit --- includes/point.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 includes/point.c (limited to 'includes/point.c') diff --git a/includes/point.c b/includes/point.c new file mode 100644 index 0000000..a68fcf2 --- /dev/null +++ b/includes/point.c @@ -0,0 +1,31 @@ +#include +#include +#include "point.h" + +#define TYPE Point + +DEFINE_OBJECT_STRUCTURE(TYPE) { + float x; + float y; +}; + +CONSTRUCTOR_IMPLEMENT(TYPE); + +void METHOD_ARG(TYPE, init, float x, float y) { + CATCH_SELF_NULL(TYPE_init); + self->x = x; + self->y = y; +} + +int METHOD_ARG(TYPE, toString, char* buffer) { + CATCH_SELF_NULL(TYPE_toString); + return sprintf(buffer, NAMEOF(TYPE) " { x = %.2f, y = %.2f }", self->x, self->y); +} + +GETTER_IMPLEMENT(TYPE, float, x); +SETTER_IMPLEMENT(TYPE, float, x); + +GETTER_IMPLEMENT(TYPE, float, y); +SETTER_IMPLEMENT(TYPE, float, y); + +#undef TYPE -- cgit v1.2.3