Userdata change bug

Issue #4 duplicate
Ilya Shurumov
created an issue

Userdata changes on return. It causes when class/struct member is declared first which type is also exported to Lua. Adding some "padding" variable before this member will 'fix' that

It took several hours to find the cause of this problem because of strange behaviour. I have tried proxies, but the same result appear.

Maybe it's a lua bug and should be redirected to Lua issue tracker (i'm novice), i'm using lua 5.2 in a couple with OOLua 2.0.0 beta

next code reproduces problem:

struct foo
{
    int ivar;
    float fvar;
};

OOLUA_PROXY(foo)
    OOLUA_MGET_MSET(ivar)
    OOLUA_MGET_MSET(fvar)
OOLUA_PROXY_END

OOLUA_EXPORT_FUNCTIONS(foo, set_ivar, set_fvar)
OOLUA_EXPORT_FUNCTIONS_CONST(foo, get_ivar, get_fvar)

class bar
{
public:
    //int test; // uncomment and no bug will happen

    foo* GetFoo() {return &m_foo;}

    foo m_foo;
};

OOLUA_PROXY(bar)
    OOLUA_MEM_FUNC(foo*, GetFoo);
OOLUA_PROXY_END

OOLUA_EXPORT_FUNCTIONS(bar, GetFoo)
OOLUA_EXPORT_FUNCTIONS_CONST(bar)

...

OOLUA::register_class<foo>(state);
OOLUA::register_class<bar>(state);

Lua code:

local a = bar.new()
local b = a:GetFoo()
local test = a.ivar -- maybe it should be 'nil'
local c = a:GetFoo() -- fails, but should not

output:

test1.lua:4: attempt to call method 'GetFoo' (a nil value)

Comments (6)

  1. Liam Devine repo owner

    Ilya please try the code from the OOLua-2 repository as this looks like issue #2 which has been fixed. I will close the issue but it you still have an issue please re-open it.

  2. Log in to comment