Add Sleep to Lua in redbean.

This commit is contained in:
Paul Kulchenko 2021-07-31 23:17:13 -07:00
parent 0b317523a0
commit 7e5d8b1a04
2 changed files with 10 additions and 0 deletions

View file

@ -859,6 +859,10 @@ FUNCTIONS
Slurp(filename:str) → str
Reads file data from local file system.
Sleep(seconds:number)
Sleeps the specified number of seconds (can be fractional). The
smallest interval is a millisecond.
Route([host:str,[path:str]])
Instructs redbean to follow the normal HTTP serving path. This
function is useful when writing an OnHttpRequest handler, since

View file

@ -4879,6 +4879,11 @@ static int LuaLog(lua_State *L) {
return 0;
}
static int LuaSleep(lua_State *L) {
usleep(1000000 * luaL_checknumber(L, 1));
return 0;
}
static int LuaIsHiddenPath(lua_State *L) {
size_t n;
const char *s;
@ -5260,6 +5265,7 @@ static const luaL_Reg kLuaFuncs[] = {
{"Sha256", LuaSha256}, //
{"Sha384", LuaSha384}, //
{"Sha512", LuaSha512}, //
{"Sleep", LuaSleep}, //
{"Slurp", LuaSlurp}, //
{"StoreAsset", LuaStoreAsset}, //
{"Underlong", LuaUnderlong}, //