new function `string.reverse'
This commit is contained in:
14
lstrlib.c
14
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
|
** Standard library for string operations and pattern-matching
|
||||||
** See Copyright Notice in lua.h
|
** 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) {
|
static int str_lower (lua_State *L) {
|
||||||
size_t l;
|
size_t l;
|
||||||
size_t i;
|
size_t i;
|
||||||
@@ -746,6 +757,7 @@ static int str_format (lua_State *L) {
|
|||||||
static const luaL_reg strlib[] = {
|
static const luaL_reg strlib[] = {
|
||||||
{"len", str_len},
|
{"len", str_len},
|
||||||
{"sub", str_sub},
|
{"sub", str_sub},
|
||||||
|
{"reverse", str_reverse},
|
||||||
{"lower", str_lower},
|
{"lower", str_lower},
|
||||||
{"upper", str_upper},
|
{"upper", str_upper},
|
||||||
{"char", str_char},
|
{"char", str_char},
|
||||||
|
|||||||
Reference in New Issue
Block a user