aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-04-02 14:44:18 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-04-02 14:44:18 -0300
commit4355e1afcdd5dd20d1ebf8aac27a7c109ea0c487 (patch)
tree024024c7c6ed65bca11f200ac76cd8c1b36e6c0b
parentcae1eff9014ec7376f4faa6c5b0e6338382f3e82 (diff)
downloadlua-4355e1afcdd5dd20d1ebf8aac27a7c109ea0c487.tar.gz
lua-4355e1afcdd5dd20d1ebf8aac27a7c109ea0c487.tar.bz2
lua-4355e1afcdd5dd20d1ebf8aac27a7c109ea0c487.zip
"getbyte" returns userdata size when called without second parameter.
-rw-r--r--iolib.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/iolib.c b/iolib.c
index d02086ff..fa105828 100644
--- a/iolib.c
+++ b/iolib.c
@@ -271,8 +271,7 @@ static void lua_printstack (FILE *f)
271 271
272static void errorfb (void) 272static void errorfb (void)
273{ 273{
274 char *s = luaL_opt_string(1, "(no messsage)", NULL); 274 fprintf(stderr, "lua: %s\n", lua_getstring(lua_getparam(1)));
275 fprintf(stderr, "lua: %s\n", s);
276 lua_printstack(stderr); 275 lua_printstack(stderr);
277} 276}
278 277
@@ -283,11 +282,16 @@ static void errorfb (void)
283static void getbyte (void) 282static void getbyte (void)
284{ 283{
285 lua_Object ud = lua_getparam(1); 284 lua_Object ud = lua_getparam(1);
286 int i = luaL_check_number(2, "getbyte")-1; 285 int i = luaL_opt_number(2, -1, "getbyte");
287 luaL_arg_check(lua_isuserdata(ud), "getbyte", 1, "userdata expected"); 286 luaL_arg_check(lua_isuserdata(ud), "getbyte", 1, "userdata expected");
288 luaL_arg_check(0 <= i && i < lua_getbindatasize(ud), "getbyte", 2, 287 if (i == -1)
289 "out of range"); 288 lua_pushnumber(lua_getbindatasize(ud));
290 lua_pushnumber(*(((char *)lua_getbinarydata(ud))+i)); 289 else {
290 i--;
291 luaL_arg_check(0 <= i && i < lua_getbindatasize(ud), "getbyte", 2,
292 "out of range");
293 lua_pushnumber(*(((char *)lua_getbinarydata(ud))+i));
294 }
291} 295}
292 296
293static void createuserdata (void) 297static void createuserdata (void)