diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-08-15 13:44:36 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-08-15 13:44:36 -0300 |
commit | a1d8eb27431c02c4529be1efd92143ad65434f3a (patch) | |
tree | 58db9340ba2b8ea1cb91004b96f15a955f167c58 /lua.c | |
parent | f64a1b175a5fa65434a073e6d071b32bb7b0ab69 (diff) | |
download | lua-a1d8eb27431c02c4529be1efd92143ad65434f3a.tar.gz lua-a1d8eb27431c02c4529be1efd92143ad65434f3a.tar.bz2 lua-a1d8eb27431c02c4529be1efd92143ad65434f3a.zip |
Added control messages to warnings
Added the concept of control messages to the warning system, plus the
implementation of the controls "@on"/"@off" to turn warnings on/off.
Moreover, the warning system in the test library adds some other
controls to ease the test of warnings.
Diffstat (limited to 'lua.c')
-rw-r--r-- | lua.c | 36 |
1 files changed, 24 insertions, 12 deletions
@@ -73,6 +73,7 @@ static void print_usage (const char *badoption) { | |||
73 | " -l name require library 'name' into global 'name'\n" | 73 | " -l name require library 'name' into global 'name'\n" |
74 | " -v show version information\n" | 74 | " -v show version information\n" |
75 | " -E ignore environment variables\n" | 75 | " -E ignore environment variables\n" |
76 | " -q turn warnings off\n" | ||
76 | " -- stop handling options\n" | 77 | " -- stop handling options\n" |
77 | " - stop handling options and execute stdin\n" | 78 | " - stop handling options and execute stdin\n" |
78 | , | 79 | , |
@@ -259,14 +260,18 @@ static int collectargs (char **argv, int *first) { | |||
259 | case '\0': /* '-' */ | 260 | case '\0': /* '-' */ |
260 | return args; /* script "name" is '-' */ | 261 | return args; /* script "name" is '-' */ |
261 | case 'E': | 262 | case 'E': |
262 | if (argv[i][2] != '\0') /* extra characters after 1st? */ | 263 | if (argv[i][2] != '\0') /* extra characters? */ |
263 | return has_error; /* invalid option */ | 264 | return has_error; /* invalid option */ |
264 | args |= has_E; | 265 | args |= has_E; |
265 | break; | 266 | break; |
267 | case 'q': | ||
268 | if (argv[i][2] != '\0') /* extra characters? */ | ||
269 | return has_error; /* invalid option */ | ||
270 | break; | ||
266 | case 'i': | 271 | case 'i': |
267 | args |= has_i; /* (-i implies -v) *//* FALLTHROUGH */ | 272 | args |= has_i; /* (-i implies -v) *//* FALLTHROUGH */ |
268 | case 'v': | 273 | case 'v': |
269 | if (argv[i][2] != '\0') /* extra characters after 1st? */ | 274 | if (argv[i][2] != '\0') /* extra characters? */ |
270 | return has_error; /* invalid option */ | 275 | return has_error; /* invalid option */ |
271 | args |= has_v; | 276 | args |= has_v; |
272 | break; | 277 | break; |
@@ -289,7 +294,8 @@ static int collectargs (char **argv, int *first) { | |||
289 | 294 | ||
290 | 295 | ||
291 | /* | 296 | /* |
292 | ** Processes options 'e' and 'l', which involve running Lua code. | 297 | ** Processes options 'e' and 'l', which involve running Lua code, and |
298 | ** 'q', which also affects the state. | ||
293 | ** Returns 0 if some code raises an error. | 299 | ** Returns 0 if some code raises an error. |
294 | */ | 300 | */ |
295 | static int runargs (lua_State *L, char **argv, int n) { | 301 | static int runargs (lua_State *L, char **argv, int n) { |
@@ -297,15 +303,21 @@ static int runargs (lua_State *L, char **argv, int n) { | |||
297 | for (i = 1; i < n; i++) { | 303 | for (i = 1; i < n; i++) { |
298 | int option = argv[i][1]; | 304 | int option = argv[i][1]; |
299 | lua_assert(argv[i][0] == '-'); /* already checked */ | 305 | lua_assert(argv[i][0] == '-'); /* already checked */ |
300 | if (option == 'e' || option == 'l') { | 306 | switch (option) { |
301 | int status; | 307 | case 'e': case 'l': { |
302 | const char *extra = argv[i] + 2; /* both options need an argument */ | 308 | int status; |
303 | if (*extra == '\0') extra = argv[++i]; | 309 | const char *extra = argv[i] + 2; /* both options need an argument */ |
304 | lua_assert(extra != NULL); | 310 | if (*extra == '\0') extra = argv[++i]; |
305 | status = (option == 'e') | 311 | lua_assert(extra != NULL); |
306 | ? dostring(L, extra, "=(command line)") | 312 | status = (option == 'e') |
307 | : dolibrary(L, extra); | 313 | ? dostring(L, extra, "=(command line)") |
308 | if (status != LUA_OK) return 0; | 314 | : dolibrary(L, extra); |
315 | if (status != LUA_OK) return 0; | ||
316 | break; | ||
317 | } | ||
318 | case 'q': | ||
319 | lua_warning(L, "@off", 0); /* no warnings */ | ||
320 | break; | ||
309 | } | 321 | } |
310 | } | 322 | } |
311 | return 1; | 323 | return 1; |