| 702 | |
| 703 | |
| 704 | static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, |
| 705 | const char *e, int tr) { |
| 706 | lua_State *L = ms->L; |
| 707 | switch (tr) { |
| 708 | case LUA_TFUNCTION: { |
| 709 | int n; |
| 710 | lua_pushvalue(L, 3); |
| 711 | n = push_captures(ms, s, e); |
| 712 | lua_call(L, n, 1); |
| 713 | break; |
| 714 | } |
| 715 | case LUA_TTABLE: { |
| 716 | push_onecapture(ms, 0, s, e); |
| 717 | lua_gettable(L, 3); |
| 718 | break; |
| 719 | } |
| 720 | default: { /* LUA_TNUMBER or LUA_TSTRING */ |
| 721 | add_s(ms, b, s, e); |
| 722 | return; |
| 723 | } |
| 724 | } |
| 725 | if (!lua_toboolean(L, -1)) { /* nil or false? */ |
| 726 | lua_pop(L, 1); |
| 727 | lua_pushlstring(L, s, e - s); /* keep original text */ |
| 728 | } |
| 729 | else if (!lua_isstring(L, -1)) |
| 730 | luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); |
| 731 | luaL_addvalue(b); /* add result to accumulator */ |
| 732 | } |
| 733 | |
| 734 | |
| 735 | static int str_gsub (lua_State *L) { |
no test coverage detected