diff --git a/src/main/java/lua/value/LTable.java b/src/main/java/lua/value/LTable.java index 574dc55a..302fc556 100644 --- a/src/main/java/lua/value/LTable.java +++ b/src/main/java/lua/value/LTable.java @@ -223,11 +223,10 @@ public class LTable extends LValue { } public void luaSetTable(VM vm, LValue table, LValue key, LValue val) { - if ( !containsKey( key ) && m_metatable != null ) { - super.luaSetTable( vm, table, key, val ); - } else { - put(key, val); - } + if ( (!containsKey( key )) && m_metatable != null && m_metatable.containsKey(TM_NEWINDEX) ) + m_metatable.get(TM_NEWINDEX).luaSetTable( vm, table, key, val ); + else + put(key,val); } /** diff --git a/src/test/java/lua/LuaJTest.java b/src/test/java/lua/LuaJTest.java index 74e1a9d2..520b9445 100644 --- a/src/test/java/lua/LuaJTest.java +++ b/src/test/java/lua/LuaJTest.java @@ -80,6 +80,10 @@ public class LuaJTest extends TestCase { runTest( "setlist" ); } + public void testSimpleMetatables() throws IOException, InterruptedException { + runTest( "simplemetatables" ); + } + public void testStrLib() throws IOException, InterruptedException { runTest( "strlib" ); } diff --git a/src/test/res/simplemetatables.lua b/src/test/res/simplemetatables.lua new file mode 100644 index 00000000..0a9c05e1 --- /dev/null +++ b/src/test/res/simplemetatables.lua @@ -0,0 +1,14 @@ +-- The purpose of this test case is to check +-- that certain simple metatable operations work properly +t = { b='bbb' } +t.__index = t +u = {} +setmetatable( u, t ) +u.c = 'ccc' + +print( 't.a', t.a ) +print( 'u.a', u.a ) +print( 't.b', t.b ) +print( 'u.b', u.b ) +print( 't.c', t.c ) +print( 'u.c', u.c ) diff --git a/src/test/res/simplemetatables.luac b/src/test/res/simplemetatables.luac new file mode 100644 index 00000000..29ab1658 Binary files /dev/null and b/src/test/res/simplemetatables.luac differ