lua-users home
lua-l archive

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


2013/2/6 YuanLin <yuanlin2008@hotmail.com>:
> ===============
> local a;
> a = function() end;
> ===============
> The code generated was:
> ===============
>         1       [1]     LOADNIL         0 0
>         2       [2]     CLOSURE         1 0     ; 0x80049078
>         3       [2]     MOVE            0 1
>         4       [2]     RETURN          0 1
> ===============
> It seemed that we can not store the closure directly to local var "a".
> Why not keep the expdesc as "VRELOCABLE" and patch the target register
> later?

The bytecode does store the function in "a", only the comment does
not help you to know that.

Local variables are mere aliases for VM registers.

You should use "luac -l -l". That shows you the constants, locals,
upvalues and function prototypes too, not only the disassembly.

You'll see that "a" is register 0. The closure is generated in
register 1, so the MOVE instruction does store the closure in "a".