diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-02-13 08:40:24 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-02-13 08:40:24 +0000 |
| commit | ff80baf2b24657cd1d6a547d21b9564b6450f330 (patch) | |
| tree | 1b8a006fbbd8cacf9caa431042c72ff5fab11bba /lib | |
| parent | better tracebacks (diff) | |
| download | alive-ff80baf2b24657cd1d6a547d21b9564b6450f330.tar.gz alive-ff80baf2b24657cd1d6a547d21b9564b6450f330.zip | |
add logic lib
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/logic.moon | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/logic.moon b/lib/logic.moon new file mode 100644 index 0000000..27fa0da --- /dev/null +++ b/lib/logic.moon @@ -0,0 +1,64 @@ +import Op from require 'core' +unpack or= table.unpack + +class BinOp extends Op + setup: (...) => + @children = { ... } + assert #@children >= 2, "#{@} needs at least two parameters" + + update: (dt) => + for child in *@children + child\update dt + +class and_ extends BinOp + @doc: "(and a b [c]...) - AND values" + + update: (dt) => + super\update dt + + @value = true + for child in *@children + @value and= child\get! + +class or_ extends BinOp + @doc: "(or a b [c]...) - OR values + +subtracts all other arguments from a" + + update: (dt) => + super\update dt + + @value = false + for child in *@children + @value or= child\get! + +class not_ extends Op + @doc: "(not a) - boolean opposite" + + setup: (@a) => + + update: (dt) => + @a\update dt + + @value = not @a\get! + +class bool extends Op + @doc: "(bool a) - convert to bool" + + setup: (@a) => + + update: (dt) => + @a\update dt + + @value = switch @a\get! + when false, nil, 0 + false + else + true + +{ + and: and_ + or: or_ + not: not_ + :bool +} |
