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