| 14287 | |
| 14288 | |
| 14289 | static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, |
| 14290 | const char *e) { |
| 14291 | lua_State *L = ms->L; |
| 14292 | switch (lua_type(L, 3)) { |
| 14293 | case LUA_TNUMBER: |
| 14294 | case LUA_TSTRING: { |
| 14295 | add_s(ms, b, s, e); |
| 14296 | return; |
| 14297 | } |
| 14298 | case LUA_TFUNCTION: { |
| 14299 | int n; |
| 14300 | lua_pushvalue(L, 3); |
| 14301 | n = push_captures(ms, s, e); |
| 14302 | lua_call(L, n, 1); |
| 14303 | break; |
| 14304 | } |
| 14305 | case LUA_TTABLE: { |
| 14306 | push_onecapture(ms, 0, s, e); |
| 14307 | lua_gettable(L, 3); |
| 14308 | break; |
| 14309 | } |
| 14310 | } |
| 14311 | if (!lua_toboolean(L, -1)) { /* nil or false? */ |
| 14312 | lua_pop(L, 1); |
| 14313 | lua_pushlstring(L, s, e - s); /* keep original text */ |
| 14314 | } |
| 14315 | else if (!lua_isstring(L, -1)) |
| 14316 | luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); |
| 14317 | luaL_addvalue(b); /* add result to accumulator */ |
| 14318 | } |
| 14319 | |
| 14320 | |
| 14321 | static int str_gsub (lua_State *L) { |
no test coverage detected