diff options
| author | rtk0c <[email protected]> | 2025-10-15 20:31:31 +0000 |
|---|---|---|
| committer | rtk0c <[email protected]> | 2025-10-15 20:31:31 +0000 |
| commit | 81cab430b58b75fe0a6c75722908481dd4d9d55a (patch) | |
| tree | 499ba0404470de6047238eb554da6f2afa965e24 /metafang/cm/ex01.lua | |
| parent | bc8c20d1e93b5c18e8915d356e74024092a74ce8 (diff) | |
this metaprogramming attempt was started outside, and then imported here
5124eb80701523ac16928219e9a1031eded128ef..bc8c20d1e93b5c18e8915d356e74024092a74ce8
Diffstat (limited to 'metafang/cm/ex01.lua')
| -rw-r--r-- | metafang/cm/ex01.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/metafang/cm/ex01.lua b/metafang/cm/ex01.lua new file mode 100644 index 0000000..f92ec2a --- /dev/null +++ b/metafang/cm/ex01.lua @@ -0,0 +1,27 @@ +-- Environment is loaded with the utils (as metatable.__index) +-- Global vars (aka properties on env) will be read as decls + +-- TERMINOLOGY: +-- decl: a property somewhere, the property name and the value makes up the declaration +-- type: a value (perhaps a part of a decl), which contains a type tag ("struct", "union", "alias", etc.) and extra info for that kind of type + +-- _struct, _union, _alias, etc. are type construction helpers. +-- They take the essential info, and returns a value properly decorated. For example it might just add a property {_tag="struct"}, or perhaps more. + +-- 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(_t("u32")) + +-- Note, defined after Bar! +Foo = _struct({ + n = _t("i32"), +}) |
