| 990 | |
| 991 | |
| 992 | LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, |
| 993 | const char *chunkname, const char *mode) { |
| 994 | ZIO z; |
| 995 | int status; |
| 996 | lua_lock(L); |
| 997 | if (!chunkname) chunkname = "?"; |
| 998 | luaZ_init(L, &z, reader, data); |
| 999 | status = luaD_protectedparser(L, &z, chunkname, mode); |
| 1000 | if (status == LUA_OK) { /* no errors? */ |
| 1001 | LClosure *f = clLvalue(L->top - 1); /* get newly created function */ |
| 1002 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ |
| 1003 | /* get global table from registry */ |
| 1004 | Table *reg = hvalue(&G(L)->l_registry); |
| 1005 | const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); |
| 1006 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ |
| 1007 | setobj(L, f->upvals[0]->v, gt); |
| 1008 | luaC_upvalbarrier(L, f->upvals[0]); |
| 1009 | } |
| 1010 | } |
| 1011 | lua_unlock(L); |
| 1012 | return status; |
| 1013 | } |
| 1014 | |
| 1015 | |
| 1016 | LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) { |
no test coverage detected