Fix tonumber()

This commit is contained in:
James Roseborough
2007-11-16 19:43:00 +00:00
parent 45f483f706
commit d2b58a3abf

View File

@@ -186,20 +186,27 @@ public class BaseLib extends LFunction {
break; break;
case TONUMBER: { case TONUMBER: {
LValue input = vm.topointer(2); switch ( vm.type(2) ) {
vm.resettop(); case Lua.LUA_TNUMBER:
if ( input instanceof LNumber ) { break;
vm.pushlvalue(input); case Lua.LUA_TSTRING:
} else if ( input instanceof LString ) { LString s = vm.tolstring(2);
int base = 10; int base = 10;
if ( vm.gettop() >= 3 ) { if ( vm.gettop() >= 3 ) {
base = vm.tointeger(3); base = vm.tointeger(3);
if ( base < 2 || base > 36 )
vm.error("bad argument #2 to '?' (base out of range)");
} }
vm.pushlvalue( ( (LString) input ).luaToNumber( base ) ); vm.pushlvalue( s.luaToNumber(base) );
} break;
default:
vm.pushnil(); vm.pushnil();
break; break;
} }
vm.insert(1);
vm.settop(1);
break;
}
case RAWGET: { case RAWGET: {
LValue t = vm.topointer(2); LValue t = vm.topointer(2);
LValue k = vm.topointer(3); LValue k = vm.topointer(3);