Fix equality test for userdata. Includes improved test7.lua.

This commit is contained in:
Ian Farmer
2008-01-11 07:56:42 +00:00
parent 9f9f31b969
commit 2461b46908
5 changed files with 37 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
java.lang.Object@b1b4c3
SampleClass@72ffb
java.lang.Object@xxxxxx
org.luaj.sample.SampleClass@xxxxxx
Hello
Hello
true
World
Square root of 9 is 3.0
Square root of 9 is 3

View File

@@ -1,14 +1,21 @@
local function fixhash(msg)
return string.gsub(msg, "@(%x+)", function(s) return "@"..(string.rep("x", 6)) end)
end
obj = luajava.newInstance("java.lang.Object")
print( obj )
print( fixhash( tostring(obj) ) )
obj = luajava.newInstance("org.luaj.sample.SampleClass")
print( obj )
obj.s = "Hello"
print( obj.s )
print( obj:getS() )
sample = luajava.newInstance("org.luaj.sample.SampleClass")
print( fixhash( tostring(sample) ) )
sample.s = "Hello"
print( sample.s )
print( sample:getS() )
obj:setS( "World" )
print( obj.s )
sample:setObj(obj)
print( obj == sample:getObj() )
sample:setS( "World" )
print( sample.s )
math = luajava.bindClass("java.lang.Math")
print("Square root of 9 is", math:sqrt(9.0))