summaryrefslogtreecommitdiff
path: root/lua.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-08-15 13:44:36 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-08-15 13:44:36 -0300
commita1d8eb27431c02c4529be1efd92143ad65434f3a (patch)
tree58db9340ba2b8ea1cb91004b96f15a955f167c58 /lua.c
parentf64a1b175a5fa65434a073e6d071b32bb7b0ab69 (diff)
downloadlua-github-a1d8eb27431c02c4529be1efd92143ad65434f3a.tar.gz
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.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/lua.c b/lua.c
index fa534ba2..d13e203b 100644
--- a/lua.c
+++ b/lua.c
@@ -73,6 +73,7 @@ static void print_usage (const char *badoption) {
" -l name require library 'name' into global 'name'\n"
" -v show version information\n"
" -E ignore environment variables\n"
+ " -q turn warnings off\n"
" -- stop handling options\n"
" - stop handling options and execute stdin\n"
,
@@ -259,14 +260,18 @@ static int collectargs (char **argv, int *first) {
case '\0': /* '-' */
return args; /* script "name" is '-' */
case 'E':
- if (argv[i][2] != '\0') /* extra characters after 1st? */
+ if (argv[i][2] != '\0') /* extra characters? */
return has_error; /* invalid option */
args |= has_E;
break;
+ case 'q':
+ if (argv[i][2] != '\0') /* extra characters? */
+ return has_error; /* invalid option */
+ break;
case 'i':
args |= has_i; /* (-i implies -v) *//* FALLTHROUGH */
case 'v':
- if (argv[i][2] != '\0') /* extra characters after 1st? */
+ if (argv[i][2] != '\0') /* extra characters? */
return has_error; /* invalid option */
args |= has_v;
break;
@@ -289,7 +294,8 @@ static int collectargs (char **argv, int *first) {
/*
-** Processes options 'e' and 'l', which involve running Lua code.
+** Processes options 'e' and 'l', which involve running Lua code, and
+** 'q', which also affects the state.
** Returns 0 if some code raises an error.
*/
static int runargs (lua_State *L, char **argv, int n) {
@@ -297,15 +303,21 @@ static int runargs (lua_State *L, char **argv, int n) {
for (i = 1; i < n; i++) {
int option = argv[i][1];
lua_assert(argv[i][0] == '-'); /* already checked */
- if (option == 'e' || option == 'l') {
- int status;
- const char *extra = argv[i] + 2; /* both options need an argument */
- if (*extra == '\0') extra = argv[++i];
- lua_assert(extra != NULL);
- status = (option == 'e')
- ? dostring(L, extra, "=(command line)")
- : dolibrary(L, extra);
- if (status != LUA_OK) return 0;
+ switch (option) {
+ case 'e': case 'l': {
+ int status;
+ const char *extra = argv[i] + 2; /* both options need an argument */
+ if (*extra == '\0') extra = argv[++i];
+ lua_assert(extra != NULL);
+ status = (option == 'e')
+ ? dostring(L, extra, "=(command line)")
+ : dolibrary(L, extra);
+ if (status != LUA_OK) return 0;
+ break;
+ }
+ case 'q':
+ lua_warning(L, "@off", 0); /* no warnings */
+ break;
}
}
return 1;