hoelzro/inline-lua

Lua Objects -> Perl Objects?

unhandyandy opened this issue · 3 comments

Can I define an object with a method in Inline Lua and then call it in Perl?

For example, should I be able to have

__Lua__
local thing = {}
thing.mt = {__index = thing}
function thing.action( x )
    return x + 1
end

and then call it in perl by thing->action( 3 )?

Or maybe by

&{$thing->{action}}(3)

@unhandyandy This is not currently possible; IIRC, Inline::Lua marshals objects (including tables) between the Perl and Lua environments, so tables lose their metatable. You can, however, do the $object->{method_name}->(@args) trick, as long as method_name is a key of $object itself and not accessed via a metatable.

OK, thanks.