MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / add_value

Function add_value

third-party/lua-5.5.0/src/lstrlib.c:909–942  ·  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

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

Callers 1

str_gsubFunction · 0.70

Calls 11

lua_pushvalueFunction · 0.70
push_capturesFunction · 0.70
push_onecaptureFunction · 0.70
lua_gettableFunction · 0.70
add_sFunction · 0.70
lua_tobooleanFunction · 0.70
luaL_addlstringFunction · 0.70
lua_isstringFunction · 0.70
luaL_errorFunction · 0.70
luaL_addvalueFunction · 0.70
lua_callFunction · 0.50

Tested by

no test coverage detected