aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-08-20 13:42:26 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-08-20 13:42:26 -0300
commitbe78aeae4c429d7d68af3a3e1b0cf8e52fcff160 (patch)
treee81d25014e238f589997f109ba10a875c3a875dc
parent5bc47fe83087e0686f4639d031801837846e4c65 (diff)
downloadlua-be78aeae4c429d7d68af3a3e1b0cf8e52fcff160.tar.gz
lua-be78aeae4c429d7d68af3a3e1b0cf8e52fcff160.tar.bz2
lua-be78aeae4c429d7d68af3a3e1b0cf8e52fcff160.zip
Default for warnings changed to "off"
Warnings are mostly a tool to help developers (e.g., by showing hidden error messages); regular users usually don't need to see them.
-rwxr-xr-xall2
-rw-r--r--lauxlib.c2
-rw-r--r--ltests.c2
-rw-r--r--lua.c10
-rw-r--r--manual/manual.of4
-rw-r--r--testes/all.lua5
-rw-r--r--testes/coroutine.lua1
-rw-r--r--testes/gc.lua2
-rw-r--r--testes/locals.lua1
-rw-r--r--testes/main.lua11
10 files changed, 23 insertions, 17 deletions
diff --git a/all b/all
index 8f78ee4d..2a8cb92f 100755
--- a/all
+++ b/all
@@ -2,7 +2,7 @@ make -s -j
2cd testes/libs; make -s 2cd testes/libs; make -s
3cd .. # back to directory 'testes' 3cd .. # back to directory 'testes'
4ulimit -S -s 2000 4ulimit -S -s 2000
5if { ../lua all.lua; } then 5if { ../lua -W all.lua; } then
6 echo -e "\n\n final OK!!!!\n\n" 6 echo -e "\n\n final OK!!!!\n\n"
7else 7else
8 echo -e "\n\n >>>> BUG!!!!\n\n" 8 echo -e "\n\n >>>> BUG!!!!\n\n"
diff --git a/lauxlib.c b/lauxlib.c
index 5a040ac6..b6740b17 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1037,7 +1037,7 @@ LUALIB_API lua_State *luaL_newstate (void) {
1037 lua_atpanic(L, &panic); 1037 lua_atpanic(L, &panic);
1038 warnstate = (int *)lua_newuserdatauv(L, sizeof(int), 0); 1038 warnstate = (int *)lua_newuserdatauv(L, sizeof(int), 0);
1039 luaL_ref(L, LUA_REGISTRYINDEX); /* make sure it won't be collected */ 1039 luaL_ref(L, LUA_REGISTRYINDEX); /* make sure it won't be collected */
1040 *warnstate = 1; /* next message starts a new warning */ 1040 *warnstate = 0; /* default is warnings off */
1041 lua_setwarnf(L, warnf, warnstate); 1041 lua_setwarnf(L, warnf, warnstate);
1042 } 1042 }
1043 return L; 1043 return L;
diff --git a/ltests.c b/ltests.c
index 95c41fd9..0d4ec938 100644
--- a/ltests.c
+++ b/ltests.c
@@ -92,7 +92,7 @@ static int tpanic (lua_State *L) {
92static void warnf (void *ud, const char *msg, int tocont) { 92static void warnf (void *ud, const char *msg, int tocont) {
93 lua_State *L = cast(lua_State *, ud); 93 lua_State *L = cast(lua_State *, ud);
94 static char buff[200] = ""; /* should be enough for tests... */ 94 static char buff[200] = ""; /* should be enough for tests... */
95 static int onoff = 1; 95 static int onoff = 0;
96 static int mode = 0; /* start in normal mode */ 96 static int mode = 0; /* start in normal mode */
97 static int lasttocont = 0; 97 static int lasttocont = 0;
98 if (!lasttocont && !tocont && *msg == '@') { /* control message? */ 98 if (!lasttocont && !tocont && *msg == '@') { /* control message? */
diff --git a/lua.c b/lua.c
index d13e203b..18f53c30 100644
--- a/lua.c
+++ b/lua.c
@@ -73,7 +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 " -W turn warnings on\n"
77 " -- stop handling options\n" 77 " -- stop handling options\n"
78 " - stop handling options and execute stdin\n" 78 " - stop handling options and execute stdin\n"
79 , 79 ,
@@ -264,7 +264,7 @@ static int collectargs (char **argv, int *first) {
264 return has_error; /* invalid option */ 264 return has_error; /* invalid option */
265 args |= has_E; 265 args |= has_E;
266 break; 266 break;
267 case 'q': 267 case 'W':
268 if (argv[i][2] != '\0') /* extra characters? */ 268 if (argv[i][2] != '\0') /* extra characters? */
269 return has_error; /* invalid option */ 269 return has_error; /* invalid option */
270 break; 270 break;
@@ -295,7 +295,7 @@ static int collectargs (char **argv, int *first) {
295 295
296/* 296/*
297** Processes options 'e' and 'l', which involve running Lua code, and 297** Processes options 'e' and 'l', which involve running Lua code, and
298** 'q', which also affects the state. 298** 'W', which also affects the state.
299** Returns 0 if some code raises an error. 299** Returns 0 if some code raises an error.
300*/ 300*/
301static int runargs (lua_State *L, char **argv, int n) { 301static int runargs (lua_State *L, char **argv, int n) {
@@ -315,8 +315,8 @@ static int runargs (lua_State *L, char **argv, int n) {
315 if (status != LUA_OK) return 0; 315 if (status != LUA_OK) return 0;
316 break; 316 break;
317 } 317 }
318 case 'q': 318 case 'W':
319 lua_warning(L, "@off", 0); /* no warnings */ 319 lua_warning(L, "@on", 0); /* warnings on */
320 break; 320 break;
321 } 321 }
322 } 322 }
diff --git a/manual/manual.of b/manual/manual.of
index a3990d33..292d1e51 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -8735,7 +8735,7 @@ The options are:
8735@item{@T{-i}| enters interactive mode after running @rep{script};} 8735@item{@T{-i}| enters interactive mode after running @rep{script};}
8736@item{@T{-v}| prints version information;} 8736@item{@T{-v}| prints version information;}
8737@item{@T{-E}| ignores environment variables;} 8737@item{@T{-E}| ignores environment variables;}
8738@item{@T{-q}| turn warnings off;} 8738@item{@T{-W}| turn warnings on;}
8739@item{@T{--}| stops handling options;} 8739@item{@T{--}| stops handling options;}
8740@item{@T{-}| executes @id{stdin} as a file and stops handling options.} 8740@item{@T{-}| executes @id{stdin} as a file and stops handling options.}
8741} 8741}
@@ -8761,7 +8761,7 @@ setting the values of
8761@Lid{package.path} and @Lid{package.cpath} 8761@Lid{package.path} and @Lid{package.cpath}
8762with the default paths defined in @id{luaconf.h}. 8762with the default paths defined in @id{luaconf.h}.
8763 8763
8764The options @T{-e}, @T{-l}, and @T{-q} are handled in 8764The options @T{-e}, @T{-l}, and @T{-W} are handled in
8765the order they appear. 8765the order they appear.
8766For instance, an invocation like 8766For instance, an invocation like
8767@verbatim{ 8767@verbatim{
diff --git a/testes/all.lua b/testes/all.lua
index 42809b9a..db074dd8 100644
--- a/testes/all.lua
+++ b/testes/all.lua
@@ -5,8 +5,8 @@
5 5
6local version = "Lua 5.4" 6local version = "Lua 5.4"
7if _VERSION ~= version then 7if _VERSION ~= version then
8 warn("This test suite is for ", version, 8 io.stderr:write("This test suite is for ", version,
9 ", not for ", _VERSION, "\nExiting tests") 9 ", not for ", _VERSION, "\nExiting tests")
10 return 10 return
11end 11end
12 12
@@ -210,6 +210,7 @@ if #msgs > 0 then
210end 210end
211 211
212print("(there should be two warnings now)") 212print("(there should be two warnings now)")
213warn("@on")
213warn("#This is ", "an expected", " warning") 214warn("#This is ", "an expected", " warning")
214warn("@off") 215warn("@off")
215warn("******** THIS WARNING SHOULD NOT APPEAR **********") 216warn("******** THIS WARNING SHOULD NOT APPEAR **********")
diff --git a/testes/coroutine.lua b/testes/coroutine.lua
index 4fc23261..79bbf2ea 100644
--- a/testes/coroutine.lua
+++ b/testes/coroutine.lua
@@ -163,6 +163,7 @@ do
163 assert(not X and coroutine.status(co) == "dead") 163 assert(not X and coroutine.status(co) == "dead")
164 164
165 -- error closing a coroutine 165 -- error closing a coroutine
166 warn("@on")
166 local x = 0 167 local x = 0
167 co = coroutine.create(function() 168 co = coroutine.create(function()
168 local y <close> = func2close(function (self,err) 169 local y <close> = func2close(function (self,err)
diff --git a/testes/gc.lua b/testes/gc.lua
index 34854d6f..bb4e3493 100644
--- a/testes/gc.lua
+++ b/testes/gc.lua
@@ -369,7 +369,7 @@ if T then
369 s[n] = i 369 s[n] = i
370 end 370 end
371 371
372 warn("@store") 372 warn("@on"); warn("@store")
373 collectgarbage() 373 collectgarbage()
374 assert(string.find(_WARN, "error in __gc metamethod")) 374 assert(string.find(_WARN, "error in __gc metamethod"))
375 assert(string.match(_WARN, "@(.-)@") == "expected"); _WARN = nil 375 assert(string.match(_WARN, "@(.-)@") == "expected"); _WARN = nil
diff --git a/testes/locals.lua b/testes/locals.lua
index b4de523d..58ad18cc 100644
--- a/testes/locals.lua
+++ b/testes/locals.lua
@@ -313,6 +313,7 @@ local function checkwarn (msg)
313 end 313 end
314end 314end
315 315
316warn("@on")
316 317
317do print("testing errors in __close") 318do print("testing errors in __close")
318 319
diff --git a/testes/main.lua b/testes/main.lua
index 5d2652cb..de14a088 100644
--- a/testes/main.lua
+++ b/testes/main.lua
@@ -221,8 +221,11 @@ assert(string.find(getoutput(), "error calling 'print'"))
221RUN('echo "io.stderr:write(1000)\ncont" | lua -e "require\'debug\'.debug()" 2> %s', out) 221RUN('echo "io.stderr:write(1000)\ncont" | lua -e "require\'debug\'.debug()" 2> %s', out)
222checkout("lua_debug> 1000lua_debug> ") 222checkout("lua_debug> 1000lua_debug> ")
223 223
224-- test warnings 224
225RUN('echo "io.stderr:write(1); warn[[XXX]]" | lua -q 2> %s', out) 225print("testing warnings")
226
227-- no warnings by default
228RUN('echo "io.stderr:write(1); warn[[XXX]]" | lua 2> %s', out)
226checkout("1") 229checkout("1")
227 230
228prepfile[[ 231prepfile[[
@@ -236,7 +239,7 @@ warn("", "@on") -- again, no control, real warning
236warn("@on") -- keep it "started" 239warn("@on") -- keep it "started"
237warn("Z", "Z", "Z") -- common warning 240warn("Z", "Z", "Z") -- common warning
238]] 241]]
239RUN('lua %s 2> %s', prog, out) 242RUN('lua -W %s 2> %s', prog, out)
240checkout[[ 243checkout[[
241Lua warning: @offXXX@off 244Lua warning: @offXXX@off
242Lua warning: @on 245Lua warning: @on
@@ -250,7 +253,7 @@ warn("@allow")
250u1 = setmetatable({}, {__gc = function () error("XYZ") end}) 253u1 = setmetatable({}, {__gc = function () error("XYZ") end})
251u2 = setmetatable({}, {__gc = function () error("ZYX") end}) 254u2 = setmetatable({}, {__gc = function () error("ZYX") end})
252]] 255]]
253RUN('lua %s 2> %s', prog, out) 256RUN('lua -W %s 2> %s', prog, out)
254checkprogout("ZYX)\nXYZ)\n") 257checkprogout("ZYX)\nXYZ)\n")
255 258
256 259