util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions

Actually just an alias of pushnil, but it does make it more obvious
where the failure conditions are, which is good for readability.
This commit is contained in:
Kim Alvefur 2020-06-07 02:25:56 +02:00
parent b50db46086
commit 625ec0a93f
6 changed files with 70 additions and 49 deletions

View file

@ -22,6 +22,9 @@
#if (LUA_VERSION_NUM == 501)
#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
#endif
#if (LUA_VERSION_NUM < 504)
#define luaL_pushfail lua_pushnil
#endif
static int Lget_nameservers(lua_State *L) {
char stack_buffer[1024]; // stack allocated buffer
@ -45,14 +48,14 @@ static int Lget_nameservers(lua_State *L) {
return 1;
} else {
lua_pushnil(L);
luaL_pushfail(L);
lua_pushfstring(L, "DnsQueryConfig returned %d", status);
return 2;
}
}
static int lerror(lua_State *L, char *string) {
lua_pushnil(L);
luaL_pushfail(L);
lua_pushfstring(L, "%s: %d", string, GetLastError());
return 2;
}