diff options
author | Philipp Janda <siffiejoe@gmx.net> | 2017-09-16 17:19:35 +0200 |
---|---|---|
committer | Philipp Janda <siffiejoe@gmx.net> | 2017-09-16 17:19:35 +0200 |
commit | 09b201c87c904066e1de5d44cf1e02538970c168 (patch) | |
tree | e56be07e08699f920482212f07342acf8f9526ae /c-api | |
parent | 3b52d81dcf1b5d6d49e1837612e207b2cab6b74d (diff) | |
download | lua-compat-5.3-09b201c87c904066e1de5d44cf1e02538970c168.tar.gz lua-compat-5.3-09b201c87c904066e1de5d44cf1e02538970c168.tar.bz2 lua-compat-5.3-09b201c87c904066e1de5d44cf1e02538970c168.zip |
Add tests for `luaL_load{buffer,file}x`.
Fix bug regarding empty input in `lua_load`.
Adapt error message and error code.
Diffstat (limited to 'c-api')
-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); |