From 0ddedaee92afe474b2a919861437af95b34eec08 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 14 May 2003 11:35:54 -0300 Subject: new function `string.reverse' --- lstrlib.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lstrlib.c') diff --git a/lstrlib.c b/lstrlib.c index e4be9f58..7340e94c 100644 --- 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}, -- cgit v1.2.3-55-g6feb