diff options
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -986,9 +986,35 @@ static int panic (lua_State *L) { | |||
986 | } | 986 | } |
987 | 987 | ||
988 | 988 | ||
989 | /* | ||
990 | ** checks whether 'message' ends with end-of-line | ||
991 | ** (and therefore is the last part of a warning) | ||
992 | */ | ||
993 | static int islast (const char *message) { | ||
994 | size_t len = strlen(message); | ||
995 | return (len > 0 && message[len - 1] == '\n'); | ||
996 | } | ||
997 | |||
998 | |||
999 | /* | ||
1000 | ** Emit a warning. If '*pud' is NULL, previous message was to be | ||
1001 | ** continued by the current one. | ||
1002 | */ | ||
1003 | static void warnf (void **pud, const char *message) { | ||
1004 | if (*pud == NULL) /* previous message was not the last? */ | ||
1005 | lua_writestringerror("%s", message); | ||
1006 | else /* start a new warning */ | ||
1007 | lua_writestringerror("Lua warning: %s", message); | ||
1008 | *pud = (islast(message)) ? pud : NULL; | ||
1009 | } | ||
1010 | |||
1011 | |||
989 | LUALIB_API lua_State *luaL_newstate (void) { | 1012 | LUALIB_API lua_State *luaL_newstate (void) { |
990 | lua_State *L = lua_newstate(l_alloc, NULL); | 1013 | lua_State *L = lua_newstate(l_alloc, NULL); |
991 | if (L) lua_atpanic(L, &panic); | 1014 | if (L) { |
1015 | lua_atpanic(L, &panic); | ||
1016 | lua_setwarnf(L, warnf, L); | ||
1017 | } | ||
992 | return L; | 1018 | return L; |
993 | } | 1019 | } |
994 | 1020 | ||