0
|
1
|
|
2 '''
|
|
3 Snippet Pi=3: RFC 2: New port semantics
|
|
4 '''
|
|
5
|
|
6 # an example of the max node's op
|
|
7 def changed(self, inputs):
|
|
8 # note how this function does not use stateaccess, as it doesn't use state
|
|
9 return max(inputs.values())
|
|
10
|
|
11 # so, how the heck does this work?
|
|
12 # we check the function to get the names of kw args in the function.
|
|
13 # we always pass self, but everything else is optional
|
|
14 # the node asked for inputs, which looks like this:
|
|
15 # inputs = {'portname' : PortObj, 'portname2', PortObj}
|
|
16 # somehow, the PortObjs are max'ible.
|
|
17 # the node has only one output so it can just return the value to set the
|
|
18 # output. (maybe)
|
|
19 # alteratively, if we decide that you always return a new dict of outputs:
|
|
20 # return {'outputportname' : max(inputs.values())}
|
|
21 # which isn't horrible, but not great
|
|
22
|
|
23 # another example: an adder. the node has ports A and B, and an output C:
|
|
24 # C also gets capped at stateaccess[min].
|
|
25 def changed(self, a, b, c, stateaccess):
|
|
26 c.set(max(stateaccess['min'], a + b))
|
|
27 return {}
|
|
28
|
|
29 # or:
|
|
30 def changed(self, a, b, stateaccess):
|
|
31 c = max(stateaccess['min'], a + b)
|
|
32 return {'c' : c}
|
|
33
|
|
34 # which i think is clearer. doing all port changes at the end has some
|
|
35 # book-keeping advantages (we can detect easily which ports are changed)
|
|
36 # the counter node could work this way:
|
|
37
|
|
38 def changed(self, someoutput):
|
|
39 return {'someoutput' : someoutput + 1}
|
|
40
|
|
41
|