Newer
Older
Tardis / lang / object.h
// SPDX-License-Identifier: MIT
// Copyright (c) 2023 John Watts and the LuminaSensum contributors

#ifndef OBJECT_H
#define OBJECT_H

#include "vm.h"

// Dispatchable object call
struct object_call {
	const char *name;
	void (*handler)(VmState state, Object obj);
};

// Object class shared between objects
struct object_class {
	void (*cleanup)(Object obj);
	struct object_call
		*calls; // Points to array terminated by call with NULL name
};

Object object_create(struct object_class *class, int priv_size);
char *object_priv(Object object, struct object_class *class);

// Adds a reference to an object
void object_hold(Object obj);

// Drops a reference to an object, possibly cleaning up the object
// Sets objptr to NULL
void object_drop(Object *objptr);

// Calls a method on an object
void dispatch_call(VmState state, Object obj, const char *name);

#endif