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:
Java-centric implementation of lua vm built to leverage standard Java features.
-
Lightweight to allow for small, fast interpretation of lua bytecode.
+
Lightweight, high performance execution of lua.
Multi-platform to be able to run on JME, JSE, or JEE environments.
Complete set of libraries and tools for integration into real-world projects.
Dependable due to sufficient unit testing of vm and library features.
@@ -71,7 +70,7 @@ at improving on the 1.0 vm in the following aspects.
Improved class and package naming conventions.
Improved unit tests of core classes.
Improved quality due to major redesign and rewrite of core elements.
-
Improved weak table support, including weak keys.
+
More complete implementation including weak keys and values, and all metatags.
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
+