Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LTR Romtables don't support __call metamethod #143

Open
drauschenbach opened this issue Nov 12, 2018 · 1 comment
Open

LTR Romtables don't support __call metamethod #143

drauschenbach opened this issue Nov 12, 2018 · 1 comment

Comments

@drauschenbach
Copy link

Use of LTR __metatable docs are thin, and I'm doing my best to work from the source code.

First, I'm surprised that the metatable map returned is always self, rather than the one I'm pointing at via an LRO_ROVAL.

Given:

const LUA_REG_TYPE mymodule_metatable_map[] = {
  { LSTRKEY("__call")  , LFUNCVAL(myCallMetamethodHandler) },
  { LNILKEY, LNILVAL }
};

const LUA_REG_TYPE mymodule_map[] = {
  { LSTRKEY("__metatable"), LRO_ROVAL(mymodule_metatable_map) },
  { LNILKEY, LNILVAL }
};

It seems to ignore the metatable and registers a metatable of self:

m = require 'mymodule'
print(m)
romtable: 0x805c9b8

for k,v in pairs(m) do print(k,v) end
__metatable     romtable: 0x805c9b8

print(getmetatable(m))
romtable: 0x805c9b8

for k,v in pairs(m) do print(k,v) end
__metatable     romtable: 0x805c9b8

So given that, I went back to a single consolidated romtable that uses itself as a metatable:

const LUA_REG_TYPE mymodule_map[] = {
  { LSTRKEY("__call") , LFUNCVAL (myCallMetamethodHandler) },
  { LSTRKEY("__metatable"), LRO_ROVAL(mymodule_map) },
  { LNILKEY, LNILVAL }
};

And __call seems to get ignored:

> m('foo')
stdin:1: attempt to call global 'm' (a romtable value)
@drauschenbach
Copy link
Author

drauschenbach commented Nov 12, 2018

I'm basically looking for a way to register the url.parse module, which returns a function rather than a table. Other popular modules do that as well, which is why I'm looking for the generalized solution. I've filed an independent issue #144.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant