[Tarantool-patches] [PATCH v20 6/7] box: implement box.lib module

Cyrill Gorcunov gorcunov at gmail.com
Wed Apr 7 23:45:57 MSK 2021


On Wed, Apr 07, 2021 at 11:37:15PM +0300, Cyrill Gorcunov wrote:
...
> 
> 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?

Look into fiber code

static const struct luaL_Reg lbox_fiber_meta [] = {
	...
	{"__serialize", lbox_fiber_serialize},
	{"__tostring", lbox_fiber_tostring},
	{"join", lbox_fiber_join},
	{"set_joinable", lbox_fiber_set_joinable},
	{"wakeup", lbox_fiber_wakeup},
	{"__index", lbox_fiber_index},
	{NULL, NULL}
};

static int
lbox_fiber_index(struct lua_State *L)
{
	if (lua_gettop(L) < 2)
		return 0;
	if (lua_isstring(L, 2) && strcmp(lua_tostring(L, 2), "storage") == 0)
		return lbox_fiber_storage(L);

-->	/* Get value from metatable */
	lua_getmetatable(L, 1);
	lua_pushvalue(L, 2);
	lua_gettable(L, -2);
	return 1;
}

So I need to do the same

	Cyrill


More information about the Tarantool-patches mailing list