From be5690bf05707107bc6f02005af82399b0c1c655 Mon Sep 17 00:00:00 2001 From: seh Date: Mon, 18 Mar 2019 03:44:58 -0500 Subject: add work on modules example --- Modules/modules.b | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Modules/modules.b (limited to 'Modules/modules.b') diff --git a/Modules/modules.b b/Modules/modules.b new file mode 100644 index 0000000..6dbeb85 --- /dev/null +++ b/Modules/modules.b @@ -0,0 +1,48 @@ +implement Modules; + +include "sys.m"; +include "draw.m"; + +# Note the lack of `include "persons.m";` +include "towns.m"; + +sys: Sys; +print: import sys; + +persons: Persons; +Person: import persons; + +towns: Towns; +Town: import towns; + +Modules: module { + init: fn(nil: ref Draw->Context, nil: list of string); +}; + +init(nil: ref Draw->Context, nil: list of string) { + sys = load Sys Sys->PATH; + + persons = load Persons "./persons.dis"; + towns = load Towns "./towns.dis"; + + persons->init(); + towns->init(); + + print("%d\n", persons->getpop()); + print("%d\n", towns->persons->getpop()); + + p := persons->mkperson(); + p.name = "Spike"; + p.age = 27; + + print("%d\n", persons->getpop()); + print("%d\n", towns->persons->getpop()); + + t := towns->mktown(); + t.pop = array[] of {p, ref Person(13, "Ed")}; + t.name = "Mars"; + + print("%s\n", t.stringify()); + + exit; +} -- cgit v1.2.3