Lines Matching refs:L

60 static int str_len (lua_State *L) {  in str_len()  argument
62 luaL_checklstring(L, 1, &l); in str_len()
63 lua_pushinteger(L, (lua_Integer)l); in str_len()
76 static int str_sub (lua_State *L) { in str_sub() argument
78 const char *s = luaL_checklstring(L, 1, &l); in str_sub()
79 size_t start = posrelat(luaL_checkinteger(L, 2), l); in str_sub()
80 size_t end = posrelat(luaL_optinteger(L, 3, -1), l); in str_sub()
84 lua_pushlstring(L, s + start - 1, end - start + 1); in str_sub()
85 else lua_pushliteral(L, ""); in str_sub()
90 static int str_reverse (lua_State *L) { in str_reverse() argument
93 const char *s = luaL_checklstring(L, 1, &l); in str_reverse()
94 char *p = luaL_buffinitsize(L, &b, l); in str_reverse()
102 static int str_lower (lua_State *L) { in str_lower() argument
106 const char *s = luaL_checklstring(L, 1, &l); in str_lower()
107 char *p = luaL_buffinitsize(L, &b, l); in str_lower()
115 static int str_upper (lua_State *L) { in str_upper() argument
119 const char *s = luaL_checklstring(L, 1, &l); in str_upper()
120 char *p = luaL_buffinitsize(L, &b, l); in str_upper()
131 static int str_rep (lua_State *L) { in str_rep() argument
133 const char *s = luaL_checklstring(L, 1, &l); in str_rep()
134 int n = luaL_checkint(L, 2); in str_rep()
135 const char *sep = luaL_optlstring(L, 3, "", &lsep); in str_rep()
136 if (n <= 0) lua_pushliteral(L, ""); in str_rep()
138 return luaL_error(L, "resulting string too large"); in str_rep()
142 char *p = luaL_buffinitsize(L, &b, totallen); in str_rep()
156 static int str_byte (lua_State *L) { in str_byte() argument
158 const char *s = luaL_checklstring(L, 1, &l); in str_byte()
159 size_t posi = posrelat(luaL_optinteger(L, 2, 1), l); in str_byte()
160 size_t pose = posrelat(luaL_optinteger(L, 3, posi), l); in str_byte()
167 return luaL_error(L, "string slice too long"); in str_byte()
168 luaL_checkstack(L, n, "string slice too long"); in str_byte()
170 lua_pushinteger(L, uchar(s[posi+i-1])); in str_byte()
175 static int str_char (lua_State *L) { in str_char() argument
176 int n = lua_gettop(L); /* number of arguments */ in str_char()
179 char *p = luaL_buffinitsize(L, &b, n); in str_char()
181 int c = luaL_checkint(L, i); in str_char()
182 luaL_argcheck(L, uchar(c) == c, i, "value out of range"); in str_char()
190 static int writer (lua_State *L, const void* b, size_t size, void* B) { in writer() argument
191 (void)L; in writer()
197 static int str_dump (lua_State *L) { in str_dump() argument
199 luaL_checktype(L, 1, LUA_TFUNCTION); in str_dump()
200 lua_settop(L, 1); in str_dump()
201 luaL_buffinit(L,&b); in str_dump()
202 if (lua_dump(L, writer, &b) != 0) in str_dump()
203 return luaL_error(L, "unable to dump given function"); in str_dump()
226 lua_State *L; member
252 return luaL_error(ms->L, "invalid capture index %%%d", l + 1); in check_capture()
261 return luaL_error(ms->L, "invalid pattern capture"); in capture_to_close()
269 luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")"); in classend()
276 luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")"); in classend()
358 luaL_error(ms->L, "malformed pattern " in matchbalance()
408 if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures"); in start_capture()
442 luaL_error(ms->L, "pattern too complex"); in match()
476 luaL_error(ms->L, "missing " LUA_QL("[") " after " in match()
570 lua_pushlstring(ms->L, s, e - s); /* add whole match */ in push_onecapture()
572 luaL_error(ms->L, "invalid capture index"); in push_onecapture()
576 if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); in push_onecapture()
578 lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); in push_onecapture()
580 lua_pushlstring(ms->L, ms->capture[i].init, l); in push_onecapture()
588 luaL_checkstack(ms->L, nlevels, "too many captures"); in push_captures()
607 static int str_find_aux (lua_State *L, int find) { in str_find_aux() argument
609 const char *s = luaL_checklstring(L, 1, &ls); in str_find_aux()
610 const char *p = luaL_checklstring(L, 2, &lp); in str_find_aux()
611 size_t init = posrelat(luaL_optinteger(L, 3, 1), ls); in str_find_aux()
614 lua_pushnil(L); /* cannot find anything */ in str_find_aux()
618 if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) { in str_find_aux()
622 lua_pushinteger(L, s2 - s + 1); in str_find_aux()
623 lua_pushinteger(L, s2 - s + lp); in str_find_aux()
634 ms.L = L; in str_find_aux()
645 lua_pushinteger(L, s1 - s + 1); /* start */ in str_find_aux()
646 lua_pushinteger(L, res - s); /* end */ in str_find_aux()
654 lua_pushnil(L); /* not found */ in str_find_aux()
659 static int str_find (lua_State *L) { in str_find() argument
660 return str_find_aux(L, 1); in str_find()
664 static int str_match (lua_State *L) { in str_match() argument
665 return str_find_aux(L, 0); in str_match()
669 static int gmatch_aux (lua_State *L) { in gmatch_aux() argument
672 const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls); in gmatch_aux()
673 const char *p = lua_tolstring(L, lua_upvalueindex(2), &lp); in gmatch_aux()
675 ms.L = L; in gmatch_aux()
680 for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3)); in gmatch_aux()
689 lua_pushinteger(L, newstart); in gmatch_aux()
690 lua_replace(L, lua_upvalueindex(3)); in gmatch_aux()
698 static int str_gmatch (lua_State *L) { in str_gmatch() argument
699 luaL_checkstring(L, 1); in str_gmatch()
700 luaL_checkstring(L, 2); in str_gmatch()
701 lua_settop(L, 2); in str_gmatch()
702 lua_pushinteger(L, 0); in str_gmatch()
703 lua_pushcclosure(L, gmatch_aux, 3); in str_gmatch()
711 const char *news = lua_tolstring(ms->L, 3, &l); in add_s()
719 luaL_error(ms->L, "invalid use of " LUA_QL("%c") in add_s()
736 lua_State *L = ms->L; in add_value() local
740 lua_pushvalue(L, 3); in add_value()
742 lua_call(L, n, 1); in add_value()
747 lua_gettable(L, 3); in add_value()
755 if (!lua_toboolean(L, -1)) { /* nil or false? */ in add_value()
756 lua_pop(L, 1); in add_value()
757 lua_pushlstring(L, s, e - s); /* keep original text */ in add_value()
759 else if (!lua_isstring(L, -1)) in add_value()
760 luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); in add_value()
765 static int str_gsub (lua_State *L) { in str_gsub() argument
767 const char *src = luaL_checklstring(L, 1, &srcl); in str_gsub()
768 const char *p = luaL_checklstring(L, 2, &lp); in str_gsub()
769 int tr = lua_type(L, 3); in str_gsub()
770 size_t max_s = luaL_optinteger(L, 4, srcl+1); in str_gsub()
775 luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || in str_gsub()
778 luaL_buffinit(L, &b); in str_gsub()
782 ms.L = L; in str_gsub()
805 lua_pushinteger(L, n); /* number of substitutions */ in str_gsub()
863 static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { in addquoted() argument
865 const char *s = luaL_checklstring(L, arg, &l); in addquoted()
887 static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { in scanformat() argument
891 luaL_error(L, "invalid format (repeated flags)"); in scanformat()
900 luaL_error(L, "invalid format (width or precision too long)"); in scanformat()
922 static int str_format (lua_State *L) { in str_format() argument
923 int top = lua_gettop(L); in str_format()
926 const char *strfrmt = luaL_checklstring(L, arg, &sfl); in str_format()
929 luaL_buffinit(L, &b); in str_format()
940 luaL_argerror(L, arg, "no value"); in str_format()
941 strfrmt = scanformat(L, strfrmt, form); in str_format()
944 nb = str_sprintf(buff, form, luaL_checkint(L, arg)); in str_format()
948 lua_Number n = luaL_checknumber(L, arg); in str_format()
951 luaL_argcheck(L, -1 < diff && diff < 1, arg, in str_format()
958 lua_Number n = luaL_checknumber(L, arg); in str_format()
961 luaL_argcheck(L, -1 < diff && diff < 1, arg, in str_format()
974 nb = str_sprintf(buff, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg)); in str_format()
979 addquoted(L, &b, arg); in str_format()
984 const char *s = luaL_tolstring(L, arg, &l); in str_format()
993 lua_pop(L, 1); /* remove result from 'luaL_tolstring' */ in str_format()
998 return luaL_error(L, "invalid option " LUA_QL("%%%c") " to " in str_format()
1031 static void createmetatable (lua_State *L) { in createmetatable() argument
1032 lua_createtable(L, 0, 1); /* table to be metatable for strings */ in createmetatable()
1033 lua_pushliteral(L, ""); /* dummy string */ in createmetatable()
1034 lua_pushvalue(L, -2); /* copy table */ in createmetatable()
1035 lua_setmetatable(L, -2); /* set table as metatable for strings */ in createmetatable()
1036 lua_pop(L, 1); /* pop dummy string */ in createmetatable()
1037 lua_pushvalue(L, -2); /* get string library */ in createmetatable()
1038 lua_setfield(L, -2, "__index"); /* metatable.__index = string */ in createmetatable()
1039 lua_pop(L, 1); /* pop metatable */ in createmetatable()
1046 LUAMOD_API int luaopen_string (lua_State *L) { in luaopen_string() argument
1047 luaL_newlib(L, strlib); in luaopen_string()
1048 createmetatable(L); in luaopen_string()