Add GetHostOs to redbean.

This commit is contained in:
Paul Kulchenko 2021-08-07 10:06:59 -07:00
parent bde630a7ad
commit 0115169a7b
2 changed files with 30 additions and 0 deletions

View file

@ -639,6 +639,9 @@ FUNCTIONS
Returns host associated with request. This will be the Host
header, if it's supplied. Otherwise it's the bind address.
GetHostOs() → str
Returns string that describes the host OS.
GetMonospaceWidth(str|char) → int
Returns monospace display width of string. This is useful for
fixed-width formatting. For example, CJK characters typically take

View file

@ -5035,6 +5035,32 @@ static int LuaGetComment(lua_State *L) {
return 1;
}
static int LuaGetHostOs(lua_State *L) {
const char *s = NULL;
if (IsLinux()) {
s = "LINUX";
} else if (IsMetal()) {
s = "METAL";
} else if (IsWindows()) {
s = "WINDOWS";
} else if (IsXnu()) {
s = "XNU";
} else if (IsOpenbsd()) {
s = "OPENBSD";
} else if (IsFreebsd()) {
s = "FREEBSD";
} else if (IsNetbsd()) {
s = "NETBSD";
}
if (s) {
lua_pushstring(L, s);
} else {
lua_pushnil(L);
}
return 1;
}
static void LuaSetIntField(lua_State *L, const char *k, lua_Integer v) {
lua_pushinteger(L, v);
lua_setfield(L, -2, k);
@ -5237,6 +5263,7 @@ static const luaL_Reg kLuaFuncs[] = {
{"GetHeader", LuaGetHeader}, //
{"GetHeaders", LuaGetHeaders}, //
{"GetHost", LuaGetHost}, //
{"GetHostOs", LuaGetHostOs}, //
{"GetHttpReason", LuaGetHttpReason}, //
{"GetHttpVersion", LuaGetHttpVersion}, //
{"GetLastModifiedTime", LuaGetLastModifiedTime}, //