summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-09-20 15:20:44 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-09-20 15:20:44 -0300
commit3636bbad3acb6c1671f20ec3f7dc65507146d7f4 (patch)
treeaa1cb9898209d3c725cbdf6891b16142f6cdb5b3
parent82f9f3e552fe3adcf5b1e585f3c99fde4c21936a (diff)
downloadlua-3636bbad3acb6c1671f20ec3f7dc65507146d7f4.tar.gz
lua-3636bbad3acb6c1671f20ec3f7dc65507146d7f4.tar.bz2
lua-3636bbad3acb6c1671f20ec3f7dc65507146d7f4.zip
new function "strrep"
-rw-r--r--strlib.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/strlib.c b/strlib.c
index be9e7734..78c6012c 100644
--- a/strlib.c
+++ b/strlib.c
@@ -3,7 +3,7 @@
3** String library to LUA 3** String library to LUA
4*/ 4*/
5 5
6char *rcs_strlib="$Id: strlib.c,v 1.27 1996/08/09 13:14:11 roberto Exp roberto $"; 6char *rcs_strlib="$Id: strlib.c,v 1.28 1996/09/16 18:02:40 roberto Exp roberto $";
7 7
8#include <string.h> 8#include <string.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -170,6 +170,16 @@ static void str_upper (void)
170 lua_pushstring(luaI_addchar(0)); 170 lua_pushstring(luaI_addchar(0));
171} 171}
172 172
173static void str_rep (void)
174{
175 char *s = lua_check_string(1, "strrep");
176 int n = (int)lua_check_number(2, "strrep");
177 luaI_addchar(0);
178 while (n-- > 0)
179 addstr(s);
180 lua_pushstring(luaI_addchar(0));
181}
182
173/* 183/*
174** get ascii value of a character in a string 184** get ascii value of a character in a string
175*/ 185*/
@@ -522,6 +532,7 @@ static struct lua_reg strlib[] = {
522{"strset", str_set}, 532{"strset", str_set},
523{"strlower", str_lower}, 533{"strlower", str_lower},
524{"strupper", str_upper}, 534{"strupper", str_upper},
535{"strrep", str_rep},
525{"ascii", str_ascii}, 536{"ascii", str_ascii},
526{"format", str_format}, 537{"format", str_format},
527{"strfind", str_find}, 538{"strfind", str_find},