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