| 1044 | |
| 1045 | |
| 1046 | LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, |
| 1047 | const char *chunkname, const char *mode) { |
| 1048 | ZIO z; |
| 1049 | int status; |
| 1050 | lua_lock(L); |
| 1051 | if (!chunkname) chunkname = "?"; |
| 1052 | luaZ_init(L, &z, reader, data); |
| 1053 | status = luaD_protectedparser(L, &z, chunkname, mode); |
| 1054 | if (status == LUA_OK) { /* no errors? */ |
| 1055 | LClosure *f = clLvalue(s2v(L->top - 1)); /* get newly created function */ |
| 1056 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ |
| 1057 | /* get global table from registry */ |
| 1058 | Table *reg = hvalue(&G(L)->l_registry); |
| 1059 | const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); |
| 1060 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ |
| 1061 | setobj(L, f->upvals[0]->v, gt); |
| 1062 | luaC_barrier(L, f->upvals[0], gt); |
| 1063 | } |
| 1064 | } |
| 1065 | lua_unlock(L); |
| 1066 | return status; |
| 1067 | } |
| 1068 | |
| 1069 | |
| 1070 | LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) { |
no test coverage detected