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