Mercurial Hosting > luan
diff core/src/luan/impl/SetTableEntry.java @ 404:d55e873e1f0d
metatables now only apply to tables
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 29 Apr 2015 07:04:40 -0600 |
parents | 05eb2837ddbf |
children | 3e68917a0dc6 |
line wrap: on
line diff
--- a/core/src/luan/impl/SetTableEntry.java Tue Apr 28 22:49:33 2015 -0600 +++ b/core/src/luan/impl/SetTableEntry.java Wed Apr 29 07:04:40 2015 -0600 @@ -5,6 +5,7 @@ import luan.Luan; import luan.LuanFunction; import luan.LuanSource; +import luan.modules.JavaLuan; final class SetTableEntry extends CodeImpl implements Settable { @@ -22,10 +23,9 @@ } private void newindex(LuanStateImpl luan,Object t,Object key,Object value) throws LuanException { - Object h; if( t instanceof LuanTable ) { LuanTable table = (LuanTable)t; - h = luan.getHandler("__newindex",table); + Object h = luan.getHandler("__newindex",table); if( h==null || table.get(key)!=null ) { try { table.put(key,value); @@ -36,17 +36,15 @@ } return; } - } else { - h = luan.getHandler("__newindex",t); - if( h==null ) - throw luan.bit(se).exception( "attempt to index '"+tableExpr.se().text()+"' (a " + Luan.type(t) + " value)" ); + if( h instanceof LuanFunction ) { + LuanFunction fn = (LuanFunction)h; + luan.bit(se).call(fn,"__newindex",new Object[]{t,key,value}); + return; + } + newindex(luan,h,key,value); } - if( h instanceof LuanFunction ) { - LuanFunction fn = (LuanFunction)h; - luan.bit(se).call(fn,"__newindex",new Object[]{t,key,value}); - return; - } - newindex(luan,h,key,value); + if( !JavaLuan.__newindex(luan,t,key,value) ) + throw luan.bit(se).exception( "attempt to index '"+tableExpr.se().text()+"' (a " + Luan.type(t) + " value)" ); } }