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);
LValue v = vm.checkany(3);
vm.argcheck(v.isTable() || v.isNil(), 3, "table or nil expected");
t.luaSetMetatable(v);
t = t.luaSetMetatable(v);
vm.resettop();
vm.pushlvalue(t);
break;

View File

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

View File

@@ -177,9 +177,11 @@ public class LValue {
}
/** Valid for tables
* @return TODO*/
public LValue luaSetMetatable(LValue metatable) {
throw new LuaErrorException( "bad argument #1 to 'setmetatable' (table expected, got "+metatable.luaGetTypeName()+")");
* @param the new LTable, or null or LNil.NIL to reset the metatable to none
* @return this if unchanged, or new LTable if copied using weak table
*/
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 */

View File

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