From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 8DB106EC5D; Thu, 8 Apr 2021 00:05:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8DB106EC5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617829501; bh=b3IAL55OFFEeCLxe3Z9NXhR3CoRF83Ile3K32quXAIE=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ZtLOgvzNaavvSsFffzk9BvKmxYcLeXnOUZpzd51e4SKekF523FmA7R8oDLW7TTGac K6SRNOIlU+0/ggyaGgYhPEuCvoDRrT8a9DqcfpcaA/57DTjfHg2Cf434bwRE3UsbO8 ovGBt9tnnEFeGvgIN3891ZWy+nrSAZcT0jeCUI80= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 01F856EC5D for ; Thu, 8 Apr 2021 00:04:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 01F856EC5D Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lUFMA-0000Sy-DG; Thu, 08 Apr 2021 00:04:58 +0300 To: Cyrill Gorcunov Cc: tml References: <20210402123420.885834-1-gorcunov@gmail.com> <20210402123420.885834-7-gorcunov@gmail.com> <8d3a4d20-2887-7423-777f-2af808b65495@tarantool.org> <02f89e4e-70ff-215f-7cc4-3331adbb3c94@tarantool.org> Message-ID: Date: Wed, 7 Apr 2021 23:04:57 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD912A3E3D5D4B49FC1CC94992626AE9EFE0A9192A937C653EE00894C459B0CD1B97E66C99B49A45BD73498C4F799CC86729ABBFAA3F8430E923E3E97FC8DFF7329 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F16C4DE526EFCC04EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637217E865CDB7D48CC8638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2C41A051AF9F48FDEDAD637A0F1A52B0698738A72DB41484ED2E47CDBA5A96583C09775C1D3CA48CFCA5A41EBD8A3A0199FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C327ED053E960B195E117882F4460429728AD0CFFFB425014E868A13BD56FB6657E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637553F28B1F14F2446EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A5BAB9819C108CE8AED73E594486CEB26AD5FB8B8B3F09555AD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F507C2EA0814E4508C46D59016DBFFF745052FD59C8E085A5A5530748C001574E2F6B06E6D2B05581D7E09C32AA3244C7E23CBEDFA55656C2DFA40A6AEEB7EC830363D8B7DA7DD44729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioju+jaMfvANXrDL+Jo/yXH5A== X-Mailru-Sender: 689FA8AB762F73936BC43F508A06382200F9EB34E4C59E450E1C3A634EBEC9693841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v20 6/7] box: implement box.lib module X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On 07.04.2021 22:45, Cyrill Gorcunov via Tarantool-patches wrote: > 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 Yeah, I see now. I thought that __index is called only for the not present fields. And it is true, but only if they are real fields of a concrete object, not metafields. In this example: mt = { call = function() print('do call') end, __index = function(self, key) print(key) end, } t = setmetatable({}, mt) an attempt to do t.call or t:call() always goes through __index. While in this example: mt = { __index = function(self, key) print(key) end, } t = setmetatable({call = function() print('do call') end}, mt) the same code bypasses __index. Your case is the first one, and it seems we can't do anything about it so far.