Software /
code /
prosody
Comparison
util-src/windows.c @ 10921:6eb5d2bb11af
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 07 Jun 2020 02:25:56 +0200 |
parent | 7889:b8d694646597 |
child | 12575:1f6f05a98fcd |
comparison
equal
deleted
inserted
replaced
10920:c171b4c59bd1 | 10921:6eb5d2bb11af |
---|---|
20 #include "lauxlib.h" | 20 #include "lauxlib.h" |
21 | 21 |
22 #if (LUA_VERSION_NUM == 501) | 22 #if (LUA_VERSION_NUM == 501) |
23 #define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R) | 23 #define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R) |
24 #endif | 24 #endif |
25 #if (LUA_VERSION_NUM < 504) | |
26 #define luaL_pushfail lua_pushnil | |
27 #endif | |
25 | 28 |
26 static int Lget_nameservers(lua_State *L) { | 29 static int Lget_nameservers(lua_State *L) { |
27 char stack_buffer[1024]; // stack allocated buffer | 30 char stack_buffer[1024]; // stack allocated buffer |
28 IP4_ARRAY *ips = (IP4_ARRAY *) stack_buffer; | 31 IP4_ARRAY *ips = (IP4_ARRAY *) stack_buffer; |
29 DWORD len = sizeof(stack_buffer); | 32 DWORD len = sizeof(stack_buffer); |
43 lua_rawseti(L, -2, i + 1); | 46 lua_rawseti(L, -2, i + 1); |
44 } | 47 } |
45 | 48 |
46 return 1; | 49 return 1; |
47 } else { | 50 } else { |
48 lua_pushnil(L); | 51 luaL_pushfail(L); |
49 lua_pushfstring(L, "DnsQueryConfig returned %d", status); | 52 lua_pushfstring(L, "DnsQueryConfig returned %d", status); |
50 return 2; | 53 return 2; |
51 } | 54 } |
52 } | 55 } |
53 | 56 |
54 static int lerror(lua_State *L, char *string) { | 57 static int lerror(lua_State *L, char *string) { |
55 lua_pushnil(L); | 58 luaL_pushfail(L); |
56 lua_pushfstring(L, "%s: %d", string, GetLastError()); | 59 lua_pushfstring(L, "%s: %d", string, GetLastError()); |
57 return 2; | 60 return 2; |
58 } | 61 } |
59 | 62 |
60 static int Lget_consolecolor(lua_State *L) { | 63 static int Lget_consolecolor(lua_State *L) { |