Team-CC-Corp / JVML-JIT

A continuation of JVML which JITs Java bytecode to Lua bytecode rather than interpreting.
MIT License
30 stars 4 forks source link

Compare objects for equality in Lua #55

Closed Turakar closed 9 years ago

Turakar commented 9 years ago

I'm currently developing a Map based upon Lua tables, but there's currently a problem: The map javadoc says that two keys are considered the same if o1.equals(o2) yields true. This is easy to implement on java, but it's hard to implement in Lua, as you can't call Object.equals(). Is there a workaround or could this be fixed (we're actually talking in that case about calling Java code from Lua, and I don't know if this is a good thing...)

ElvishJerricco commented 9 years ago

Calling java code from lua is fairly easy.

findMethod(obj[1] --[[class]], "equals(Ljava/lang/Object;)Z" --[[method name]])[1](obj, otherObj)
ElvishJerricco commented 9 years ago

Just make sure to check for thrown exceptions.

local method = findMethod(obj[1] --[[class]], "equals(Ljava/lang/Object;)Z" --[[method name]])
local retVal, exception = method[1](obj, otherObj)
if exception then
    -- handle thrown exception, typically by throwing
    return nil, exception
end
-- do stuff with retVal
Turakar commented 9 years ago

Thx