MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / callclosemth

Function callclosemth

extlibs/lua/src/lfunc.c:150–177  ·  view source on GitHub ↗

** Prepare and call a closing method. If status is OK, code is still ** inside the original protected call, and so any error will be handled ** there. Otherwise, a previous error already activated the original ** protected call, and so the call to the closing method must be ** protected here. (A status == CLOSEPROTECT behaves like a previous ** error, to also run the closing method in protected mo

Source from the content-addressed store, hash-verified

148** that won't be used again.
149*/
150static int callclosemth (lua_State *L, StkId level, int status) {
151 TValue *uv = s2v(level); /* value being closed */
152 if (likely(status == LUA_OK)) {
153 if (prepclosingmethod(L, uv, &G(L)->nilvalue)) /* something to call? */
154 callclose(L, NULL); /* call closing method */
155 else if (!l_isfalse(uv)) /* non-closable non-false value? */
156 varerror(L, level, "attempt to close non-closable variable '%s'");
157 }
158 else { /* must close the object in protected mode */
159 ptrdiff_t oldtop;
160 level++; /* space for error message */
161 oldtop = savestack(L, level + 1); /* top will be after that */
162 luaD_seterrorobj(L, status, level); /* set error message */
163 if (prepclosingmethod(L, uv, s2v(level))) { /* something to call? */
164 int newstatus = luaD_pcall(L, callclose, NULL, oldtop, 0);
165 if (newstatus != LUA_OK && status == CLOSEPROTECT) /* first error? */
166 status = newstatus; /* this will be the new error */
167 else {
168 if (newstatus != LUA_OK) /* suppressed error? */
169 luaE_warnerror(L, "__close metamethod");
170 /* leave original error (or nil) on top */
171 L->top = restorestack(L, oldtop);
172 }
173 }
174 /* else no metamethod; ignore this case and keep original error */
175 }
176 return status;
177}
178
179
180/*

Callers 1

luaF_closeFunction · 0.85

Calls 6

prepclosingmethodFunction · 0.85
callcloseFunction · 0.85
varerrorFunction · 0.85
luaD_seterrorobjFunction · 0.85
luaD_pcallFunction · 0.85
luaE_warnerrorFunction · 0.85

Tested by

no test coverage detected