Fix equality test for userdata. Includes improved test7.lua.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user