fix string.format not converting non-strings for %s (requires __tostring fix)
This commit is contained in:
@@ -309,10 +309,24 @@ public class StringLib extends TwoArgFunction {
|
|||||||
addquoted( result, args.checkstring( arg ) );
|
addquoted( result, args.checkstring( arg ) );
|
||||||
break;
|
break;
|
||||||
case 's': {
|
case 's': {
|
||||||
LuaString s = args.checkstring( arg );
|
LuaValue argv = args.checkvalue( arg );
|
||||||
|
LuaString s;
|
||||||
|
LuaValue h = argv.metatag(TOSTRING);
|
||||||
|
if ( ! h.isnil() ) {
|
||||||
|
LuaValue v = h.call(argv).tostring();
|
||||||
|
return !v.isnil() ? v : StringLib.valueOf("(null)");
|
||||||
|
} else {
|
||||||
|
LuaValue v = argv.tostring();
|
||||||
|
if ( ! v.isnil() ) {
|
||||||
|
s = v.checkstring();
|
||||||
|
} else {
|
||||||
|
s = StringLib.valueOf(argv.tojstring());
|
||||||
|
}
|
||||||
|
}
|
||||||
if ( fdsc.precision == -1 && s.length() >= 100 ) {
|
if ( fdsc.precision == -1 && s.length() >= 100 ) {
|
||||||
result.append( s );
|
result.append( s );
|
||||||
} else {
|
} else {
|
||||||
|
fdsc.zeroPad = false;
|
||||||
fdsc.format( result, s );
|
fdsc.format( result, s );
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|||||||
Reference in New Issue
Block a user