diff --git a/README.html b/README.html index 6fc151f2..f1e4a3fb 100644 --- a/README.html +++ b/README.html @@ -3,8 +3,7 @@ Getting Started with LuaJ - - + @@ -53,7 +52,7 @@ Freely available under the terms of the Luaj is a lua interpreter based on the 5.1.x version of lua with the following goals in mind:

Performance

diff --git a/test/lua/metatags.lua b/test/lua/metatags.lua index 0c86b9d9..2cf2a677 100644 --- a/test/lua/metatags.lua +++ b/test/lua/metatags.lua @@ -43,6 +43,8 @@ local mt = { return 'mt.__tostring('..type(a)..','..type(b)..')' end, __metatable={}, + __index=buildop('index'), + __newindex=buildop('newindex'), } -- pcall a function and check for a pattern in the error string @@ -178,3 +180,21 @@ for i=1,#values do print( debug.setmetatable( a, nil ) ) end +print( '---- __index, __newindex' ) +values = { aboolean, anumber, afunction, athread } +for i=1,#values do + local a = values[i] + print( type(a), 'before', ecall( 'attempt to index', function() return a.foo end ) ) + print( type(a), 'before', ecall( 'attempt to index', function() return a[123] end ) ) + print( type(a), 'before', ecall( 'index', function() a.foo = 'bar' end ) ) + print( type(a), 'before', ecall( 'index', function() a[123] = 'bar' end ) ) + print( type(a), 'before', ecall( 'attempt to index', function() return a:foo() end ) ) + print( debug.setmetatable( a, mt ) ) + print( type(a), 'after', pcall( function() return a.foo end ) ) + print( type(a), 'after', pcall( function() return a[123] end ) ) + print( type(a), 'after', pcall( function() a.foo = 'bar' end ) ) + print( type(a), 'after', pcall( function() a[123] = 'bar' end ) ) + print( type(a), 'after', ecall( 'attempt to call', function() return a:foo() end ) ) + print( debug.setmetatable( a, nil ) ) +end +