lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 3636bbad3acb6c1671f20ec3f7dc65507146d7f4
parent 82f9f3e552fe3adcf5b1e585f3c99fde4c21936a
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Fri, 20 Sep 1996 15:20:24 -0300

new function "strrep"

Diffstat:
Mstrlib.c | 13++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/strlib.c b/strlib.c @@ -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},