1
0
forked from alex-eg/sex

test an opaque record across a module boundary

A bodyless pub record ahead of a private definition exports the handle
and keeps the fields, the way flecs keeps ecs_world_t. It worked with
nothing added, and nothing said so.
This commit is contained in:
2026-10-08 11:09:42 +03:00
parent 6c8b38b7e2
commit e9960488fb
4 changed files with 33 additions and 3 deletions

View File

@@ -6,6 +6,7 @@
;;; greet-app.sex.
(pub include stdio.h)
(include stdlib.h)
(pub var greet-count ;; a comment in the header of a public form is
;; not part of it: what the importer is given has
@@ -60,6 +61,24 @@
(pub fn manhattan ((self (* const vec2))) int
(return (+ (. self x) (. self y)))))
;;; An opaque record: the handle is public and the fields are not, so
;;; the importer holds a (* tally) and reaches it only through methods.
(pub record tally)
(record tally ((n int)))
(ops tally
(pub fn make () (* tally)
(var t (* tally) (malloc (sizeof tally)))
(= (. t n) 0)
(return t))
(pub fn bump ((self (* tally))) void
(++ (. self n)))
(pub fn count ((self (* const tally))) int
(return (. self n)))
(pub fn drop ((self (* tally))) void
(free self)))
;;; A pub sum is pasted whole, so the importer builds its own copy of
;;; the declarations -- and of the constructors, which is why those are
;;; static: two units defining colourːrgb would not link.