diff options
author | Li Jin <dragon-fly@qq.com> | 2024-10-19 00:35:11 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2024-10-19 00:35:11 +0800 |
commit | 1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0 (patch) | |
tree | 8bd3fbeb396fd2fce6e5b34c3ee10f4923feca72 /src/3rdParty/lua/lauxlib.c | |
parent | 05da3cbfa3689e6c229c41156d0dd08ab554cd77 (diff) | |
download | yuescript-1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0.tar.gz yuescript-1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0.tar.bz2 yuescript-1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0.zip |
Fixed issue #174.
Diffstat (limited to 'src/3rdParty/lua/lauxlib.c')
-rw-r--r-- | src/3rdParty/lua/lauxlib.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/3rdParty/lua/lauxlib.c b/src/3rdParty/lua/lauxlib.c index 4ca6c65..923105e 100644 --- a/src/3rdParty/lua/lauxlib.c +++ b/src/3rdParty/lua/lauxlib.c | |||
@@ -80,6 +80,7 @@ static int pushglobalfuncname (lua_State *L, lua_Debug *ar) { | |||
80 | int top = lua_gettop(L); | 80 | int top = lua_gettop(L); |
81 | lua_getinfo(L, "f", ar); /* push function */ | 81 | lua_getinfo(L, "f", ar); /* push function */ |
82 | lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); | 82 | lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); |
83 | luaL_checkstack(L, 6, "not enough stack"); /* slots for 'findfield' */ | ||
83 | if (findfield(L, top + 1, 2)) { | 84 | if (findfield(L, top + 1, 2)) { |
84 | const char *name = lua_tostring(L, -1); | 85 | const char *name = lua_tostring(L, -1); |
85 | if (strncmp(name, LUA_GNAME ".", 3) == 0) { /* name start with '_G.'? */ | 86 | if (strncmp(name, LUA_GNAME ".", 3) == 0) { /* name start with '_G.'? */ |
@@ -249,11 +250,13 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { | |||
249 | return 1; | 250 | return 1; |
250 | } | 251 | } |
251 | else { | 252 | else { |
253 | const char *msg; | ||
252 | luaL_pushfail(L); | 254 | luaL_pushfail(L); |
255 | msg = (en != 0) ? strerror(en) : "(no extra info)"; | ||
253 | if (fname) | 256 | if (fname) |
254 | lua_pushfstring(L, "%s: %s", fname, strerror(en)); | 257 | lua_pushfstring(L, "%s: %s", fname, msg); |
255 | else | 258 | else |
256 | lua_pushstring(L, strerror(en)); | 259 | lua_pushstring(L, msg); |
257 | lua_pushinteger(L, en); | 260 | lua_pushinteger(L, en); |
258 | return 3; | 261 | return 3; |
259 | } | 262 | } |
@@ -732,9 +735,12 @@ static const char *getF (lua_State *L, void *ud, size_t *size) { | |||
732 | 735 | ||
733 | 736 | ||
734 | static int errfile (lua_State *L, const char *what, int fnameindex) { | 737 | static int errfile (lua_State *L, const char *what, int fnameindex) { |
735 | const char *serr = strerror(errno); | 738 | int err = errno; |
736 | const char *filename = lua_tostring(L, fnameindex) + 1; | 739 | const char *filename = lua_tostring(L, fnameindex) + 1; |
737 | lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); | 740 | if (err != 0) |
741 | lua_pushfstring(L, "cannot %s %s: %s", what, filename, strerror(err)); | ||
742 | else | ||
743 | lua_pushfstring(L, "cannot %s %s", what, filename); | ||
738 | lua_remove(L, fnameindex); | 744 | lua_remove(L, fnameindex); |
739 | return LUA_ERRFILE; | 745 | return LUA_ERRFILE; |
740 | } | 746 | } |
@@ -787,6 +793,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename, | |||
787 | } | 793 | } |
788 | else { | 794 | else { |
789 | lua_pushfstring(L, "@%s", filename); | 795 | lua_pushfstring(L, "@%s", filename); |
796 | errno = 0; | ||
790 | lf.f = fopen(filename, "r"); | 797 | lf.f = fopen(filename, "r"); |
791 | if (lf.f == NULL) return errfile(L, "open", fnameindex); | 798 | if (lf.f == NULL) return errfile(L, "open", fnameindex); |
792 | } | 799 | } |
@@ -796,6 +803,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename, | |||
796 | if (c == LUA_SIGNATURE[0]) { /* binary file? */ | 803 | if (c == LUA_SIGNATURE[0]) { /* binary file? */ |
797 | lf.n = 0; /* remove possible newline */ | 804 | lf.n = 0; /* remove possible newline */ |
798 | if (filename) { /* "real" file? */ | 805 | if (filename) { /* "real" file? */ |
806 | errno = 0; | ||
799 | lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ | 807 | lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ |
800 | if (lf.f == NULL) return errfile(L, "reopen", fnameindex); | 808 | if (lf.f == NULL) return errfile(L, "reopen", fnameindex); |
801 | skipcomment(lf.f, &c); /* re-read initial portion */ | 809 | skipcomment(lf.f, &c); /* re-read initial portion */ |
@@ -803,6 +811,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename, | |||
803 | } | 811 | } |
804 | if (c != EOF) | 812 | if (c != EOF) |
805 | lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */ | 813 | lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */ |
814 | errno = 0; | ||
806 | status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode); | 815 | status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode); |
807 | readstatus = ferror(lf.f); | 816 | readstatus = ferror(lf.f); |
808 | if (filename) fclose(lf.f); /* close file (even in case of errors) */ | 817 | if (filename) fclose(lf.f); /* close file (even in case of errors) */ |
@@ -933,7 +942,7 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { | |||
933 | LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { | 942 | LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { |
934 | luaL_checkstack(L, nup, "too many upvalues"); | 943 | luaL_checkstack(L, nup, "too many upvalues"); |
935 | for (; l->name != NULL; l++) { /* fill the table with given functions */ | 944 | for (; l->name != NULL; l++) { /* fill the table with given functions */ |
936 | if (l->func == NULL) /* place holder? */ | 945 | if (l->func == NULL) /* placeholder? */ |
937 | lua_pushboolean(L, 0); | 946 | lua_pushboolean(L, 0); |
938 | else { | 947 | else { |
939 | int i; | 948 | int i; |
@@ -1025,9 +1034,14 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { | |||
1025 | } | 1034 | } |
1026 | 1035 | ||
1027 | 1036 | ||
1037 | /* | ||
1038 | ** Standard panic funcion just prints an error message. The test | ||
1039 | ** with 'lua_type' avoids possible memory errors in 'lua_tostring'. | ||
1040 | */ | ||
1028 | static int panic (lua_State *L) { | 1041 | static int panic (lua_State *L) { |
1029 | const char *msg = lua_tostring(L, -1); | 1042 | const char *msg = (lua_type(L, -1) == LUA_TSTRING) |
1030 | if (msg == NULL) msg = "error object is not a string"; | 1043 | ? lua_tostring(L, -1) |
1044 | : "error object is not a string"; | ||
1031 | lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n", | 1045 | lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n", |
1032 | msg); | 1046 | msg); |
1033 | return 0; /* return to Lua to abort */ | 1047 | return 0; /* return to Lua to abort */ |