209#define OBJECTIVELY_MAGIC 0xdeadbeef
214#define isobject(obj) \
215 (obj && *((unsigned int *) obj) == OBJECTIVELY_MAGIC)
220#define instanceof(type, obj) \
221 (isobject(obj) && $((Object *) obj, isKindOfClass, _##type()))
227 ((type *) _alloc(_##type()))
232#define cast(type, obj) \
233 ((type *) _cast(_##type(), (const ident) obj))
238#define classof(obj) \
239 ((Object *) obj)->clazz
244#define classnameof(obj) \
245 classof(obj)->def.name
250#define interfaceof(type, clazz) \
251 ((type##Interface *) (clazz)->interface)
267#define $(obj, method, ...) \
269 typeof(obj) _obj = (obj); \
270 ((typeof(_obj->interface[0])) classof(_obj)->interface)->method(_obj, ## __VA_ARGS__); \
274#define $$(type, method, ...) \
276 interfaceof(type, _##type())->method(__VA_ARGS__); \
282#define super(type, obj, method, ...) \
283 interfaceof(type, _Class()->def.superclass)->method(cast(type, obj), ## __VA_ARGS__)
OBJECTIVELY_EXPORT void addClassImage(ident handle, const ident address)
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).
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.