Skip to content

Commit

Permalink
Add GetTime to redbean Lua (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkulchenko authored Aug 22, 2021
1 parent c506584 commit 2730c66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tool/net/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions tool/net/redbean.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -5201,6 +5206,7 @@ static const luaL_Reg kLuaFuncs[] = {
{"GetRemoteAddr", LuaGetRemoteAddr}, //
{"GetScheme", LuaGetScheme}, //
{"GetServerAddr", LuaGetServerAddr}, //
{"GetTime", LuaGetTime}, //
{"GetUrl", LuaGetUrl}, //
{"GetUser", LuaGetUser}, //
{"GetZipPaths", LuaGetZipPaths}, //
Expand Down

0 comments on commit 2730c66

Please sign in to comment.