diff options
| -rw-r--r-- | iolib.c | 16 |
1 files changed, 10 insertions, 6 deletions
| @@ -271,8 +271,7 @@ static void lua_printstack (FILE *f) | |||
| 271 | 271 | ||
| 272 | static void errorfb (void) | 272 | static 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) | |||
| 283 | static void getbyte (void) | 282 | static 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 | ||
| 293 | static void createuserdata (void) | 297 | static void createuserdata (void) |
