Skip to content

Commit e5d688f

Browse files
committed
lua: Implement think function
1 parent 0e730f0 commit e5d688f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ TODO:
1313

1414
## Main Functions
1515

16-
#### HttpServer HttpServer:Create()
16+
#### HttpServer httpserver.Create()
1717
Creates a new HTTPServer.
1818

19-
#### HttpServer:Destroy(HttpServer server)
19+
#### httpserver.Destroy(HttpServer server)
2020
Destroys the given http server.
2121

22-
## Basic Functions
22+
#### (internal function) httpserver.Think()
23+
Runs `HttpServer:Think()` on all existing http servers.
24+
Called by the `Think`(`HTTPServer`) hook we add.
25+
26+
## Class Functions
2327

2428
#### HttpServer:Start(String IP, Number Port)
2529
This will start or restart the HTTP Server, and it will listen on the given address + port.

source/lua.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@ LUA_FUNCTION_STATIC(httpserver_Create)
239239
return 1;
240240
}
241241

242+
LUA_FUNCTION_STATIC(httpserver_Think)
243+
{
244+
for (auto& [httpserver, _] : g_pPushedHttpServer)
245+
httpserver->Think();
246+
247+
return 0;
248+
}
249+
242250
LUA_FUNCTION_STATIC(httpserver_Destroy)
243251
{
244252
HttpServer* pServer = Get_HttpServer(1, true);
@@ -288,6 +296,7 @@ void LUA_InitServer(GarrysMod::Lua::ILuaBase* LUA)
288296
Util::StartTable();
289297
Util::AddFunc(httpserver_Create, "Create");
290298
Util::AddFunc(httpserver_Destroy, "Destroy");
299+
Util::AddFunc(httpserver_Think, "Think");
291300
Util::FinishTable("httpserver");
292301

293302
LUA->PushSpecial(GarrysMod::Lua::SPECIAL_GLOB);

0 commit comments

Comments
 (0)