mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 07:18:30 +00:00
Add GetHostOs to redbean (#228)
This commit is contained in:
parent
0cdba6878b
commit
6bbb44c165
2 changed files with 31 additions and 0 deletions
|
@ -639,6 +639,9 @@ FUNCTIONS
|
||||||
Returns host associated with request. This will be the Host
|
Returns host associated with request. This will be the Host
|
||||||
header, if it's supplied. Otherwise it's the bind address.
|
header, if it's supplied. Otherwise it's the bind address.
|
||||||
|
|
||||||
|
GetHostOs() → str
|
||||||
|
Returns string that describes the host OS.
|
||||||
|
|
||||||
GetMonospaceWidth(str|char) → int
|
GetMonospaceWidth(str|char) → int
|
||||||
Returns monospace display width of string. This is useful for
|
Returns monospace display width of string. This is useful for
|
||||||
fixed-width formatting. For example, CJK characters typically take
|
fixed-width formatting. For example, CJK characters typically take
|
||||||
|
|
|
@ -5035,6 +5035,32 @@ static int LuaGetComment(lua_State *L) {
|
||||||
return 1;
|
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) {
|
static void LuaSetIntField(lua_State *L, const char *k, lua_Integer v) {
|
||||||
lua_pushinteger(L, v);
|
lua_pushinteger(L, v);
|
||||||
lua_setfield(L, -2, k);
|
lua_setfield(L, -2, k);
|
||||||
|
@ -5194,6 +5220,7 @@ static bool LuaRun(const char *path, bool mandatory) {
|
||||||
} else {
|
} else {
|
||||||
WARNF("%s %s", path, lua_tostring(L, -1));
|
WARNF("%s %s", path, lua_tostring(L, -1));
|
||||||
}
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
free(code);
|
free(code);
|
||||||
}
|
}
|
||||||
|
@ -5236,6 +5263,7 @@ static const luaL_Reg kLuaFuncs[] = {
|
||||||
{"GetHeader", LuaGetHeader}, //
|
{"GetHeader", LuaGetHeader}, //
|
||||||
{"GetHeaders", LuaGetHeaders}, //
|
{"GetHeaders", LuaGetHeaders}, //
|
||||||
{"GetHost", LuaGetHost}, //
|
{"GetHost", LuaGetHost}, //
|
||||||
|
{"GetHostOs", LuaGetHostOs}, //
|
||||||
{"GetHttpReason", LuaGetHttpReason}, //
|
{"GetHttpReason", LuaGetHttpReason}, //
|
||||||
{"GetHttpVersion", LuaGetHttpVersion}, //
|
{"GetHttpVersion", LuaGetHttpVersion}, //
|
||||||
{"GetLastModifiedTime", LuaGetLastModifiedTime}, //
|
{"GetLastModifiedTime", LuaGetLastModifiedTime}, //
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue