public void add_value(Buffer lbuf, int soffset, int end, LuaValue repl) {
			switch (repl.type()) {
			case LuaValue.TSTRING:
			case LuaValue.TNUMBER:
				add_s(lbuf, repl.strvalue(), soffset, end);
				return;

			case LuaValue.TFUNCTION:
				repl = repl.invoke(push_captures(true, soffset, end)).arg1();
				break;

			case LuaValue.TTABLE:
				// Need to call push_onecapture here for the error checking
				repl = repl.get(push_onecapture(0, soffset, end));
				break;

			default:
				error("bad argument: string/function/table expected");
				return;
			}

			if (!repl.toboolean()) {
				repl = s.substring(soffset, end);
			} else if (!repl.isstring()) {
				error("invalid replacement value (a " + repl.typename() + ")");
			}
			lbuf.append(repl.strvalue());
		}