MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / add_value

Function add_value

extlibs/lua/src/lstrlib.c:903–936  ·  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

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

Tested by

no test coverage detected