diff options
author | Aki <please@ignore.pl> | 2021-02-23 23:11:36 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2021-02-23 23:11:36 +0100 |
commit | a8bcb7a654691a9a41ba193f16dca38bdd65bfa0 (patch) | |
tree | c0ac28b28f9377bc0f0e68aa1b7ee77044ff3772 | |
parent | c9c0384ebf1b882dd0035530e5949bfcbf979d2b (diff) | |
download | plop-a8bcb7a654691a9a41ba193f16dca38bdd65bfa0.zip plop-a8bcb7a654691a9a41ba193f16dca38bdd65bfa0.tar.gz plop-a8bcb7a654691a9a41ba193f16dca38bdd65bfa0.tar.bz2 |
Moved main Lua initialization to a function
-rw-r--r-- | main.c | 12 | ||||
-rw-r--r-- | plop.c | 17 | ||||
-rw-r--r-- | plop.h | 1 |
3 files changed, 25 insertions, 5 deletions
@@ -2,9 +2,7 @@ #include <sys/epoll.h> #include <unistd.h> -#include <lauxlib.h> #include <lua.h> -#include <lualib.h> #include "plop.h" @@ -25,9 +23,6 @@ static void usage(const char * const name) /// \return Error code int main(int argc, char ** argv) { - lua_State * L = luaL_newstate(); - luaL_openlibs(L); - const char * service = "8080"; int opt; @@ -54,6 +49,13 @@ int main(int argc, char ** argv) return 8; } + lua_State * L = plop_initialize_lua(); + + if (NULL == L) + { + return 9; + } + if (LUA_OK != plop_load_handler(L, argv[optind])) { return 2; @@ -13,11 +13,28 @@ #include <lauxlib.h> #include <lua.h> +#include <lualib.h> #include "connection.h" #include "request.h" #include "response.h" +/// Initializes new Lua state for the server. +/// \return Lua state +lua_State * plop_initialize_lua(void) +{ + lua_State * L = luaL_newstate(); + + if (NULL == L) + { + return NULL; + } + + luaL_openlibs(L); + + return L; +} + /// Tries to create, bind and start listening on INET server socket. /// \param node Hostname /// \param service Port @@ -4,6 +4,7 @@ #include <lua.h> +lua_State * plop_initialize_lua(void); int plop_make_server(const char *, const char *); int plop_load_handler(lua_State *, const char *); int plop_handle_client(lua_State *, struct epoll_event *); |