mirror of
https://github.com/minetest-mods/mesecons.git
synced 2025-07-04 08:30:24 +02:00
Handle getting out-of-bounds bits in get_bit
The binary state is not padded with zeroes, so they must be inferred.
This commit is contained in:
@ -163,8 +163,13 @@ function mesecon.getbinstate(nodename, states)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function mesecon.get_bit(binary,bit)
|
function mesecon.get_bit(binary,bit)
|
||||||
bit = bit or 1
|
local len = binary:len()
|
||||||
local c = binary:len()-(bit-1)
|
if bit then
|
||||||
|
if bit > len then return false end
|
||||||
|
else
|
||||||
|
bit = 1
|
||||||
|
end
|
||||||
|
local c = len-(bit-1)
|
||||||
return binary:sub(c,c) == "1"
|
return binary:sub(c,c) == "1"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user