Hum, another thing strange.
I tested the following code
local q3 = SelFIFO.Find("myFifo")
local mt = getmetatable(q3)
print('--- mt ----')
for k,v in pairs(mt) do print(k,v) end
print('--- index ---')
print(mt.__index)
for k,v in pairs(mt.__index) do print(k,v) end
But it's output is :
--- mt ----
dump function: 0x13e7270
list function: 0x13e7290
Pop function: 0x13e4188
__index table: 0x13e7058
Push function: 0x13e4148
--- index ---
nil
*E* (launch) Selenites/FIFO.sel:31: bad argument #1 to 'pairs' (table expected, got nil)
How it's possible to got something during table scanning but being unable to retrieve it ?
The C code behind is the following (lua 5.1) :
static const struct luaL_reg SelFFLib [] = {
{"Create", sff_create},
{"Find", sff_find},
{NULL, NULL}
};
static const struct luaL_reg SelFFM [] = {
{"Push", sff_push},
{"Pop", sff_pop},
/* {"HowMany", sff_HowMany}, */
{"dump", sff_dump},
{"list", sff_list},
{NULL, NULL}
};
void init_SelFIFO( lua_State *L ){ /* CAUTION : called also when thread are created */
luaL_newmetatable(L, "SelFIFO");
lua_pushstring(L, "__index");
lua_pushvalue(L, -2);
lua_settable(L, -3); /* metatable.__index = metatable */
luaL_register(L, NULL, SelFFM);
luaL_register(L,"SelFIFO", SelFFLib);
}
And this function is called by :
lua_State *tstate = luaL_newstate(); /* Initialise new state for the thread */
assert(tstate);
luaL_openlibs( tstate );
init_shared_Lua( tstate );
init_SelFIFO( tstate );
Thanks.
Laurent
Le Mercredi 28 juin 2017 17h04, Laurent FAILLIE <l_faillie@yahoo.com> a écrit :
I tried
local q3 = SelFIFO.Find("myFifo")
local mt = getmetatable(q3)
mt.__index = mt
q3:dump()
but the result is the same :
Selenites/FIFO.sel:27: attempt to call method 'dump' (a nil value)
Anyway, it's strange it's working in my main thread and not the slave one : state initialization code is strictly the same.
Best regards,
Laurent