MCPcopy Create free account
hub / github.com/Overload-Technologies/Overload / warnf

Function warnf

Dependencies/lua/src/ltests.c:95–156  ·  view source on GitHub ↗

** Warning function for tests. First, it concatenates all parts of ** a warning in buffer 'buff'. Then, it has three modes: ** - 0.normal: messages starting with '#' are shown on standard output; ** - other messages abort the tests (they represent real warning ** conditions; the standard tests should not generate these conditions ** unexpectedly); ** - 1.allow: all messages are shown; ** - 2.store

Source from the content-addressed store, hash-verified

93** - 2.store: all warnings go to the global '_WARN';
94*/
95static void warnf (void *ud, const char *msg, int tocont) {
96 lua_State *L = cast(lua_State *, ud);
97 static char buff[200] = ""; /* should be enough for tests... */
98 static int onoff = 0;
99 static int mode = 0; /* start in normal mode */
100 static int lasttocont = 0;
101 if (!lasttocont && !tocont && *msg == '@') { /* control message? */
102 if (buff[0] != '\0')
103 badexit("Control warning during warning: %s\naborting...\n", msg, buff);
104 if (strcmp(msg, "@off") == 0)
105 onoff = 0;
106 else if (strcmp(msg, "@on") == 0)
107 onoff = 1;
108 else if (strcmp(msg, "@normal") == 0)
109 mode = 0;
110 else if (strcmp(msg, "@allow") == 0)
111 mode = 1;
112 else if (strcmp(msg, "@store") == 0)
113 mode = 2;
114 else
115 badexit("Invalid control warning in test mode: %s\naborting...\n",
116 msg, NULL);
117 return;
118 }
119 lasttocont = tocont;
120 if (strlen(msg) >= sizeof(buff) - strlen(buff))
121 badexit("warnf-buffer overflow (%s)\n", msg, buff);
122 strcat(buff, msg); /* add new message to current warning */
123 if (!tocont) { /* message finished? */
124 lua_unlock(L);
125 luaL_checkstack(L, 1, "warn stack space");
126 lua_getglobal(L, "_WARN");
127 if (!lua_toboolean(L, -1))
128 lua_pop(L, 1); /* ok, no previous unexpected warning */
129 else {
130 badexit("Unhandled warning in store mode: %s\naborting...\n",
131 lua_tostring(L, -1), buff);
132 }
133 lua_lock(L);
134 switch (mode) {
135 case 0: { /* normal */
136 if (buff[0] != '#' && onoff) /* unexpected warning? */
137 badexit("Unexpected warning in test mode: %s\naborting...\n",
138 buff, NULL);
139 } /* FALLTHROUGH */
140 case 1: { /* allow */
141 if (onoff)
142 fprintf(stderr, "Lua warning: %s\n", buff); /* print warning */
143 break;
144 }
145 case 2: { /* store */
146 lua_unlock(L);
147 luaL_checkstack(L, 1, "warn stack space");
148 lua_pushstring(L, buff);
149 lua_setglobal(L, "_WARN"); /* assign message to global '_WARN' */
150 lua_lock(L);
151 break;
152 }

Callers

nothing calls this directly

Calls 6

badexitFunction · 0.85
lua_getglobalFunction · 0.85
lua_tobooleanFunction · 0.85
lua_pushstringFunction · 0.85
lua_setglobalFunction · 0.85
luaL_checkstackFunction · 0.70

Tested by

no test coverage detected