** 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. */
| 11159 | ** reserved slot inside the stack. |
| 11160 | */ |
| 11161 | static const char *generic_reader (lua_State *L, void *ud, size_t *size) { |
| 11162 | (void)ud; /* to avoid warnings */ |
| 11163 | luaL_checkstack(L, 2, "too many nested functions"); |
| 11164 | lua_pushvalue(L, 1); /* get function */ |
| 11165 | lua_call(L, 0, 1); /* call it */ |
| 11166 | if (lua_isnil(L, -1)) { |
| 11167 | *size = 0; |
| 11168 | return NULL; |
| 11169 | } |
| 11170 | else if (lua_isstring(L, -1)) { |
| 11171 | lua_replace(L, 3); /* save string in a reserved stack slot */ |
| 11172 | return lua_tolstring(L, 3, size); |
| 11173 | } |
| 11174 | else luaL_error(L, "reader function must return a string"); |
| 11175 | return NULL; /* to avoid warnings */ |
| 11176 | } |
| 11177 | |
| 11178 | |
| 11179 | static int luaB_load (lua_State *L) { |
nothing calls this directly
no test coverage detected