class.c 631 Bytes
#include <stdarg.h>
#include <stdlib.h>
#include <assert.h>

#include "class.h"
#include "interface/class.h"

const
struct interface i_Class = {
	"class",
	3
};

inline
void *
classNew(class_ptr class, ...)
{
	void * object = calloc(1, class->object_size + sizeof(void*));
	va_list params;

	if (class->init)	class->init();

	* (class_ptr *)object = class;
	object += sizeof(void*);

	va_start(params, class);
	CALL(object, Class, ctor, &params);
	va_end(params);

	return object;
}

inline
void
classDelete(void ** object)
{
	CALL(*object, Class, dtor);

	free(*object - sizeof(void*));
	*object = NULL;
}

// vim: set ts=4 sw=4: