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