string.byte may return multiple values
This commit is contained in:
17
lstrlib.c
17
lstrlib.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lstrlib.c,v 1.103 2004/06/08 14:31:15 roberto Exp roberto $
|
** $Id: lstrlib.c,v 1.104 2004/07/09 18:24:41 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
|
||||||
*/
|
*/
|
||||||
@@ -107,11 +107,16 @@ static int str_rep (lua_State *L) {
|
|||||||
static int str_byte (lua_State *L) {
|
static int str_byte (lua_State *L) {
|
||||||
size_t l;
|
size_t l;
|
||||||
const char *s = luaL_checklstring(L, 1, &l);
|
const char *s = luaL_checklstring(L, 1, &l);
|
||||||
sint32 pos = posrelat(luaL_optinteger(L, 2, 1), l);
|
sint32 posi = posrelat(luaL_optinteger(L, 2, 1), l);
|
||||||
if (pos <= 0 || (size_t)(pos) > l) /* index out of range? */
|
sint32 pose = posrelat(luaL_optinteger(L, 3, posi), l);
|
||||||
return 0; /* no answer */
|
int n, i;
|
||||||
lua_pushinteger(L, uchar(s[pos-1]));
|
if (!(0 < posi && posi <= pose && (size_t)pose <= l))
|
||||||
return 1;
|
return 0; /* index out of range; no answer */
|
||||||
|
n = pose - posi + 1;
|
||||||
|
luaL_checkstack(L, n, "string slice too long");
|
||||||
|
for (i=0; i<n; i++)
|
||||||
|
lua_pushinteger(L, uchar(s[posi+i-1]));
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user