Fix weak table creation, processing

This commit is contained in:
James Roseborough
2008-07-24 02:47:35 +00:00
parent cf069baf15
commit 4fcb2b1796
4 changed files with 11 additions and 10 deletions

View File

@@ -194,7 +194,7 @@ public class BaseLib extends LFunction {
LTable t = vm.checktable(2); LTable t = vm.checktable(2);
LValue v = vm.checkany(3); LValue v = vm.checkany(3);
vm.argcheck(v.isTable() || v.isNil(), 3, "table or nil expected"); vm.argcheck(v.isTable() || v.isNil(), 3, "table or nil expected");
t.luaSetMetatable(v); t = t.luaSetMetatable(v);
vm.resettop(); vm.resettop();
vm.pushlvalue(t); vm.pushlvalue(t);
break; break;

View File

@@ -267,7 +267,7 @@ public class LTable extends LValue {
} }
/** Valid for tables */ /** Valid for tables */
public LValue luaSetMetatable(LValue metatable) { public LTable luaSetMetatable(LValue metatable) {
if ( m_metatable != null && m_metatable.containsKey(TM_METATABLE) ) if ( m_metatable != null && m_metatable.containsKey(TM_METATABLE) )
throw new LuaErrorException("cannot change a protected metatable"); throw new LuaErrorException("cannot change a protected metatable");
if ( metatable == null || metatable.isNil() ) if ( metatable == null || metatable.isNil() )
@@ -279,10 +279,10 @@ public class LTable extends LValue {
return new LWeakTable(this); return new LWeakTable(this);
} }
this.m_metatable = t; this.m_metatable = t;
} else {
throw new LuaErrorException("not a table: "+metatable.luaGetTypeName());
} }
else return this;
throw new LuaErrorException("nil or table expected, got "+metatable.luaGetTypeName());
return null;
} }
public String toJavaString() { public String toJavaString() {

View File

@@ -177,9 +177,11 @@ public class LValue {
} }
/** Valid for tables /** Valid for tables
* @return TODO*/ * @param the new LTable, or null or LNil.NIL to reset the metatable to none
public LValue luaSetMetatable(LValue metatable) { * @return this if unchanged, or new LTable if copied using weak table
throw new LuaErrorException( "bad argument #1 to 'setmetatable' (table expected, got "+metatable.luaGetTypeName()+")"); */
public LTable luaSetMetatable(LValue metatable) {
throw new LuaErrorException( "cannot set metatable for "+metatable.luaGetTypeName());
} }
/** Valid for all types: return the int value identifying the type of this value */ /** Valid for all types: return the int value identifying the type of this value */

View File

@@ -1,5 +1,4 @@
-- normalized printing -- normalized printing
function eles(t,f) function eles(t,f)
f = f or pairs f = f or pairs