lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Have you tried basic debugging steps, like checking if the metatable is actually in the registry with the key provided by `obj->kind`?

Also, is there a reason to purposefully subject yourself to older software versions?

On 2023-12-01 20:31, Laurent FAILLIE wrote:
Hello,

I'm using Lua as embedded language for a C application, and I'm using
the following code to push an "object" in the state :

---

void pushSectionObject(lua_State *L, struct Section *obj){
    struct Section **s = (struct Section **)lua_newuserdata(L,
sizeof(struct Section *));
    if(!s)
        luaL_error(L, "No memory");

    *s = obj;

    luaL_getmetatable(L, obj->kind);
    lua_setmetatable(L, -2);
}
---

and the Lua side is

---

    local res = ''
    for s in Marcel.Sections()
    do
        res = res .. s:getName() ..'\t'.. s:getKind() ..'\t'..
            (s:isEnabled() and '1' or '0')
        if s.inError then
            res = res ..'\t'.. (s:inError() and '1' or '0')
        end
        res = res .. '\n'
    end

    ...

---

And this code is perfectly working with Lua 5.2 - 5.4 ... but not
using Lua 5.1 where I got following error

*E* [Marcel status] DPD :
...ets/Marcel/SimulProd/scripts/PublishMarcelStatus.lua:10: attempt to
index local 's' (a userdata value)

which is corresponding to s:getName() piece.

Any tip or idea ?

Thanks