"CONSTRUCTOR(class)=class::class(" \
"DESTRUCTOR(class)=class::~class()" \
"ATTRIB(class, name, T, val)=T name = val;" \
+ "ATTRIB_STRZONE(class, name, T, val)=T name = val;" \
+ "STATIC_ATTRIB(class, name, T, val)=static T name = val;" \
+ "STATIC_ATTRIB_STRZONE(class, name, T, val)=static T name = val;" \
"METHOD(class, name, prototype)=virtual void class::name()" \
"ENDCLASS(class)=};" \
__STDC__
CLASS \
CONSTRUCTOR \
DESTRUCTOR \
- ATTRIB \
+ ATTRIB ATTRIB_STRZONE \
+ STATIC_ATTRIB STATIC_ATTRIB_STRZONE \
METHOD \
ENDCLASS \
LABEL \
}
#define VTBL(cname, base) \
- INIT_STATIC(cname); \
+ _INIT_STATIC(cname); \
entity cname##_vtbl; \
void cname##_vtbl_init() \
{ \
} \
ACCUMULATE_FUNCTION(RegisterClasses, cname##_vtbl_init)
-#define INIT_STATIC(cname) [[accumulate]] void spawn##cname##_static(cname this)
+#define _INIT_STATIC(cname) [[accumulate]] void spawn##cname##_static(cname this)
#define INIT(cname) [[accumulate]] cname spawn##cname##_1(cname this)
#define CLASS(cname, base) \
class(cname).bool instanceOf##cname; \
bool is_##cname(entity e) { return e.instanceOf##cname; } \
VTBL(cname, base) \
- INIT_STATIC(cname) \
+ _INIT_STATIC(cname) \
{ \
if (cname##_vtbl) \
{ \
#define METHOD(cname, name, prototype) \
STATIC_METHOD(cname, name, prototype); \
class(cname) .prototype name; \
- INIT_STATIC(cname) \
+ _INIT_STATIC(cname) \
{ \
this.name = METHOD_REFERENCE(cname, name); \
} \
this.name = val; \
}
+#define STATIC_ATTRIB(cname, name, type, val) \
+ type cname##_##name; \
+ _INIT_STATIC(cname) \
+ { \
+ noref bool strzone; /* Error on strzone() calls. */ \
+ cname##_##name = val; \
+ }
+
+// cleanup potentially zoned strings from base classes
+
#define ATTRIB_STRZONE(cname, name, type, val) \
class(cname).type name; \
INIT(cname) \
this.name = strzone(val); \
}
+#define STATIC_ATTRIB_STRZONE(cname, name, type, val) \
+ type cname##_##name; \
+ _INIT_STATIC(cname) \
+ { \
+ if (cname##_##name) \
+ strunzone(cname##_##name); \
+ cname##_##name = val; \
+ }
+
#define ATTRIBARRAY(cname, name, type, cnt) \
class(cname).type name[cnt];
#pragma once
CLASS(DataSource, Object)
- entity DataSource_true;
- entity DataSource_false;
- INIT_STATIC(DataSource) {
- DataSource_true = NEW(Object);
- DataSource_false = NULL;
- }
+ STATIC_ATTRIB(DataSource, true, entity, NEW(Object));
+ STATIC_ATTRIB(DataSource, false, entity, NULL);
/**
* get entry `i` passing `name` and `icon` through `returns` if it is not null
* returns `DataSource_false` if out of bounds