From: Cyrill Gorcunov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tml <tarantool-patches@dev.tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH v20 6/7] box: implement box.lib module
Date: Wed, 7 Apr 2021 23:37:15 +0300 [thread overview]
Message-ID: <YG4X+zqggvDKvrqo@grain> (raw)
In-Reply-To: <02f89e4e-70ff-215f-7cc4-3331adbb3c94@tarantool.org>
On Wed, Apr 07, 2021 at 10:28:09PM +0200, Vladislav Shpilevoy wrote:
> >>
> >> Actually this snippet comes from popen code where
> >> we have wrappers on lua level and test for metamethods.
> >> While it doesn't hurt it makes no much sense in current
> >> code, thanks! Will drop.
> >
> > Heh, in real we need these to handle metamethods such as
> > "module:load". I added a comment into the code.
>
> For methods you need to use the metatype. It is defined as
> luaL_register_type(), where you can add methods, not just
> __index. The latter is more for, well, indexing. Getting an
> attribute, for example. See an example in lua/popen.c.
>
> Methods should not end up in __index.
Wait. Here is what I have now
void
box_lua_lib_init(struct lua_State *L)
{
func_hash = mh_strnptr_new();
if (func_hash == NULL)
panic("box.lib: Can't allocate func hash table");
static const struct luaL_Reg top_methods[] = {
{ "load", lbox_module_load },
{ NULL, NULL },
};
luaL_register(L, "box.lib", top_methods);
lua_pop(L, 1);
static const struct luaL_Reg lbox_module_methods[] = {
{ "unload", lbox_module_unload },
{ "load", lbox_module_load_func },
{ "__index", lbox_module_index },
{ "__serialize", lbox_module_serialize },
{ "__gc", lbox_module_gc },
{ NULL, NULL },
};
luaL_register_type(L, uname_lib, lbox_module_methods);
...
}
If I don't lookup for key being some nonnil value in __index
(ie those 5 lines) then module:load simply stop working. As
far as I understand the __index is called when Lua looks up
for a key in table. It sends "load" there and since it is
in metatable it executes lbox_module_load_func as it should.
What I'm missing?
next prev parent reply other threads:[~2021-04-07 20:37 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-02 12:34 [Tarantool-patches] [PATCH v20 0/7] box: implement box.lib Lua module Cyrill Gorcunov via Tarantool-patches
2021-04-02 12:34 ` [Tarantool-patches] [PATCH v20 1/7] box/schema: make sure hashes are created Cyrill Gorcunov via Tarantool-patches
2021-04-05 9:28 ` Serge Petrenko via Tarantool-patches
2021-04-05 9:50 ` Cyrill Gorcunov via Tarantool-patches
2021-04-05 10:13 ` Serge Petrenko via Tarantool-patches
2021-04-05 15:45 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-06 7:44 ` Cyrill Gorcunov via Tarantool-patches
2021-04-02 12:34 ` [Tarantool-patches] [PATCH v20 2/7] box/func: module_reload -- drop redundant argument Cyrill Gorcunov via Tarantool-patches
2021-04-05 10:23 ` Serge Petrenko via Tarantool-patches
2021-04-05 10:26 ` Serge Petrenko via Tarantool-patches
2021-04-05 10:31 ` Cyrill Gorcunov via Tarantool-patches
2021-04-02 12:34 ` [Tarantool-patches] [PATCH v20 3/7] box/func: fix modules functions restore Cyrill Gorcunov via Tarantool-patches
2021-04-05 10:53 ` Serge Petrenko via Tarantool-patches
2021-04-05 11:26 ` Cyrill Gorcunov via Tarantool-patches
2021-04-05 11:42 ` Serge Petrenko via Tarantool-patches
2021-04-05 15:47 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-06 8:38 ` Cyrill Gorcunov via Tarantool-patches
2021-04-06 20:02 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-06 20:42 ` Cyrill Gorcunov via Tarantool-patches
2021-04-02 12:34 ` [Tarantool-patches] [PATCH v20 4/7] box/module_cache: introduce modules subsystem Cyrill Gorcunov via Tarantool-patches
2021-04-05 12:34 ` Serge Petrenko via Tarantool-patches
2021-04-05 15:52 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-06 14:33 ` Cyrill Gorcunov via Tarantool-patches
2021-04-06 20:09 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-06 22:05 ` Cyrill Gorcunov via Tarantool-patches
2021-04-06 23:43 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-07 7:03 ` Cyrill Gorcunov via Tarantool-patches
2021-04-02 12:34 ` [Tarantool-patches] [PATCH v20 5/7] box/schema.func: switch to new module api Cyrill Gorcunov via Tarantool-patches
2021-04-05 15:56 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-02 12:34 ` [Tarantool-patches] [PATCH v20 6/7] box: implement box.lib module Cyrill Gorcunov via Tarantool-patches
2021-04-05 16:04 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-07 16:59 ` Cyrill Gorcunov via Tarantool-patches
2021-04-07 20:22 ` Cyrill Gorcunov via Tarantool-patches
2021-04-07 20:28 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-07 20:37 ` Cyrill Gorcunov via Tarantool-patches [this message]
2021-04-07 20:45 ` Cyrill Gorcunov via Tarantool-patches
2021-04-07 21:04 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-02 12:34 ` [Tarantool-patches] [PATCH v20 7/7] test: add box.lib test Cyrill Gorcunov via Tarantool-patches
2021-04-05 16:04 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-05 15:45 ` [Tarantool-patches] [PATCH v20 0/7] box: implement box.lib Lua module Vladislav Shpilevoy via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YG4X+zqggvDKvrqo@grain \
--to=tarantool-patches@dev.tarantool.org \
--cc=gorcunov@gmail.com \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v20 6/7] box: implement box.lib module' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox