lib/sod.h, test/chimaera.sod: Promote `SOD_DECL' to the library header.
[sod] / lib / sod.h
index 594e343..919b927 100644 (file)
--- a/lib/sod.h
+++ b/lib/sod.h
@@ -168,6 +168,19 @@ struct sod_chain {
 
 #define SOD_CONVERT(cls, obj) ((cls *)sod_convert(cls##__class, (obj)))
 
+/* --- @SOD_DECL@ --- *
+ *
+ * Arguments:  @cls_@ = a class type name
+ *             @var_@ = a variable name
+ *
+ * Use:                Declare @var_@ as a pointer to an initialized instance of
+ *             @cls_@ with automatic lifetime.
+ */
+
+#define SOD_DECL(cls_, var_)                                           \
+  struct cls_##__ilayout var_##__layout;                               \
+  cls_ *var_ = cls_##__class->cls.init(&var_##__layout)
+
 /*----- Functions provided ------------------------------------------------*/
 
 /* --- @sod_subclassp@ --- *