Fix load(func) when mutiple string fragments are supplied by calls to func

This commit is contained in:
James Roseborough
2012-01-21 17:36:03 +00:00
parent 26ed1ef392
commit c46ee6b9bd
4 changed files with 38 additions and 15 deletions

View File

@@ -413,28 +413,26 @@ public class BaseLib extends OneArgFunction implements ResourceFinder {
private static class StringInputStream extends InputStream {
LuaValue func;
final LuaValue func;
byte[] bytes;
int offset;
int offset, remaining = 0;
StringInputStream(LuaValue func) {
this.func = func;
}
public int read() throws IOException {
if ( func == null ) return -1;
if ( bytes == null ) {
if ( remaining <= 0 ) {
LuaValue s = func.call();
if ( s.isnil() ) {
func = null;
bytes = null;
if ( s.isnil() )
return -1;
LuaString ls = s.strvalue();
bytes = ls.m_bytes;
offset = ls.m_offset;
remaining = ls.m_length;
if (remaining <= 0)
return -1;
}
bytes = s.tojstring().getBytes();
offset = 0;
}
if ( offset >= bytes.length )
return -1;
--remaining;
return bytes[offset++];
}
}
}