Module lib.blocks
Blocks: basic rectangular building blocks for shado applications.
Blocks are populated with lamps.
See also:
Functions
Block:new (a1, a2) | Create a new block. |
Block:inRange (x, y) | Test whether a coordinate position is within the size range of a block. |
Block:setLamp (x, y, lampState) | Set the lamp value for a single position in the block. |
Block:fill (lampState) | Fill a block with a single lamp value. |
Block:getLamp (x, y) | Get the lamp value of a location in the block, or return THRU
if out of coordinate range. |
Block:press (x, y, how) | The default button press handler. |
Block:routePress00 (x, y) | Internal function for routing press-on events. |
Functions
- Block:new (a1, a2)
-
Create a new block. Can be called as
Block:new("xxxx xxxx xxxx")
where the argument string specifies the number of rows (according to the number of space-separated tokens) and the content of each row (according to the character:
0
,1
,.
,/
).The form
Block:new(w, h)
takes two integers and creates a block of width
w
and heighth
, all lamp valuesOFF
(opaque black).The form
Block:new()
creates a block of size
(0, 0)
and is used in some circumstances for inheritance.Parameters:
- a1 format string, or width (or omitted for zero-size block)
- a2 if present: height
Returns:
-
a new block
- Block:inRange (x, y)
-
Test whether a coordinate position is within the size
range of a block. Top-left is
(1, 1)
.Parameters:
- x the X coordinate position
- y the Y coordinate position
Returns:
true
orfalse
depending on position - Block:setLamp (x, y, lampState)
-
Set the lamp value for a single position in the block. Throws an
error if the position is out of range.
Parameters:
- x the X coordinate position
- y the Y coordinate position
- lampState
the lamp value (type
types.LampState
)
See also:
- Block:fill (lampState)
-
Fill a block with a single lamp value.
Parameters:
- lampState
the lamp value (type
types.LampState
)
Returns:
-
the block
See also:
- lampState
the lamp value (type
- Block:getLamp (x, y)
-
Get the lamp value of a location in the block, or return
THRU
if out of coordinate range. Top-left is(1, 1)
.Parameters:
- x the X coordinate
- y the Y coordinate
Returns:
-
the lamp value
See also:
- Block:press (x, y, how)
-
The default button press handler. Returns
false
; override to do something useful (and return non-false
to mark the press as being processed).Parameters:
- x the X coordinate
- y the Y coordinate
- how
1
for press,0
for release
- Block:routePress00 (x, y)
-
Internal function for routing press-on events. Returns a
RouteResult
object if the location is within range and the block handles the press, otherwisenil
.Parameters:
- x
- y