MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / generic_reader

Function generic_reader

3rd/lua-5.4.3/src/lbaselib.c:349–363  ·  view source on GitHub ↗

** Reader for generic 'load' function: 'lua_load' uses the ** stack for internal stuff, so the reader cannot change the ** stack top. Instead, it keeps its resulting string in a ** reserved slot inside the stack. */

Source from the content-addressed store, hash-verified

347** reserved slot inside the stack.
348*/
349static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
350 (void)(ud); /* not used */
351 luaL_checkstack(L, 2, "too many nested functions");
352 lua_pushvalue(L, 1); /* get function */
353 lua_call(L, 0, 1); /* call it */
354 if (lua_isnil(L, -1)) {
355 lua_pop(L, 1); /* pop result */
356 *size = 0;
357 return NULL;
358 }
359 else if (l_unlikely(!lua_isstring(L, -1)))
360 luaL_error(L, "reader function must return a string");
361 lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
362 return lua_tolstring(L, RESERVEDSLOT, size);
363}
364
365
366static int luaB_load (lua_State *L) {

Callers

nothing calls this directly

Calls 5

luaL_checkstackFunction · 0.85
lua_pushvalueFunction · 0.85
lua_isstringFunction · 0.85
luaL_errorFunction · 0.85
lua_tolstringFunction · 0.85

Tested by

no test coverage detected