Skip to content

Commit

Permalink
fix booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
trentgill committed May 12, 2021
1 parent cefb48c commit 67716e9
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions booleans.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,33 @@
-- enumeration of the fnlist. least to most density of transfer
fenum = {'~|','>','<','&','~^','^','~&','<=','>=','|'}

public.add('f1','&',fenum)
public.add('f2','|',fenum)
public.add('f3','^',fenum)
public.add('f4','~^',fenum)
public{f1 = '&' }:options(fenum):action(function() apply() end)
public{f2 = '|' }:options(fenum):action(function() apply() end)
public{f3 = '^' }:options(fenum):action(function() apply() end)
public{f4 = '~^'}:options(fenum):action(function() apply() end)

-- all the dynamic transfer fns between 2 inputs (ordering doesn't matter)
fnlist =
{ '~|' = function(a,b) return not (a or b) end
, '>' = function(a,b) return a>b end
, '<' = function(a,b) return a<b end
, '&' = function(a,b) return (a and b) end
, '~^' = function(a,b) return a==b end
, '^' = function(a,b) return a~=b end
, '~&' = function(a,b) return not (a and b) end
, '<=' = function(a,b) return a<=b end
, '>=' = function(a,b) return a>=b end
, '|' = function(a,b) return (a or b) end
{ ['~|'] = function(a,b) return not (a or b) end
, ['>' ] = function(a,b) return a and not b end
, ['<' ] = function(a,b) return b and not a end
, ['&' ] = function(a,b) return (a and b) end
, ['~^'] = function(a,b) return a==b end
, ['^' ] = function(a,b) return a~=b end
, ['~&'] = function(a,b) return not (a and b) end
, ['<='] = function(a,b) return not (a and not b) end
, ['>='] = function(a,b) return not (b and not a) end
, ['|' ] = function(a,b) return (a or b) end
}

function q(n) return input[n].volts > 1.0 end
function apply()
print'apply'
local a, b = q(1), q(2)
output[1].volts = fnlist[public.f1](a, b)
output[2].volts = fnlist[public.f2](a, b)
output[3].volts = fnlist[public.f3](a, b)
output[4].volts = fnlist[public.f4](a, b)
output[1].volts = fnlist[public.f1](a, b) and 5 or 0
output[2].volts = fnlist[public.f2](a, b) and 5 or 0
output[3].volts = fnlist[public.f3](a, b) and 5 or 0
output[4].volts = fnlist[public.f4](a, b) and 5 or 0
end

function init()
Expand Down

0 comments on commit 67716e9

Please sign in to comment.