rzel / kahlua

Automatically exported from code.google.com/p/kahlua
0 stars 0 forks source link

metatable __call into java has wrong parameters #25

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
consider this Lua code:
"""
function f (tbl, oneparam)
  return tbl["foo"] + oneparam
end

t = {foo=9}
mt = {__call = f}
setmetatable(t,mt)

print(f(t, 3))
print(t(3))
"""
this works fine and both print statements print "12"

if function "f" is implemented in Java, this fails, because in the metatable 
call, "tbl" is parameter -1, not 0.

a naive patch is attached, but it is still bad - after that patch, the return 
values are shifted
see the test for more details

Original issue reported on code.google.com by matej...@gmail.com on 20 Jun 2010 at 12:57

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the report, I'll take a closer look at this as soon as I have some 
more free time.

Could you explain what you mean is wrong with the patch? How are the return 
values shifted?

Original comment by kristofer.karlsson@gmail.com on 20 Jun 2010 at 8:11

GoogleCodeExporter commented 9 years ago
well, this is where i got lost, so i reported it to you with an incompete patch 
;e)

for code equivalent to this:
function manyreturns()
  return 1,2,3
end
a,b,c = manyreturns()
the values of a,b,c are 2,3,nil respectively

Original comment by matej...@gmail.com on 20 Jun 2010 at 8:34

GoogleCodeExporter commented 9 years ago
Thanks! That clarifies it.

Original comment by kristofer.karlsson@gmail.com on 20 Jun 2010 at 8:41

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r236.

Original comment by kristofer.karlsson@gmail.com on 21 Jun 2010 at 6:50

GoogleCodeExporter commented 9 years ago
Fixed in subversion.
Your patch was nearly correct, it just needed some extra fixes in the callJava 
method.

See the full diff here:
http://code.google.com/p/kahlua/source/detail?r=236

Fortunately, it seems that the bug only affected __call operations with java 
functions and nothing else (which is probably why it wasn't found earlier).

Original comment by kristofer.karlsson@gmail.com on 21 Jun 2010 at 6:52