aboutsummaryrefslogtreecommitdiff
path: root/cm/ex01.lua
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2025-09-24 01:09:38 +0000
committerrtk0c <[email protected]>2025-10-15 20:28:15 +0000
commit5124eb80701523ac16928219e9a1031eded128ef (patch)
tree165e99dc01bee9d8b00bab09997fe04f772bdefb /cm/ex01.lua
parent21da7e16ec4104fa7a4fe489f2c371520e037cc6 (diff)
metalanguage design (both lua literals and DSL)
Diffstat (limited to 'cm/ex01.lua')
-rw-r--r--cm/ex01.lua20
1 files changed, 20 insertions, 0 deletions
diff --git a/cm/ex01.lua b/cm/ex01.lua
new file mode 100644
index 0000000..feaf876
--- /dev/null
+++ b/cm/ex01.lua
@@ -0,0 +1,20 @@
+-- Environment is loaded with the utils (as metatable.__index)
+-- Global vars (aka properties on env) will be read as decls
+
+-- name implied by property key here
+Bar = _struct({
+ -- _t: Loads another type by its name. Return the type, or a placeholder if the type is not yet available
+ -- Useful recursive definitions
+ -- Undefined type errors generated on the referential resolution pass (i.e. not immediately)
+ field1 = _t("i32"),
+ field2 = _t("string"),
+ -- Deferred loading as described above
+ compound_field = _t("Foo"),
+})
+
+uint32 = _alias("u32")
+
+-- Note, defined after Bar!
+Foo = _struct({
+ n = _t("i32"),
+})