lua-users home
lua-l archive

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


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