Fix bug in LuaJava overload resolution.
This commit is contained in:
@@ -119,27 +119,37 @@ public class CoerceLuaToJava {
|
|||||||
this.targetType = targetType;
|
this.targetType = targetType;
|
||||||
}
|
}
|
||||||
public int score( LuaValue value ) {
|
public int score( LuaValue value ) {
|
||||||
|
int fromStringPenalty = 0;
|
||||||
|
if ( value.type() == LuaValue.TSTRING ) {
|
||||||
|
value = value.tonumber();
|
||||||
|
if ( value.isnil() ) {
|
||||||
|
return SCORE_UNCOERCIBLE;
|
||||||
|
}
|
||||||
|
fromStringPenalty = 4;
|
||||||
|
}
|
||||||
if ( value.isint() ) {
|
if ( value.isint() ) {
|
||||||
switch ( targetType ) {
|
switch ( targetType ) {
|
||||||
case TARGET_TYPE_BYTE: {
|
case TARGET_TYPE_BYTE: {
|
||||||
int i = value.toint();
|
int i = value.toint();
|
||||||
return (i==(byte)i)? 0: SCORE_WRONG_TYPE;
|
return fromStringPenalty + ((i==(byte)i)? 0: SCORE_WRONG_TYPE);
|
||||||
}
|
}
|
||||||
case TARGET_TYPE_CHAR: {
|
case TARGET_TYPE_CHAR: {
|
||||||
int i = value.toint();
|
int i = value.toint();
|
||||||
return (i==(byte)i)? 1: (i==(char)i)? 0: SCORE_WRONG_TYPE;
|
return fromStringPenalty + ((i==(byte)i)? 1: (i==(char)i)? 0: SCORE_WRONG_TYPE);
|
||||||
}
|
}
|
||||||
case TARGET_TYPE_SHORT: {
|
case TARGET_TYPE_SHORT: {
|
||||||
int i = value.toint();
|
int i = value.toint();
|
||||||
return (i==(byte)i)? 1: (i==(short)i)? 0: SCORE_WRONG_TYPE;
|
return fromStringPenalty +
|
||||||
|
((i==(byte)i)? 1: (i==(short)i)? 0: SCORE_WRONG_TYPE);
|
||||||
}
|
}
|
||||||
case TARGET_TYPE_INT: {
|
case TARGET_TYPE_INT: {
|
||||||
int i = value.toint();
|
int i = value.toint();
|
||||||
return (i==(byte)i)? 2: ((i==(char)i) || (i==(short)i))? 1: 0;
|
return fromStringPenalty +
|
||||||
|
((i==(byte)i)? 2: ((i==(char)i) || (i==(short)i))? 1: 0);
|
||||||
}
|
}
|
||||||
case TARGET_TYPE_FLOAT: return 1;
|
case TARGET_TYPE_FLOAT: return fromStringPenalty + 1;
|
||||||
case TARGET_TYPE_LONG: return 1;
|
case TARGET_TYPE_LONG: return fromStringPenalty + 1;
|
||||||
case TARGET_TYPE_DOUBLE: return 2;
|
case TARGET_TYPE_DOUBLE: return fromStringPenalty + 2;
|
||||||
default: return SCORE_WRONG_TYPE;
|
default: return SCORE_WRONG_TYPE;
|
||||||
}
|
}
|
||||||
} else if ( value.isnumber() ) {
|
} else if ( value.isnumber() ) {
|
||||||
@@ -150,15 +160,15 @@ public class CoerceLuaToJava {
|
|||||||
case TARGET_TYPE_INT: return SCORE_WRONG_TYPE;
|
case TARGET_TYPE_INT: return SCORE_WRONG_TYPE;
|
||||||
case TARGET_TYPE_LONG: {
|
case TARGET_TYPE_LONG: {
|
||||||
double d = value.todouble();
|
double d = value.todouble();
|
||||||
return (d==(long)d)? 0: SCORE_WRONG_TYPE;
|
return fromStringPenalty + ((d==(long)d)? 0: SCORE_WRONG_TYPE);
|
||||||
}
|
}
|
||||||
case TARGET_TYPE_FLOAT: {
|
case TARGET_TYPE_FLOAT: {
|
||||||
double d = value.todouble();
|
double d = value.todouble();
|
||||||
return (d==(float)d)? 0: SCORE_WRONG_TYPE;
|
return fromStringPenalty + ((d==(float)d)? 0: SCORE_WRONG_TYPE);
|
||||||
}
|
}
|
||||||
case TARGET_TYPE_DOUBLE: {
|
case TARGET_TYPE_DOUBLE: {
|
||||||
double d = value.todouble();
|
double d = value.todouble();
|
||||||
return ((d==(long)d) || (d==(float)d))? 1: 0;
|
return fromStringPenalty + (((d==(long)d) || (d==(float)d))? 1: 0);
|
||||||
}
|
}
|
||||||
default: return SCORE_WRONG_TYPE;
|
default: return SCORE_WRONG_TYPE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user