diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-05-14 11:35:54 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-05-14 11:35:54 -0300 |
| commit | 0ddedaee92afe474b2a919861437af95b34eec08 (patch) | |
| tree | f52927bc19f89bbb74e9980ffd89c8e56cad759b /lstrlib.c | |
| parent | 5cc448386adad1da2901e381481e4129034b692b (diff) | |
| download | lua-0ddedaee92afe474b2a919861437af95b34eec08.tar.gz lua-0ddedaee92afe474b2a919861437af95b34eec08.tar.bz2 lua-0ddedaee92afe474b2a919861437af95b34eec08.zip | |
new function `string.reverse'
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}, |
