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