aboutsummaryrefslogtreecommitdiff
path: root/lib/object.nom
diff options
context:
space:
mode:
Diffstat (limited to 'lib/object.nom')
-rw-r--r--lib/object.nom42
1 files changed, 23 insertions, 19 deletions
diff --git a/lib/object.nom b/lib/object.nom
index d8c7f5e..103f2d7 100644
--- a/lib/object.nom
+++ b/lib/object.nom
@@ -1,25 +1,27 @@
-#!/usr/bin/env nomsu -V4.8.10
+#!/usr/bin/env nomsu -V4.10.12.7
#
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"
+ "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"
- my action [set up]: %me.barks or= 0
+ my action [set up]:
+ %me.barks or= 0
+
my action [bark, woof]:
- %barks = ("Bark!" for % in 1 to %me.barks)
+ %barks = [: for % in 1 to %me.barks: add "Bark!"]
return (%barks::joined with " ")
my action [get pissed off]: %me.barks += 1
-
- %d = (Dog {barks:2})
+ %d = (Dog {barks: 2})
assume (type of %d) == "Dog"
assume (%d is a "Dog")
assume %d.barks == 2
@@ -34,31 +36,31 @@ test:
assume (%d.barks == 3)
%d2 = (Dog {})
assume (%d2.barks == 0) or barf "Default initializer failed"
- with {%d:Dog {barks:1}}:
+ with {%d: Dog {barks: 1}}:
assume ((%d::bark) == "Bark!")
+
object (Corgi) extends (Dog):
my action [sploot] "splooted"
my action [bark, woof]:
- %barks = ("Yip!" for % in 1 to %me.barks)
+ %barks = [: for % in 1 to %me.barks: add "Yip!"]
return (%barks::joined with " ")
%corg = (Corgi {})
assume (%corg.barks == 0)
- with {%d:Corgi {barks:1}}:
+ with {%d: Corgi {barks: 1}}:
assume ((%d::sploot) == "splooted") or barf "subclass method failed"
assume ((%d::bark) == "Yip!") or barf "inheritance failed"
assume ((%d::woof) == "Yip!")
- with {%d:Dog {barks:2}}:
+ with {%d: Dog {barks: 2}}:
assume ((%d::bark) == "Bark! Bark!")
+
(my action %actions %body) compiles to:
lua> "\
..local fn_name = \%actions[1].stub:as_lua_id()
local \%args = List(\%actions[1]:get_args())
table.insert(\%args, 1, \(\%me))
- local lua = LuaCode("class.", fn_name, " = ", \(..)
- what (%args -> %body) compiles to
- ..)
+ local lua = LuaCode("class.", fn_name, " = ", \(what (%args -> %body) compiles to))
for i=2,#\%actions do
local alias = \%actions[i]
local alias_name = alias.stub:as_lua_id()
@@ -75,7 +77,9 @@ test:
(object %classname extends %parent %class_body) compiles to:
unless (%classname.type == "Action"):
- compile error at %classname "Expected this to be an action, not a \(%classname.type)"
+ compile error at %classname "\
+ ..Expected this to be an action, not a \%classname.type"
+
for % in %classname:
unless (% is text):
compile error at % "Class names should not have arguments."