| 729 | |
| 730 | |
| 731 | static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, |
| 732 | const char *e, int tr) { |
| 733 | lua_State *L = ms->L; |
| 734 | switch (tr) { |
| 735 | case LUA_TFUNCTION: { |
| 736 | int n; |
| 737 | lua_pushvalue(L, 3); |
| 738 | n = push_captures(ms, s, e); |
| 739 | lua_call(L, n, 1); |
| 740 | break; |
| 741 | } |
| 742 | case LUA_TTABLE: { |
| 743 | push_onecapture(ms, 0, s, e); |
| 744 | lua_gettable(L, 3); |
| 745 | break; |
| 746 | } |
| 747 | default: { /* LUA_TNUMBER or LUA_TSTRING */ |
| 748 | add_s(ms, b, s, e); |
| 749 | return; |
| 750 | } |
| 751 | } |
| 752 | if (!lua_toboolean(L, -1)) { /* nil or false? */ |
| 753 | lua_pop(L, 1); |
| 754 | lua_pushlstring(L, s, e - s); /* keep original text */ |
| 755 | } |
| 756 | else if (!lua_isstring(L, -1)) |
| 757 | luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); |
| 758 | luaL_addvalue(b); /* add result to accumulator */ |
| 759 | } |
| 760 | |
| 761 | |
| 762 | static int str_gsub (lua_State *L) { |
no test coverage detected