Reject nan as table index.

This commit is contained in:
James Roseborough
2010-05-04 23:48:59 +00:00
parent 029895c22b
commit 7d3b58d631
4 changed files with 12 additions and 1 deletions

View File

@@ -192,4 +192,9 @@ public class LuaDouble extends LuaNumber {
return LuaString.valueOf(tojstring()); return LuaString.valueOf(tojstring());
} }
public LuaValue checkvalidkey() {
if ( Double.isNaN(v) )
throw new LuaError("table index expected, got nan");
return this;
}
} }

View File

@@ -62,6 +62,10 @@ public class LuaNil extends LuaValue {
public LuaValue checknotnil() { public LuaValue checknotnil() {
return typerror("value"); return typerror("value");
} }
public LuaValue checkvalidkey() {
return typerror("table index");
}
// optional argument conversions - nil alwas falls badk to default value // optional argument conversions - nil alwas falls badk to default value
public boolean optboolean(boolean defval) { return defval; } public boolean optboolean(boolean defval) { return defval; }

View File

@@ -189,7 +189,7 @@ public class LuaTable extends LuaValue {
/** caller must ensure key is not nil */ /** caller must ensure key is not nil */
public void set( LuaValue key, LuaValue value ) { public void set( LuaValue key, LuaValue value ) {
key.checknotnil(); key.checkvalidkey();
if ( m_metatable==null || ! rawget(key).isnil() || ! settable(this,key,value) ) if ( m_metatable==null || ! rawget(key).isnil() || ! settable(this,key,value) )
rawset(key, value); rawset(key, value);
} }

View File

@@ -153,6 +153,8 @@ public class LuaValue extends Varargs {
public Object checkuserdata() { typerror("userdata"); return null; } public Object checkuserdata() { typerror("userdata"); return null; }
public Object checkuserdata(Class c) { typerror("userdata"); return null; } public Object checkuserdata(Class c) { typerror("userdata"); return null; }
public LuaValue checknotnil() { return this; } public LuaValue checknotnil() { return this; }
public LuaValue checkvalidkey() { return this; }
/** @deprecated - use checkjstring() instead */ /** @deprecated - use checkjstring() instead */
public String checkString() { return checkjstring(); } public String checkString() { return checkjstring(); }