Fix equality test for userdata. Includes improved test7.lua.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<project default="all">
|
<project default="all">
|
||||||
<property name="version" value="0.15"/>
|
<property name="version" value="0.16"/>
|
||||||
|
|
||||||
<target name="clean">
|
<target name="clean">
|
||||||
<delete dir="build"/>
|
<delete dir="build"/>
|
||||||
|
|||||||
@@ -55,4 +55,10 @@ public class LUserData extends LValue {
|
|||||||
public Object toJavaInstance() {
|
public Object toJavaInstance() {
|
||||||
return m_instance;
|
return m_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean luaBinCmpUnknown( int opcode, LValue lhs ) {
|
||||||
|
if ( opcode == Lua.OP_EQ )
|
||||||
|
return lhs.equals( this );
|
||||||
|
return super.luaBinCmpUnknown( opcode, lhs );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ package org.luaj.sample;
|
|||||||
|
|
||||||
public class SampleClass {
|
public class SampleClass {
|
||||||
|
|
||||||
|
public Object o;
|
||||||
public String s;
|
public String s;
|
||||||
public String t;
|
public String t;
|
||||||
|
|
||||||
@@ -41,4 +42,12 @@ public class SampleClass {
|
|||||||
public void setS(String s) {
|
public void setS(String s) {
|
||||||
this.s = s;
|
this.s = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setObj(Object o) {
|
||||||
|
this.o = o;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getObj() {
|
||||||
|
return o;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
java.lang.Object@b1b4c3
|
java.lang.Object@xxxxxx
|
||||||
SampleClass@72ffb
|
org.luaj.sample.SampleClass@xxxxxx
|
||||||
Hello
|
Hello
|
||||||
Hello
|
Hello
|
||||||
|
true
|
||||||
World
|
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")
|
obj = luajava.newInstance("java.lang.Object")
|
||||||
print( obj )
|
print( fixhash( tostring(obj) ) )
|
||||||
|
|
||||||
obj = luajava.newInstance("org.luaj.sample.SampleClass")
|
sample = luajava.newInstance("org.luaj.sample.SampleClass")
|
||||||
print( obj )
|
print( fixhash( tostring(sample) ) )
|
||||||
obj.s = "Hello"
|
sample.s = "Hello"
|
||||||
print( obj.s )
|
print( sample.s )
|
||||||
print( obj:getS() )
|
print( sample:getS() )
|
||||||
|
|
||||||
obj:setS( "World" )
|
sample:setObj(obj)
|
||||||
print( obj.s )
|
print( obj == sample:getObj() )
|
||||||
|
|
||||||
|
sample:setS( "World" )
|
||||||
|
print( sample.s )
|
||||||
|
|
||||||
math = luajava.bindClass("java.lang.Math")
|
math = luajava.bindClass("java.lang.Math")
|
||||||
print("Square root of 9 is", math:sqrt(9.0))
|
print("Square root of 9 is", math:sqrt(9.0))
|
||||||
|
|||||||
Reference in New Issue
Block a user