From a1d8eb27431c02c4529be1efd92143ad65434f3a Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 15 Aug 2019 13:44:36 -0300 Subject: 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. --- lua.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'lua.c') 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; -- cgit v1.2.3-55-g6feb