From 2730c66f4ad22cddc3d18e96ac8ccbd8b662ed84 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Sun, 22 Aug 2021 00:59:47 -0700 Subject: [PATCH] Add GetTime to redbean Lua (#255) --- tool/net/help.txt | 5 ++++- tool/net/redbean.c | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tool/net/help.txt b/tool/net/help.txt index 8aa0b0f89ee..79edc0d9763 100644 --- a/tool/net/help.txt +++ b/tool/net/help.txt @@ -682,6 +682,9 @@ FUNCTIONS GetScheme() → str Returns scheme from Request-URL, if any. + GetTime() → seconds:number + Returns current time as a UNIX timestamp with 0.0001s precision. + GetPayload() → str Returns the request message payload, or empty string if there isn't one. @@ -700,7 +703,7 @@ FUNCTIONS GetRandomBytes([length:int]) → str Returns string with the specified number of random bytes (1..256). - If no length is specified, then the string of length 16 is returned. + If no length is specified, then a string of length 16 is returned. GetRedbeanVersion() → int Returns the Redbean version in the format 0xMMmmpp, with major (MM), diff --git a/tool/net/redbean.c b/tool/net/redbean.c index ddbb25d5d35..a0eb4a614f8 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -4846,6 +4846,11 @@ static int LuaSleep(lua_State *L) { return 0; } +static int LuaGetTime(lua_State *L) { + lua_pushnumber(L, nowl()); + return 1; +} + static int LuaIsHiddenPath(lua_State *L) { size_t n; const char *s; @@ -5201,6 +5206,7 @@ static const luaL_Reg kLuaFuncs[] = { {"GetRemoteAddr", LuaGetRemoteAddr}, // {"GetScheme", LuaGetScheme}, // {"GetServerAddr", LuaGetServerAddr}, // + {"GetTime", LuaGetTime}, // {"GetUrl", LuaGetUrl}, // {"GetUser", LuaGetUser}, // {"GetZipPaths", LuaGetZipPaths}, //