205#define OBJECTIVELY_MAGIC 0xdeadbeef
210#define isobject(obj) \
211 (obj && *((unsigned int *) obj) == OBJECTIVELY_MAGIC)
216#define instanceof(type, obj) \
217 (isobject(obj) && $((Object *) obj, isKindOfClass, _##type()))
223 ((type *) _alloc(_##type()))
228#define cast(type, obj) \
229 ((type *) _cast(_##type(), (const ident) obj))
234#define classof(obj) \
235 ((Object *) obj)->clazz
240#define classnameof(obj) \
241 classof(obj)->def.name
246#define interfaceof(type, clazz) \
247 ((type##Interface *) (clazz)->interface)
252#define $(obj, method, ...) \
254 typeof(obj) _obj = obj; \
255 _obj->interface->method(_obj, ## __VA_ARGS__); \
259#define $$(type, method, ...) \
261 interfaceof(type, _##type())->method(__VA_ARGS__); \
267#define super(type, obj, method, ...) \
268 interfaceof(type, _Class()->def.superclass)->method(cast(type, obj), ## __VA_ARGS__)
OBJECTIVELY_EXPORT void addClassImage(ident handle)
Registers an image that provides Classes, e.g. a plugin.
OBJECTIVELY_EXPORT ident retain(ident obj)
Atomically increment the given Object's reference count.
OBJECTIVELY_EXPORT size_t _pageSize
The page size, in bytes, of the target host.
OBJECTIVELY_EXPORT Class * _initialize(const ClassDef *clazz)
Initializes the given Class.
OBJECTIVELY_EXPORT void removeClassImage(ident handle)
Unregisters an image, and every Class it declared.
OBJECTIVELY_EXPORT ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
OBJECTIVELY_EXPORT ident _alloc(Class *clazz)
Instantiate a type through the given Class.
OBJECTIVELY_EXPORT Class * classForName(const char *name)
OBJECTIVELY_EXPORT ident _cast(const Class *clazz, const ident obj)
Perform a type-checking cast.
Helpers for at-most-once semantics.
void * ident
The identity type, similar to Objective-C id.
#define OBJECTIVELY_EXPORT
ClassDefs are passed to _initialize via an archetype to initialize a Class.
size_t instanceSize
The instance size (required).
size_t interfaceSize
The interface size (required).
ptrdiff_t interfaceOffset
The interface offset (required).
Class * superclass
The superclass (required). e.g. _Object().
void(* destroy)(Class *clazz)
The Class destructor (optional). This method is run for initialized Classes when your application exi...
const char * name
The Class name (required).
void(* initialize)(Class *clazz)
The Class initializer (optional).
The runtime representation of a Class.
ident image
The base address of the image that declared this Class.
ClassDef def
The Class definition.
Class * next
Provides chaining of initialized Classes.
ident interface
The interface of the Class.