aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-05-14 11:35:54 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-05-14 11:35:54 -0300
commit0ddedaee92afe474b2a919861437af95b34eec08 (patch)
treef52927bc19f89bbb74e9980ffd89c8e56cad759b
parent5cc448386adad1da2901e381481e4129034b692b (diff)
downloadlua-0ddedaee92afe474b2a919861437af95b34eec08.tar.gz
lua-0ddedaee92afe474b2a919861437af95b34eec08.tar.bz2
lua-0ddedaee92afe474b2a919861437af95b34eec08.zip
new function `string.reverse'
-rw-r--r--lstrlib.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/lstrlib.c b/lstrlib.c
index e4be9f58..7340e94c 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.97 2003/03/19 21:16:12 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.98 2003/04/03 13:35:34 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -56,6 +56,17 @@ static int str_sub (lua_State *L) {
56} 56}
57 57
58 58
59static int str_reverse (lua_State *L) {
60 size_t l;
61 luaL_Buffer b;
62 const char *s = luaL_checklstring(L, 1, &l);
63 luaL_buffinit(L, &b);
64 while (l--) luaL_putchar(&b, s[l]);
65 luaL_pushresult(&b);
66 return 1;
67}
68
69
59static int str_lower (lua_State *L) { 70static int str_lower (lua_State *L) {
60 size_t l; 71 size_t l;
61 size_t i; 72 size_t i;
@@ -746,6 +757,7 @@ static int str_format (lua_State *L) {
746static const luaL_reg strlib[] = { 757static const luaL_reg strlib[] = {
747 {"len", str_len}, 758 {"len", str_len},
748 {"sub", str_sub}, 759 {"sub", str_sub},
760 {"reverse", str_reverse},
749 {"lower", str_lower}, 761 {"lower", str_lower},
750 {"upper", str_upper}, 762 {"upper", str_upper},
751 {"char", str_char}, 763 {"char", str_char},