Improve string compatibility with lua 5.2.

This commit is contained in:
James Roseborough
2012-09-19 14:00:26 +00:00
parent a8aeddfc60
commit 406068190b
4 changed files with 23 additions and 14 deletions

View File

@@ -230,8 +230,7 @@ public class BaseLib extends OneArgFunction implements ResourceFinder {
for ( int i=1, n=args.narg(); i<=n; i++ ) {
if ( i>1 ) globals.STDOUT.write( '\t' );
LuaString s = tostring.call( args.arg(i) ).strvalue();
int z = s.indexOf((byte)0, 0);
globals.STDOUT.write( s.m_bytes, s.m_offset, z>=0? z: s.m_length );
globals.STDOUT.write( s.m_bytes, s.m_offset, s.m_length );
}
globals.STDOUT.println();
return NONE;

View File

@@ -303,15 +303,20 @@ public class StringLib extends OneArgFunction {
buf.append( (byte)'\\' );
buf.append( (byte)c );
break;
case '\r':
buf.append( "\\r" );
break;
case '\0':
buf.append( "\\000" );
break;
default:
buf.append( (byte) c );
break;
if (c <= 0x1F || c == 0x7F) {
buf.append( (byte) '\\' );
if (i+1 == n || s.luaByte(i+1) < '0' || s.luaByte(i+1) > '9') {
buf.append(Integer.toString(c));
} else {
buf.append( (byte) '0' );
buf.append( (byte) (char) ('0' + c / 10) );
buf.append( (byte) (char) ('0' + c % 10) );
}
} else {
buf.append((byte) c);
}
break;
}
}
buf.append( (byte) '"' );