| 1118 | |
| 1119 | |
| 1120 | LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, |
| 1121 | const char *chunkname, const char *mode) { |
| 1122 | ZIO z; |
| 1123 | TStatus status; |
| 1124 | lua_lock(L); |
| 1125 | if (!chunkname) chunkname = "?"; |
| 1126 | luaZ_init(L, &z, reader, data); |
| 1127 | status = luaD_protectedparser(L, &z, chunkname, mode); |
| 1128 | if (status == LUA_OK) { /* no errors? */ |
| 1129 | LClosure *f = clLvalue(s2v(L->top.p - 1)); /* get new function */ |
| 1130 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ |
| 1131 | /* get global table from registry */ |
| 1132 | TValue gt; |
| 1133 | getGlobalTable(L, >); |
| 1134 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ |
| 1135 | setobj(L, f->upvals[0]->v.p, >); |
| 1136 | luaC_barrier(L, f->upvals[0], >); |
| 1137 | } |
| 1138 | } |
| 1139 | lua_unlock(L); |
| 1140 | return APIstatus(status); |
| 1141 | } |
| 1142 | |
| 1143 | |
| 1144 | /* |
no test coverage detected