mruby-io: fix `IO#ungetbyte`; ref #5389

- remove `Integer#chr` (thus `mruby-sting-ext`) dependency
- fix the behavior when `c.is_a? String`
- fix the behavior when `c > 255`
parent 9a9c842c
......@@ -184,9 +184,15 @@ class IO
nil
end
def ungetbyte(substr)
substr = substr.chr if substr.is_a? Integer
ungetc substr
def ungetbyte(c)
if c.is_a? String
c = c.getbyte(0)
else
c &= 0xff
end
s = " "
s.setbyte(0,c)
ungetc s
end
def read(length = nil, outbuf = "")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment