Skip to content

Commit

Permalink
lua: Implement think function
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelIT7 committed Dec 15, 2024
1 parent 0e730f0 commit e5d688f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ TODO:

## Main Functions

#### HttpServer HttpServer:Create()
#### HttpServer httpserver.Create()
Creates a new HTTPServer.

#### HttpServer:Destroy(HttpServer server)
#### httpserver.Destroy(HttpServer server)
Destroys the given http server.

## Basic Functions
#### (internal function) httpserver.Think()
Runs `HttpServer:Think()` on all existing http servers.
Called by the `Think`(`HTTPServer`) hook we add.

## Class Functions

#### HttpServer:Start(String IP, Number Port)
This will start or restart the HTTP Server, and it will listen on the given address + port.
Expand Down
9 changes: 9 additions & 0 deletions source/lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ LUA_FUNCTION_STATIC(httpserver_Create)
return 1;
}

LUA_FUNCTION_STATIC(httpserver_Think)
{
for (auto& [httpserver, _] : g_pPushedHttpServer)
httpserver->Think();

return 0;
}

LUA_FUNCTION_STATIC(httpserver_Destroy)
{
HttpServer* pServer = Get_HttpServer(1, true);
Expand Down Expand Up @@ -288,6 +296,7 @@ void LUA_InitServer(GarrysMod::Lua::ILuaBase* LUA)
Util::StartTable();
Util::AddFunc(httpserver_Create, "Create");
Util::AddFunc(httpserver_Destroy, "Destroy");
Util::AddFunc(httpserver_Think, "Think");
Util::FinishTable("httpserver");

LUA->PushSpecial(GarrysMod::Lua::SPECIAL_GLOB);
Expand Down

0 comments on commit e5d688f

Please sign in to comment.