Fix getmetatable when metatable contains __metatable tag
This commit is contained in:
@@ -175,8 +175,13 @@ public class BaseLib extends LFunction {
|
|||||||
vm.resettop();
|
vm.resettop();
|
||||||
vm.pushnil();
|
vm.pushnil();
|
||||||
} else {
|
} else {
|
||||||
vm.insert(1);
|
vm.replace(1);
|
||||||
vm.settop(1);
|
vm.settop(1);
|
||||||
|
vm.getfield(-1,LValue.TM_METATABLE);
|
||||||
|
if ( vm.isnil(-1) )
|
||||||
|
vm.pop(1);
|
||||||
|
else
|
||||||
|
vm.remove(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ public class LTable extends LValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Valid for tables */
|
/** Valid for tables */
|
||||||
public org.luaj.vm.LTable luaGetMetatable() {
|
public LTable luaGetMetatable() {
|
||||||
return this.m_metatable;
|
return this.m_metatable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -899,7 +899,11 @@ public class LuaState extends Lua {
|
|||||||
return calls[cc-callStackDepth];
|
return calls[cc-callStackDepth];
|
||||||
}
|
}
|
||||||
|
|
||||||
private LValue mtget(LValue t, LString tag) {
|
private void indexError(LValue nontable) {
|
||||||
|
error( "attempt to index ? (a "+nontable.luaGetTypeName()+" value)", 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
private LValue luaV_getmetafield(LValue t, LString tag) {
|
||||||
LTable mt = t.luaGetMetatable();
|
LTable mt = t.luaGetMetatable();
|
||||||
if ( mt == null )
|
if ( mt == null )
|
||||||
return null;
|
return null;
|
||||||
@@ -907,10 +911,6 @@ public class LuaState extends Lua {
|
|||||||
return h.isNil()? null: h;
|
return h.isNil()? null: h;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void indexError(LValue nontable) {
|
|
||||||
error( "attempt to index ? (a "+nontable.luaGetTypeName()+" value)", 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
public LValue luaV_gettable(LValue table, LValue key) {
|
public LValue luaV_gettable(LValue table, LValue key) {
|
||||||
LValue h=LNil.NIL,t=table;
|
LValue h=LNil.NIL,t=table;
|
||||||
for ( int loop=0; loop<MAXTAGLOOP; loop++ ) {
|
for ( int loop=0; loop<MAXTAGLOOP; loop++ ) {
|
||||||
@@ -919,12 +919,12 @@ public class LuaState extends Lua {
|
|||||||
if ( !v.isNil() ) {
|
if ( !v.isNil() ) {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
h = mtget(t, LTable.TM_INDEX);
|
h = luaV_getmetafield(t, LTable.TM_INDEX);
|
||||||
if ( h == null ) {
|
if ( h == null ) {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
h = mtget(t, LTable.TM_INDEX);
|
h = luaV_getmetafield(t, LTable.TM_INDEX);
|
||||||
if ( h == null ) {
|
if ( h == null ) {
|
||||||
indexError(t);
|
indexError(t);
|
||||||
}
|
}
|
||||||
@@ -961,13 +961,13 @@ public class LuaState extends Lua {
|
|||||||
lt.put(key, val);
|
lt.put(key, val);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
h = mtget(t, LTable.TM_NEWINDEX);
|
h = luaV_getmetafield(t, LTable.TM_NEWINDEX);
|
||||||
if ( h == null ) {
|
if ( h == null ) {
|
||||||
lt.put(key, val);
|
lt.put(key, val);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
h = mtget(t, LTable.TM_NEWINDEX);
|
h = luaV_getmetafield(t, LTable.TM_NEWINDEX);
|
||||||
if ( h == null ) {
|
if ( h == null ) {
|
||||||
indexError(t);
|
indexError(t);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user