new function `string.reverse'

This commit is contained in:
Roberto Ierusalimschy 2003-05-14 11:35:54 -03:00
parent 5cc448386a
commit 0ddedaee92

View File

@ -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},