diff options
Diffstat (limited to 'c-api/compat-5.3.c')
-rw-r--r-- | c-api/compat-5.3.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c index 4bd984a..e87808c 100644 --- a/c-api/compat-5.3.c +++ b/c-api/compat-5.3.c | |||
@@ -447,7 +447,7 @@ COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { | |||
447 | 447 | ||
448 | static int compat53_checkmode (lua_State *L, const char *mode, const char *modename, int err) { | 448 | static int compat53_checkmode (lua_State *L, const char *mode, const char *modename, int err) { |
449 | if (mode && strchr(mode, modename[0]) == NULL) { | 449 | if (mode && strchr(mode, modename[0]) == NULL) { |
450 | lua_pushfstring(L, "attempt to load a %s chunk when 'mode' is '%s'", modename, mode); | 450 | lua_pushfstring(L, "attempt to load a %s chunk (mode is '%s')", modename, mode); |
451 | return err; | 451 | return err; |
452 | } | 452 | } |
453 | return LUA_OK; | 453 | return LUA_OK; |
@@ -475,17 +475,16 @@ static const char *compat53_reader (lua_State *L, void *ud, size_t *size) { | |||
475 | 475 | ||
476 | 476 | ||
477 | COMPAT53_API int lua_load (lua_State *L, lua_Reader reader, void *data, const char *source, const char *mode) { | 477 | COMPAT53_API int lua_load (lua_State *L, lua_Reader reader, void *data, const char *source, const char *mode) { |
478 | int status = LUA_OK; | ||
478 | compat53_reader_data compat53_data = { reader, data, 1, 0, 0 }; | 479 | compat53_reader_data compat53_data = { reader, data, 1, 0, 0 }; |
479 | compat53_data.peeked_data = reader(L, data, &(compat53_data.peeked_data_size)); | 480 | compat53_data.peeked_data = reader(L, data, &(compat53_data.peeked_data_size)); |
480 | if (compat53_data.peeked_data && compat53_data.peeked_data_size) { | 481 | if (compat53_data.peeked_data && compat53_data.peeked_data_size && |
481 | int status = LUA_OK; | 482 | compat53_data.peeked_data[0] == LUA_SIGNATURE[0]) /* binary file? */ |
482 | if (compat53_data.peeked_data[0] == LUA_SIGNATURE[0]) /* binary file? */ | 483 | status = compat53_checkmode(L, mode, "binary", LUA_ERRSYNTAX); |
483 | status = compat53_checkmode(L, mode, "binary", LUA_ERRFILE); | 484 | else |
484 | else | 485 | status = compat53_checkmode(L, mode, "text", LUA_ERRSYNTAX); |
485 | status = compat53_checkmode(L, mode, "text", LUA_ERRFILE); | 486 | if (status != LUA_OK) |
486 | if (status != LUA_OK) | 487 | return status; |
487 | return status; | ||
488 | } | ||
489 | /* we need to call the original 5.1 version of lua_load! */ | 488 | /* we need to call the original 5.1 version of lua_load! */ |
490 | #undef lua_load | 489 | #undef lua_load |
491 | return lua_load(L, compat53_reader, &compat53_data, source); | 490 | return lua_load(L, compat53_reader, &compat53_data, source); |