lua-users home
lua-l archive

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


Whoops. The final check for NULL is reversed, of course. I should just copy-paste and be done with it. :)

On Tue, Feb 27, 2018 at 6:16 PM, Steven Johnson <steve@xibalbastudios.com> wrote:
Hi.

I'm writing some 5.1-based modules that uses lua_getupvalue and lua_setupvalue. By default, when building in release mode, the platform I'm targeting strips debug info, and the code in question breaks.

Looking into the Lua source suggested that the `if (name)` branch in those two functions is being skipped; basically, sizeupvalues is turning up 0 on me and aux_upvalue early-outs. (I see that in 5.2 and 5.3 aux_upvalue takes more pains to return a string, but it seems this must be accounting for a different scenario?)

With the following change to the Lua closure part

    Proto *p = f->l.p;
    const char * str;
    if (!(1 <= n && n <= f->l.nupvalues)) return NULL;
    *val = f->l.upvals[n-1]->v;
    str = p->sizeupvalues ? getstr(p->upvalues[n-1]) : NULL;
    return (str == NULL) ? str : "(*no name)";

I seem to be reliably getting upvalues again. However, I'd be interested to know if I'm violating any other assumptions.