1
0
mirror of https://github.com/lua/lua.git synced 2025-01-28 06:03:00 +08:00

"getbyte" returns userdata size when called without second parameter.

This commit is contained in:
Roberto Ierusalimschy 1997-04-02 14:44:18 -03:00
parent cae1eff901
commit 4355e1afcd

16
iolib.c
View File

@ -271,8 +271,7 @@ static void lua_printstack (FILE *f)
static void errorfb (void)
{
char *s = luaL_opt_string(1, "(no messsage)", NULL);
fprintf(stderr, "lua: %s\n", s);
fprintf(stderr, "lua: %s\n", lua_getstring(lua_getparam(1)));
lua_printstack(stderr);
}
@ -283,11 +282,16 @@ static void errorfb (void)
static void getbyte (void)
{
lua_Object ud = lua_getparam(1);
int i = luaL_check_number(2, "getbyte")-1;
int i = luaL_opt_number(2, -1, "getbyte");
luaL_arg_check(lua_isuserdata(ud), "getbyte", 1, "userdata expected");
luaL_arg_check(0 <= i && i < lua_getbindatasize(ud), "getbyte", 2,
"out of range");
lua_pushnumber(*(((char *)lua_getbinarydata(ud))+i));
if (i == -1)
lua_pushnumber(lua_getbindatasize(ud));
else {
i--;
luaL_arg_check(0 <= i && i < lua_getbindatasize(ud), "getbyte", 2,
"out of range");
lua_pushnumber(*(((char *)lua_getbinarydata(ud))+i));
}
}
static void createuserdata (void)