MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / add_value

Function add_value

3rd/lua-5.4.3/src/lstrlib.c:906–939  ·  view source on GitHub ↗

** Add the replacement value to the string buffer 'b'. ** Return true if the original string was changed. (Function calls and ** table indexing resulting in nil or false do not change the subject.) */

Source from the content-addressed store, hash-verified

904** table indexing resulting in nil or false do not change the subject.)
905*/
906static int add_value (MatchState *ms, luaL_Buffer *b, const char *s,
907 const char *e, int tr) {
908 lua_State *L = ms->L;
909 switch (tr) {
910 case LUA_TFUNCTION: { /* call the function */
911 int n;
912 lua_pushvalue(L, 3); /* push the function */
913 n = push_captures(ms, s, e); /* all captures as arguments */
914 lua_call(L, n, 1); /* call it */
915 break;
916 }
917 case LUA_TTABLE: { /* index the table */
918 push_onecapture(ms, 0, s, e); /* first capture is the index */
919 lua_gettable(L, 3);
920 break;
921 }
922 default: { /* LUA_TNUMBER or LUA_TSTRING */
923 add_s(ms, b, s, e); /* add value to the buffer */
924 return 1; /* something changed */
925 }
926 }
927 if (!lua_toboolean(L, -1)) { /* nil or false? */
928 lua_pop(L, 1); /* remove value */
929 luaL_addlstring(b, s, e - s); /* keep original text */
930 return 0; /* no changes */
931 }
932 else if (l_unlikely(!lua_isstring(L, -1)))
933 return luaL_error(L, "invalid replacement value (a %s)",
934 luaL_typename(L, -1));
935 else {
936 luaL_addvalue(b); /* add result to accumulator */
937 return 1; /* something changed */
938 }
939}
940
941
942static int str_gsub (lua_State *L) {

Callers 1

str_gsubFunction · 0.85

Calls 10

lua_pushvalueFunction · 0.85
push_capturesFunction · 0.85
push_onecaptureFunction · 0.85
lua_gettableFunction · 0.85
add_sFunction · 0.85
lua_tobooleanFunction · 0.85
luaL_addlstringFunction · 0.85
lua_isstringFunction · 0.85
luaL_errorFunction · 0.85
luaL_addvalueFunction · 0.85

Tested by

no test coverage detected