| 961 | |
| 962 | |
| 963 | LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, |
| 964 | const char *chunkname, const char *mode) { |
| 965 | ZIO z; |
| 966 | int status; |
| 967 | lua_lock(L); |
| 968 | if (!chunkname) chunkname = "?"; |
| 969 | luaZ_init(L, &z, reader, data); |
| 970 | status = luaD_protectedparser(L, &z, chunkname, mode); |
| 971 | if (status == LUA_OK) { /* no errors? */ |
| 972 | LClosure *f = clLvalue(L->top - 1); /* get newly created function */ |
| 973 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ |
| 974 | /* get global table from registry */ |
| 975 | Table *reg = hvalue(&G(L)->l_registry); |
| 976 | const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); |
| 977 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ |
| 978 | setobj(L, f->upvals[0]->v, gt); |
| 979 | luaC_upvalbarrier(L, f->upvals[0]); |
| 980 | } |
| 981 | } |
| 982 | lua_unlock(L); |
| 983 | return status; |
| 984 | } |
| 985 | |
| 986 | |
| 987 | LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) { |
no test coverage detected