mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 17:56:34 -04:00
Merge branch 'sides-idiom' of https://github.com/benblank/OpenComputers into master-MC1.7.10
This commit is contained in:
commit
10c7276ecf
@ -32,6 +32,31 @@ local sides = {
|
|||||||
forward = 3
|
forward = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local metatable = getmetatable(sides) or {}
|
||||||
|
|
||||||
|
-- sides[0..5] are mapped to itertable[1..6].
|
||||||
|
local itertable = {
|
||||||
|
sides[0],
|
||||||
|
sides[1],
|
||||||
|
sides[2],
|
||||||
|
sides[3],
|
||||||
|
sides[4],
|
||||||
|
sides[5]
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Future-proofing against the possible introduction of additional
|
||||||
|
-- logical sides (e.g. [7] = "all", [8] = "none", etc.).
|
||||||
|
function metatable.__len(sides)
|
||||||
|
return #itertable
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Allow `sides` to be iterated over like a normal (1-based) array.
|
||||||
|
function metatable.__ipairs(sides)
|
||||||
|
return ipairs(itertable)
|
||||||
|
end
|
||||||
|
|
||||||
|
setmetatable(sides, metatable)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
return sides
|
return sides
|
||||||
|
Loading…
x
Reference in New Issue
Block a user