159#define OBJECTIVELY_MAGIC 0xdeadbeef
164#define isobject(obj) \
165 (obj && *((unsigned int *) obj) == OBJECTIVELY_MAGIC)
170#define instanceof(type, obj) \
171 (isobject(obj) && $((Object *) obj, isKindOfClass, _##type()))
177 ((type *) _alloc(_##type()))
182#define cast(type, obj) \
183 ((type *) _cast(_##type(), (const ident) obj))
188#define classof(obj) \
189 ((Object *) obj)->clazz
194#define classnameof(obj) \
195 classof(obj)->def.name
200#define interfaceof(type, clazz) \
201 ((type##Interface *) (clazz)->interface)
206#define $(obj, method, ...) \
208 typeof(obj) _obj = obj; \
209 _obj->interface->method(_obj, ## __VA_ARGS__); \
215#define $$(type, method, ...) \
217 interfaceof(type, _##type())->method(__VA_ARGS__); \
223#define super(type, obj, method, ...) \
224 interfaceof(type, _Class()->def.superclass)->method(cast(type, obj), ## __VA_ARGS__)
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 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.
ClassDef def
The Class definition.
Class * next
Provides chaining of initialized Classes.
ident interface
The interface of the Class.