Lines Matching refs:L

28 static int str_len (lua_State *L) {  in str_len()  argument
30 luaL_checklstring(L, 1, &l); in str_len()
31 lua_pushinteger(L, l); in str_len()
43 static int str_sub (lua_State *L) { in str_sub() argument
45 const char *s = luaL_checklstring(L, 1, &l); in str_sub()
46 ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l); in str_sub()
47 ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l); in str_sub()
51 lua_pushlstring(L, s+start-1, end-start+1); in str_sub()
52 else lua_pushliteral(L, ""); in str_sub()
57 static int str_reverse (lua_State *L) { in str_reverse() argument
60 const char *s = luaL_checklstring(L, 1, &l); in str_reverse()
61 luaL_buffinit(L, &b); in str_reverse()
68 static int str_lower (lua_State *L) { in str_lower() argument
72 const char *s = luaL_checklstring(L, 1, &l); in str_lower()
73 luaL_buffinit(L, &b); in str_lower()
81 static int str_upper (lua_State *L) { in str_upper() argument
85 const char *s = luaL_checklstring(L, 1, &l); in str_upper()
86 luaL_buffinit(L, &b); in str_upper()
93 static int str_rep (lua_State *L) { in str_rep() argument
96 const char *s = luaL_checklstring(L, 1, &l); in str_rep()
97 int n = luaL_checkint(L, 2); in str_rep()
98 luaL_buffinit(L, &b); in str_rep()
106 static int str_byte (lua_State *L) { in str_byte() argument
108 const char *s = luaL_checklstring(L, 1, &l); in str_byte()
109 ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l); in str_byte()
110 ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l); in str_byte()
117 luaL_error(L, "string slice too long"); in str_byte()
118 luaL_checkstack(L, n, "string slice too long"); in str_byte()
120 lua_pushinteger(L, uchar(s[posi+i-1])); in str_byte()
125 static int str_char (lua_State *L) { in str_char() argument
126 int n = lua_gettop(L); /* number of arguments */ in str_char()
129 luaL_buffinit(L, &b); in str_char()
131 int c = luaL_checkint(L, i); in str_char()
132 luaL_argcheck(L, uchar(c) == c, i, "invalid value"); in str_char()
140 static int writer (lua_State *L, const void* b, size_t size, void* B) { in writer() argument
141 (void)L; in writer()
147 static int str_dump (lua_State *L) { in str_dump() argument
149 luaL_checktype(L, 1, LUA_TFUNCTION); in str_dump()
150 lua_settop(L, 1); in str_dump()
151 luaL_buffinit(L,&b); in str_dump()
152 if (lua_dump(L, writer, &b) != 0) in str_dump()
153 luaL_error(L, "unable to dump given function"); in str_dump()
173 lua_State *L; member
189 return luaL_error(ms->L, "invalid capture index"); in check_capture()
198 return luaL_error(ms->L, "invalid pattern capture"); in capture_to_close()
206 luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")"); in classend()
213 luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")"); in classend()
284 luaL_error(ms->L, "unbalanced pattern"); in matchbalance()
333 if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures"); in start_capture()
388 luaL_error(ms->L, "missing " LUA_QL("[") " after " in match()
470 lua_pushlstring(ms->L, s, e - s); /* add whole match */ in push_onecapture()
472 luaL_error(ms->L, "invalid capture index"); in push_onecapture()
476 if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); in push_onecapture()
478 lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); in push_onecapture()
480 lua_pushlstring(ms->L, ms->capture[i].init, l); in push_onecapture()
488 luaL_checkstack(ms->L, nlevels, "too many captures"); in push_captures()
495 static int str_find_aux (lua_State *L, int find) { in str_find_aux() argument
497 const char *s = luaL_checklstring(L, 1, &l1); in str_find_aux()
498 const char *p = luaL_checklstring(L, 2, &l2); in str_find_aux()
499 ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1; in str_find_aux()
502 if (find && (lua_toboolean(L, 4) || /* explicit request? */ in str_find_aux()
507 lua_pushinteger(L, s2-s+1); in str_find_aux()
508 lua_pushinteger(L, s2-s+l2); in str_find_aux()
516 ms.L = L; in str_find_aux()
524 lua_pushinteger(L, s1-s+1); /* start */ in str_find_aux()
525 lua_pushinteger(L, res-s); /* end */ in str_find_aux()
533 lua_pushnil(L); /* not found */ in str_find_aux()
538 static int str_find (lua_State *L) { in str_find() argument
539 return str_find_aux(L, 1); in str_find()
543 static int str_match (lua_State *L) { in str_match() argument
544 return str_find_aux(L, 0); in str_match()
548 static int gmatch_aux (lua_State *L) { in gmatch_aux() argument
551 const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls); in gmatch_aux()
552 const char *p = lua_tostring(L, lua_upvalueindex(2)); in gmatch_aux()
554 ms.L = L; in gmatch_aux()
557 for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3)); in gmatch_aux()
565 lua_pushinteger(L, newstart); in gmatch_aux()
566 lua_replace(L, lua_upvalueindex(3)); in gmatch_aux()
574 static int gmatch (lua_State *L) { in gmatch() argument
575 luaL_checkstring(L, 1); in gmatch()
576 luaL_checkstring(L, 2); in gmatch()
577 lua_settop(L, 2); in gmatch()
578 lua_pushinteger(L, 0); in gmatch()
579 lua_pushcclosure(L, gmatch_aux, 3); in gmatch()
584 static int gfind_nodef (lua_State *L) { in gfind_nodef() argument
585 return luaL_error(L, LUA_QL("string.gfind") " was renamed to " in gfind_nodef()
593 const char *news = lua_tolstring(ms->L, 3, &l); in add_s()
614 lua_State *L = ms->L; in add_value() local
615 switch (lua_type(L, 3)) { in add_value()
623 lua_pushvalue(L, 3); in add_value()
625 lua_call(L, n, 1); in add_value()
630 lua_gettable(L, 3); in add_value()
634 if (!lua_toboolean(L, -1)) { /* nil or false? */ in add_value()
635 lua_pop(L, 1); in add_value()
636 lua_pushlstring(L, s, e - s); /* keep original text */ in add_value()
638 else if (!lua_isstring(L, -1)) in add_value()
639 luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); in add_value()
644 static int str_gsub (lua_State *L) { in str_gsub() argument
646 const char *src = luaL_checklstring(L, 1, &srcl); in str_gsub()
647 const char *p = luaL_checkstring(L, 2); in str_gsub()
648 int tr = lua_type(L, 3); in str_gsub()
649 int max_s = luaL_optint(L, 4, srcl+1); in str_gsub()
654 luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || in str_gsub()
657 luaL_buffinit(L, &b); in str_gsub()
658 ms.L = L; in str_gsub()
678 lua_pushinteger(L, n); /* number of substitutions */ in str_gsub()
696 static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { in addquoted() argument
698 const char *s = luaL_checklstring(L, arg, &l); in addquoted()
725 static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { in scanformat() argument
729 luaL_error(L, "invalid format (repeated flags)"); in scanformat()
738 luaL_error(L, "invalid format (width or precision too long)"); in scanformat()
756 static int str_format (lua_State *L) { in str_format() argument
757 int top = lua_gettop(L); in str_format()
760 const char *strfrmt = luaL_checklstring(L, arg, &sfl); in str_format()
763 luaL_buffinit(L, &b); in str_format()
773 luaL_argerror(L, arg, "no value"); in str_format()
774 strfrmt = scanformat(L, strfrmt, form); in str_format()
777 sprintf(buff, form, (int)luaL_checknumber(L, arg)); in str_format()
782 sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); in str_format()
787 sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); in str_format()
792 sprintf(buff, form, (double)luaL_checknumber(L, arg)); in str_format()
796 addquoted(L, &b, arg); in str_format()
801 const char *s = luaL_checklstring(L, arg, &l); in str_format()
805 lua_pushvalue(L, arg); in str_format()
815 return luaL_error(L, "invalid option " LUA_QL("%%%c") " to " in str_format()
847 static void createmetatable (lua_State *L) { in createmetatable() argument
848 lua_createtable(L, 0, 1); /* create metatable for strings */ in createmetatable()
849 lua_pushliteral(L, ""); /* dummy string */ in createmetatable()
850 lua_pushvalue(L, -2); in createmetatable()
851 lua_setmetatable(L, -2); /* set string metatable */ in createmetatable()
852 lua_pop(L, 1); /* pop dummy string */ in createmetatable()
853 lua_pushvalue(L, -2); /* string library... */ in createmetatable()
854 lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */ in createmetatable()
855 lua_pop(L, 1); /* pop metatable */ in createmetatable()
862 LUALIB_API int luaopen_string (lua_State *L) { in luaopen_string() argument
863 luaL_register(L, LUA_STRLIBNAME, strlib); in luaopen_string()
865 lua_getfield(L, -1, "gmatch"); in luaopen_string()
866 lua_setfield(L, -2, "gfind"); in luaopen_string()
868 createmetatable(L); in luaopen_string()