simplify delegation of luaGetTable, luaSetTable.

This commit is contained in:
James Roseborough
2008-05-28 00:44:31 +00:00
parent 06afefebb5
commit 03224d7da3
2 changed files with 11 additions and 37 deletions

View File

@@ -202,32 +202,6 @@ public class LTable extends LValue {
array[key-1]: array[key-1]:
hashGet(LInteger.valueOf(key)) ); hashGet(LInteger.valueOf(key)) );
} }
/** Set a table value, including metatable processing.
*
* As an optimization for the common case, looks directly in the table first
* before delgating to the vm for metatable processing.
*/
public void luaSetTable(LuaState vm, LValue key, LValue val) {
if ( containsKey(key) || m_metatable == null || ! m_metatable.containsKey(TM_NEWINDEX) )
put( key, val );
else
vm.luaV_settable(this, key, val);
}
/** Get a table value, including metatable processing.
*
* As an optimization for the common case, looks directly in the table first
* before delgating to the vm for metatable processing.
*/
public LValue luaGetTable(LuaState vm, LValue key) {
LValue val = get(key);
return ! val.isNil() || m_metatable == null || ! m_metatable.containsKey(TM_INDEX)?
val:
vm.luaV_gettable(this, key);
}
/** Check for null, and convert to nilor leave alone /** Check for null, and convert to nilor leave alone
*/ */

View File

@@ -556,7 +556,7 @@ public class LuaState extends Lua {
b = LuaState.GETARG_Bx(i); b = LuaState.GETARG_Bx(i);
key = k[b]; key = k[b];
table = cl.env; table = cl.env;
val = table.luaGetTable(this, key); val = this.luaV_gettable(table, key);
this.stack[base + a] = val; this.stack[base + a] = val;
continue; continue;
} }
@@ -564,7 +564,7 @@ public class LuaState extends Lua {
b = LuaState.GETARG_B(i); b = LuaState.GETARG_B(i);
key = GETARG_RKC(k, i); key = GETARG_RKC(k, i);
table = this.stack[base + b]; table = this.stack[base + b];
val = table.luaGetTable(this, key); val = this.luaV_gettable(table, key);
this.stack[base + a] = val; this.stack[base + a] = val;
continue; continue;
} }
@@ -573,7 +573,7 @@ public class LuaState extends Lua {
key = k[b]; key = k[b];
val = this.stack[base + a]; val = this.stack[base + a];
table = cl.env; table = cl.env;
table.luaSetTable(this, key, val); this.luaV_settable(table, key, val);
continue; continue;
} }
case LuaState.OP_SETUPVAL: { case LuaState.OP_SETUPVAL: {
@@ -585,7 +585,7 @@ public class LuaState extends Lua {
key = GETARG_RKB(k, i); key = GETARG_RKB(k, i);
val = GETARG_RKC(k, i); val = GETARG_RKC(k, i);
table = this.stack[base + a]; table = this.stack[base + a];
table.luaSetTable(this, key, val); this.luaV_settable(table, key, val);
continue; continue;
} }
case LuaState.OP_NEWTABLE: { case LuaState.OP_NEWTABLE: {
@@ -597,7 +597,7 @@ public class LuaState extends Lua {
case LuaState.OP_SELF: { case LuaState.OP_SELF: {
rkb = GETARG_RKB(k, i); rkb = GETARG_RKB(k, i);
rkc = GETARG_RKC(k, i); rkc = GETARG_RKC(k, i);
val = rkb.luaGetTable(this, rkc); val = this.luaV_gettable(rkb, rkc);
this.stack[base + a] = val; this.stack[base + a] = val;
this.stack[base + a + 1] = rkb; this.stack[base + a + 1] = rkb;
continue; continue;
@@ -1408,7 +1408,7 @@ public class LuaState extends Lua {
*/ */
public void getfield(int index, LString k) { public void getfield(int index, LString k) {
LTable t = totable(index); LTable t = totable(index);
pushlvalue( t.luaGetTable(this, k) ); pushlvalue( this.luaV_gettable(t, k) );
} }
/** /**
@@ -1424,7 +1424,7 @@ public class LuaState extends Lua {
* </pre> * </pre>
*/ */
public void getglobal(String s) { public void getglobal(String s) {
pushlvalue( _G.luaGetTable(this, new LString(s)) ); pushlvalue( this.luaV_gettable(_G, new LString(s)) );
} }
/** /**
@@ -1463,7 +1463,7 @@ public class LuaState extends Lua {
public void gettable(int index) { public void gettable(int index) {
LValue t = totable(index); LValue t = totable(index);
LValue k = poplvalue(); LValue k = poplvalue();
pushlvalue( t.luaGetTable(this, k) ); pushlvalue( this.luaV_gettable(t, k) );
} }
/** /**
@@ -2077,7 +2077,7 @@ public class LuaState extends Lua {
*/ */
public void setfield(int index, LString k) { public void setfield(int index, LString k) {
LTable t = totable(index); LTable t = totable(index);
t.luaSetTable(this, k, poplvalue()); this.luaV_settable(t, k, poplvalue());
} }
/** /**
@@ -2094,7 +2094,7 @@ public class LuaState extends Lua {
* </pre> * </pre>
*/ */
public void setglobal(String name) { public void setglobal(String name) {
_G.luaSetTable(this, new LString(name), poplvalue()); this.luaV_settable(_G, new LString(name), poplvalue());
} }
/** /**
@@ -2134,7 +2134,7 @@ public class LuaState extends Lua {
LTable t = totable(index); LTable t = totable(index);
LValue v = poplvalue(); LValue v = poplvalue();
LValue k = poplvalue(); LValue k = poplvalue();
t.luaSetTable(this, k, v); this.luaV_settable(t, k, v);
} }
/** /**