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 ...@@ -184,9 +184,15 @@ class IO
nil nil
end end
def ungetbyte(substr) def ungetbyte(c)
substr = substr.chr if substr.is_a? Integer if c.is_a? String
ungetc substr c = c.getbyte(0)
else
c &= 0xff
end
s = " "
s.setbyte(0,c)
ungetc s
end end
def read(length = nil, outbuf = "") 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