lua-users home
lua-l archive

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


It was reported by Vladimir Strakh 17 hours ago, in the mail titled
"Lua 5.2 load(...., env) returning table instead of function", and
comfirmed by Roberto 14 hours ago :-)

2012/11/29 云风 <cloudwu@gmail.com>:
> There is no upvalue (_ENV) in a binary chunk sometimes.
>
> For example,
>
> function test()
> return 1
> end
> print(type(load(string.dump(test),nil,"b",_ENV)))
>
> --> table
>
> string.dump(test) has no upvalue, load will return a table instead of a
> function.
>
> I guess check the return value of lua_setupvalue would be better:
>
>   if (status == LUA_OK && top >= 4) {  /* is there an 'env' argument */
>     const char *env;
>     lua_pushvalue(L, 4);  /* environment for loaded function */
>     env = lua_setupvalue(L, -2, 1);  /* set it as 1st upvalue */
>     if (env == NULL) {
>         lua_pop(L,1);
>     }
>   }
>
>   The same problem in luaB_loadfile.
>
> --
> http://blog.codingnow.com



--
regards,
Xavier Wang.