5 #define NULL (null_entity)
13 entity spawnVtbl(entity this, entity base)
15 entity vtbl = spawn();
16 copyentity(this, vtbl);
17 vtbl.vtblname = vtbl.classname;
18 vtbl.classname = "vtbl";
19 vtbl.vtblbase = base ? base : vtbl; // Top level objects use vtbl as base
24 entity spawnObject(entity this, entity)
27 this.classname = "Object";
28 if (!Object_vtbl) Object_vtbl = spawnVtbl(this, NULL);
32 // Classes have a `spawn##cname(entity, entity)` constructor
33 // The parameters are used as locals for [[accumulate]]
35 // Macro to hide this implementation detail
36 #define NEW(cname) (spawn##cname(NULL, NULL))
38 #define CLASS(cname, base) \
39 entity spawn##cname(entity this, entity basevtbl) { \
40 this = NEW(base); basevtbl = base##_vtbl; \
43 #define METHOD(cname, name, prototype) \
44 prototype cname##_##name; \
46 [[accumulate]] entity spawn##cname(entity this, entity basevtbl) { \
47 this.name = cname##_##name; \
50 #define ATTRIB(cname, name, type, val) \
52 [[accumulate]] entity spawn##cname(entity this, entity basevtbl) { \
56 #define ATTRIBARRAY(cname, name, type, cnt) \
59 #define ENDCLASS(cname) \
60 .bool instanceOf##cname; \
61 entity cname##_vtbl; \
62 [[accumulate]] [[last]] entity spawn##cname(entity this, entity basevtbl) { \
63 this.instanceOf##cname = true; \
64 this.classname = #cname; \
65 if (!cname##_vtbl) cname##_vtbl = spawnVtbl(this, basevtbl); \
69 #define SUPER(cname) (cname##_vtbl.vtblbase)