aboutsummaryrefslogtreecommitdiff
path: root/lib/object.nom
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-10-29 13:00:08 -0700
committerBruce Hill <bruce@bruce-hill.com>2018-10-29 13:00:30 -0700
commit23abab4f809e8d4b825746580082292db700036b (patch)
tree8eb95a3b781547abedadd08705a6e6291662737c /lib/object.nom
parentbe1df7ccd3fb5352ca666129aee93c56b5b27b40 (diff)
Some cleanups and fixes, made the parser more permissive of prematurely
terminated files.
Diffstat (limited to 'lib/object.nom')
-rw-r--r--lib/object.nom23
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/object.nom b/lib/object.nom
index 25ff644..bbc6e06 100644
--- a/lib/object.nom
+++ b/lib/object.nom
@@ -2,6 +2,15 @@
#
This file contains the implementation of an Object-Oriented programming system.
+%globals.METAMETHOD_MAP = {..}
+ "as text": "__tostring", "clean up": "__gc",
+ "+ 1": "__add", "- 1": "__sub", "* 1": "__mul", "/ 1": "__div",
+ "-": "__unm", "// 1": "__idiv", "mod 1": "__mod", "^ 1": "__pow",
+ "& 1": "__band", "| 1": "__bor", "~ 1": "__bxor", "~": "__bnot",
+ "<< 1": "__bshl", ">> 1": "__bshr", "== 1": "__eq", "< 1": "__lt",
+ "<= 1": "__le", "set 1 = 2": "__newindex", "size": "__len",
+ "iterate": "__ipairs", "iterate all": "__pairs",
+
test:
object (Dog):
(Dog).genus = "Canus"
@@ -86,9 +95,7 @@ compile [object %classname extends %parent %class_body] to:
__tostring=function(cls) return cls.name end,
__call=function(cls, inst)
inst = setmetatable(inst or {}, cls)
- if inst.set_up then
- inst:set_up()
- end
+ if inst.set_up then inst:set_up() end
return inst
end,
})
@@ -100,15 +107,7 @@ compile [object %classname extends %parent %class_body] to:
return inst.name..getmetatable(_Dict{}).__tostring(inst)
end
\(%class_body as lua statements)
- local metamethod_map = {["as text"]="__tostring", ["clean up"]="__gc",
- ["+ 1"]="__add", ["- 1"]="__sub", ["* 1"]="__mul", ["/ 1"]="__div",
- ["-"]="__unm", ["// 1"]="__idiv", ["mod 1"]="__mod", ["^ 1"]="__pow",
- ["& 1"]="__band", ["| 1"]="__bor", ["~ 1"]="__bxor", ["~"]="__bnot",
- ["<< 1"]="__bshl", [">> 1"]="__bshr", ["== 1"]="__eq", ["< 1"]="__lt",
- ["<= 1"]="__le", ["set 1 = 2"]="__newindex", ["size"]="__len",
- ["iterate"]="__ipairs", ["iterate all"]="__pairs",
- }
- for stub,metamethod in pairs(metamethod_map) do
+ for stub,metamethod in pairs(globals.METAMETHOD_MAP) do
class[metamethod] = class[stub:as_lua_id()]
end
end"