From 8bb18a89060ecd581a06238ce3fa5d2170ee3a15 Mon Sep 17 00:00:00 2001 From: the lemons Date: Sat, 27 Aug 2022 01:23:20 -0500 Subject: implement component system --- globals.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 globals.lua (limited to 'globals.lua') diff --git a/globals.lua b/globals.lua new file mode 100644 index 0000000..6ee62a9 --- /dev/null +++ b/globals.lua @@ -0,0 +1,23 @@ +local gbl_mt = {} +local decl = {} + +function gbl_mt:__index(k) + if not decl[k] then + error("unknown global: "..k, 2) + end + return rawget(self, k) +end + +function gbl_mt:__newindex(k, v) + if not decl[k] then + error("unknown global: "..k, 2) + end + rawset(self, k, v) +end + +function global(k, v) + decl[k] = true + rawset(_G, k, v) +end + +setmetatable(_G, gbl_mt) -- cgit v1.2.3