diff options
Diffstat (limited to 'lstrlib.c')
-rw-r--r-- | lstrlib.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -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 | ||
59 | static 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 | |||
59 | static int str_lower (lua_State *L) { | 70 | static 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) { | |||
746 | static const luaL_reg strlib[] = { | 757 | static 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}, |