MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / str_sub

Function str_sub

deps/lua/src/lstrlib.c:43–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41
42
43static int str_sub (lua_State *L) {
44 size_t l;
45 const char *s = luaL_checklstring(L, 1, &l);
46 ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l);
47 ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l);
48 if (start < 1) start = 1;
49 if (end > (ptrdiff_t)l) end = (ptrdiff_t)l;
50 if (start <= end)
51 lua_pushlstring(L, s+start-1, end-start+1);
52 else lua_pushliteral(L, "");
53 return 1;
54}
55
56
57static int str_reverse (lua_State *L) {

Callers

nothing calls this directly

Calls 5

luaL_checklstringFunction · 0.85
posrelatFunction · 0.85
luaL_checkintegerFunction · 0.85
luaL_optintegerFunction · 0.85
lua_pushlstringFunction · 0.85

Tested by

no test coverage detected