Sfoglia il codice sorgente

'luaL_newstate' starts state with warnings on

It is easier to forget to turn them on then to turn them off.
Roberto I 1 mese fa
parent
commit
3d03ae5bd6
2 ha cambiato i file con 3 aggiunte e 2 eliminazioni
  1. 1 1
      lauxlib.c
  2. 2 1
      lua.c

+ 1 - 1
lauxlib.c

@@ -1185,7 +1185,7 @@ LUALIB_API lua_State *(luaL_newstate) (void) {
   lua_State *L = lua_newstate(luaL_alloc, NULL, luaL_makeseed(NULL));
   if (l_likely(L)) {
     lua_atpanic(L, &panic);
-    lua_setwarnf(L, warnfoff, L);  /* default is warnings off */
+    lua_setwarnf(L, warnfon, L);
   }
   return L;
 }

+ 2 - 1
lua.c

@@ -349,6 +349,7 @@ static int collectargs (char **argv, int *first) {
 */
 static int runargs (lua_State *L, char **argv, int n) {
   int i;
+  lua_warning(L, "@off", 0);  /* by default, Lua stand-alone has warnings off */
   for (i = 1; i < n; i++) {
     int option = argv[i][1];
     lua_assert(argv[i][0] == '-');  /* already checked */
@@ -725,7 +726,7 @@ static int pmain (lua_State *L) {
     if (handle_luainit(L) != LUA_OK)  /* run LUA_INIT */
       return 0;  /* error running LUA_INIT */
   }
-  if (!runargs(L, argv, optlim))  /* execute arguments -e and -l */
+  if (!runargs(L, argv, optlim))  /* execute arguments -e, -l, and -W */
     return 0;  /* something failed */
   if (script > 0) {  /* execute main script (if there is one) */
     if (handle_script(L, argv + script) != LUA_OK)