Reject nan as table index.
This commit is contained in:
@@ -192,4 +192,9 @@ public class LuaDouble extends LuaNumber {
|
||||
return LuaString.valueOf(tojstring());
|
||||
}
|
||||
|
||||
public LuaValue checkvalidkey() {
|
||||
if ( Double.isNaN(v) )
|
||||
throw new LuaError("table index expected, got nan");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,10 @@ public class LuaNil extends LuaValue {
|
||||
return typerror("value");
|
||||
}
|
||||
|
||||
public LuaValue checkvalidkey() {
|
||||
return typerror("table index");
|
||||
}
|
||||
|
||||
// optional argument conversions - nil alwas falls badk to default value
|
||||
public boolean optboolean(boolean defval) { return defval; }
|
||||
public LuaClosure optclosure(LuaClosure defval) { return defval; }
|
||||
|
||||
@@ -189,7 +189,7 @@ public class LuaTable extends LuaValue {
|
||||
|
||||
/** caller must ensure key is not nil */
|
||||
public void set( LuaValue key, LuaValue value ) {
|
||||
key.checknotnil();
|
||||
key.checkvalidkey();
|
||||
if ( m_metatable==null || ! rawget(key).isnil() || ! settable(this,key,value) )
|
||||
rawset(key, value);
|
||||
}
|
||||
|
||||
@@ -153,6 +153,8 @@ public class LuaValue extends Varargs {
|
||||
public Object checkuserdata() { typerror("userdata"); return null; }
|
||||
public Object checkuserdata(Class c) { typerror("userdata"); return null; }
|
||||
public LuaValue checknotnil() { return this; }
|
||||
public LuaValue checkvalidkey() { return this; }
|
||||
|
||||
|
||||
/** @deprecated - use checkjstring() instead */
|
||||
public String checkString() { return checkjstring(); }
|
||||
|
||||
Reference in New Issue
Block a user