commit 0ddedaee92afe474b2a919861437af95b34eec08
parent 5cc448386adad1da2901e381481e4129034b692b
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 14 May 2003 11:35:32 -0300
new function `string.reverse'
Diffstat:
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/lstrlib.c b/lstrlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstrlib.c,v 1.97 2003/03/19 21:16:12 roberto Exp roberto $
+** $Id: lstrlib.c,v 1.98 2003/04/03 13:35:34 roberto Exp roberto $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@@ -56,6 +56,17 @@ static int str_sub (lua_State *L) {
}
+static int str_reverse (lua_State *L) {
+ size_t l;
+ luaL_Buffer b;
+ const char *s = luaL_checklstring(L, 1, &l);
+ luaL_buffinit(L, &b);
+ while (l--) luaL_putchar(&b, s[l]);
+ luaL_pushresult(&b);
+ return 1;
+}
+
+
static int str_lower (lua_State *L) {
size_t l;
size_t i;
@@ -746,6 +757,7 @@ static int str_format (lua_State *L) {
static const luaL_reg strlib[] = {
{"len", str_len},
{"sub", str_sub},
+ {"reverse", str_reverse},
{"lower", str_lower},
{"upper", str_upper},
{"char", str_char},