Expected behavior
Negative and out-of-bounds indices to pixbuf.buffer:sub() and related methods (replace(), shift(), map()) should raise errors if not supported, or else behave analogously to indices given to string.sub(). (Documentation for buffer.sub() explicitly draws this comparison.)
Actual behavior
> pixbuf=require'pixbuf'
> buf = pixbuf.newBuffer(4, 4)
> buf:set(1, 'AAAABBBBCCCCDDDD')
> print(('>>%s<<'):format(('ABCD'):sub(5, -1)))
>><<
> print(('>>%s<<'):format(buf:sub(5, -1):dump())) -- should be empty too
>>DDDD<<
> buf:replace('XXXX', 5) -- off the end
> print(buf:dump())
AAAABBBBCCCCXXXX
> buf:map(function(r, g, b, w) return r+1, g+1, b+1, w+1 end, buf, -1, -1) -- just the last pixel
Lua error: stdin:1: bad argument #2 to 'map' (Buffer limits out of order)
stack traceback:
[C]: in function 'map'
stdin:1: in main chunk
[C]: ?
[C]: ?
> buf:shift(1, pixbuf.SHIFT_LOGICAL, 5, 5) -- off the end
> print(('>>%s<<'):format(buf:dump()))
>>AAAABBBBCCCC<<
Test code
pixbuf=require'pixbuf'
buf = pixbuf.newBuffer(4, 4)
buf:set(1, 'AAAABBBBCCCCDDDD')
print(('>>%s<<'):format(('ABCD'):sub(5, -1)))
print(('>>%s<<'):format(buf:sub(5, -1):dump())) -- should be empty too
buf:replace('XXXX', 5) -- off the end
print(buf:dump())
buf:map(function(r, g, b, w) return r+1, g+1, b+1, w+1 end, buf, -1, -1) -- just the last pixel
buf:shift(1, pixbuf.SHIFT_LOGICAL, 5, 5) -- off the end
print(('>>%s<<'):format(buf:dump()))
NodeMCU startup banner
NodeMCU 3.0.0.0
branch: fixbuf-base
commit: 0661fe100172a6a1b724488abcbdaefc854dc267
release: 3.0.0-release_20211229 +58
release DTS: 202604111201
SSL: false
build type: float
LFS: 0x20000 bytes total capacity
modules: bit,color_utils,file,gpio,http,net,node,pixbuf,tmr,uart,wifi,ws2812
Hardware
Adafruit Feather Huzzah + no special hardware.
Expected behavior
Negative and out-of-bounds indices to
pixbuf.buffer:sub()and related methods (replace(),shift(),map()) should raise errors if not supported, or else behave analogously to indices given tostring.sub(). (Documentation forbuffer.sub()explicitly draws this comparison.)Actual behavior
Test code
NodeMCU startup banner
Hardware
Adafruit Feather Huzzah + no special hardware.