diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2026-04-07 13:42:34 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2026-04-07 13:42:34 -0300 |
| commit | 29cf284089d543408d726440a3f1acaecdf73636 (patch) | |
| tree | e18363e7d53bb64d6f82943556ff0c3110778837 /lua.c | |
| parent | c037162a1a657088d722f550e287015525bb2259 (diff) | |
| download | lua-29cf284089d543408d726440a3f1acaecdf73636.tar.gz lua-29cf284089d543408d726440a3f1acaecdf73636.tar.bz2 lua-29cf284089d543408d726440a3f1acaecdf73636.zip | |
Avoid macros luaL_loadbuffer and luaL_loadfile
Use luaL_loadbufferx and luaL_loadfilex instead, being explicit about
whether to accept binary chunks.
Diffstat (limited to '')
| -rw-r--r-- | lua.c | 12 |
1 files changed, 6 insertions, 6 deletions
| @@ -207,12 +207,12 @@ static int dochunk (lua_State *L, int status) { | |||
| 207 | 207 | ||
| 208 | 208 | ||
| 209 | static int dofile (lua_State *L, const char *name) { | 209 | static int dofile (lua_State *L, const char *name) { |
| 210 | return dochunk(L, luaL_loadfile(L, name)); | 210 | return dochunk(L, luaL_loadfilex(L, name, "bt")); |
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | 213 | ||
| 214 | static int dostring (lua_State *L, const char *s, const char *name) { | 214 | static int dostring (lua_State *L, const char *s, const char *name) { |
| 215 | return dochunk(L, luaL_loadbuffer(L, s, strlen(s), name)); | 215 | return dochunk(L, luaL_loadbufferx(L, s, strlen(s), name, "t")); |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | 218 | ||
| @@ -266,7 +266,7 @@ static int handle_script (lua_State *L, char **argv) { | |||
| 266 | const char *fname = argv[0]; | 266 | const char *fname = argv[0]; |
| 267 | if (strcmp(fname, "-") == 0 && strcmp(argv[-1], "--") != 0) | 267 | if (strcmp(fname, "-") == 0 && strcmp(argv[-1], "--") != 0) |
| 268 | fname = NULL; /* stdin */ | 268 | fname = NULL; /* stdin */ |
| 269 | status = luaL_loadfile(L, fname); | 269 | status = luaL_loadfilex(L, fname, "bt"); |
| 270 | if (status == LUA_OK) { | 270 | if (status == LUA_OK) { |
| 271 | int n = pushargs(L); /* push arguments to script */ | 271 | int n = pushargs(L); /* push arguments to script */ |
| 272 | status = docall(L, n, LUA_MULTRET); | 272 | status = docall(L, n, LUA_MULTRET); |
| @@ -609,11 +609,11 @@ static int pushline (lua_State *L, int firstline) { | |||
| 609 | static int addreturn (lua_State *L) { | 609 | static int addreturn (lua_State *L) { |
| 610 | const char *line = lua_tostring(L, -1); /* original line */ | 610 | const char *line = lua_tostring(L, -1); /* original line */ |
| 611 | const char *retline = lua_pushfstring(L, "return %s;", line); | 611 | const char *retline = lua_pushfstring(L, "return %s;", line); |
| 612 | int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin"); | 612 | int status = luaL_loadbufferx(L, retline, strlen(retline), "=stdin", "t"); |
| 613 | if (status == LUA_OK) | 613 | if (status == LUA_OK) |
| 614 | lua_remove(L, -2); /* remove modified line */ | 614 | lua_remove(L, -2); /* remove modified line */ |
| 615 | else | 615 | else |
| 616 | lua_pop(L, 2); /* pop result from 'luaL_loadbuffer' and modified line */ | 616 | lua_pop(L, 2); /* pop result from 'luaL_loadbufferx' and modified line */ |
| 617 | return status; | 617 | return status; |
| 618 | } | 618 | } |
| 619 | 619 | ||
| @@ -640,7 +640,7 @@ static int multiline (lua_State *L) { | |||
| 640 | const char *line = lua_tolstring(L, 1, &len); /* get first line */ | 640 | const char *line = lua_tolstring(L, 1, &len); /* get first line */ |
| 641 | checklocal(line); | 641 | checklocal(line); |
| 642 | for (;;) { /* repeat until gets a complete statement */ | 642 | for (;;) { /* repeat until gets a complete statement */ |
| 643 | int status = luaL_loadbuffer(L, line, len, "=stdin"); /* try it */ | 643 | int status = luaL_loadbufferx(L, line, len, "=stdin", "t"); /* try it */ |
| 644 | if (!incomplete(L, status) || !pushline(L, 0)) | 644 | if (!incomplete(L, status) || !pushline(L, 0)) |
| 645 | return status; /* should not or cannot try to add continuation line */ | 645 | return status; /* should not or cannot try to add continuation line */ |
| 646 | lua_remove(L, -2); /* remove error message (from incomplete line) */ | 646 | lua_remove(L, -2); /* remove error message (from incomplete line) */ |
