new function "strrep"

This commit is contained in:
Roberto Ierusalimschy 1996-09-20 15:20:44 -03:00
parent 82f9f3e552
commit 3636bbad3a

View file

@ -3,7 +3,7 @@
** String library to LUA
*/
char *rcs_strlib="$Id: strlib.c,v 1.27 1996/08/09 13:14:11 roberto Exp roberto $";
char *rcs_strlib="$Id: strlib.c,v 1.28 1996/09/16 18:02:40 roberto Exp roberto $";
#include <string.h>
#include <stdio.h>
@ -170,6 +170,16 @@ static void str_upper (void)
lua_pushstring(luaI_addchar(0));
}
static void str_rep (void)
{
char *s = lua_check_string(1, "strrep");
int n = (int)lua_check_number(2, "strrep");
luaI_addchar(0);
while (n-- > 0)
addstr(s);
lua_pushstring(luaI_addchar(0));
}
/*
** get ascii value of a character in a string
*/
@ -522,6 +532,7 @@ static struct lua_reg strlib[] = {
{"strset", str_set},
{"strlower", str_lower},
{"strupper", str_upper},
{"strrep", str_rep},
{"ascii", str_ascii},
{"format", str_format},
{"strfind", str_find},