summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--default.lua3
-rw-r--r--plop.c27
2 files changed, 7 insertions, 23 deletions
diff --git a/default.lua b/default.lua
index 0f9aaf4..1dc535f 100644
--- a/default.lua
+++ b/default.lua
@@ -1,6 +1,5 @@
--- Default client request handler.
---- @param request string Unparsed request from the client
--- @return string Body of the response
-function Handler (request)
+function Handler (...)
return [["Hello, from plop/Lua"]]
end
diff --git a/plop.c b/plop.c
index 51721b6..12cef19 100644
--- a/plop.c
+++ b/plop.c
@@ -109,29 +109,14 @@ int handle_client(lua_State * L, struct pollfd * pfd, struct request ** request,
return -1; // TODO: Handle errors properly
}
- // TODO: Remove debug information or move to logging
- printf(
- "(%.*s) %.*s\n",
- (*request)->version.length, (*request)->data + (*request)->version.start,
- (*request)->path.length, (*request)->data + (*request)->path.start);
-
- for (int h = 0; h < (*request)->headerc; ++h)
- {
- printf(
- "\t'%.*s' = '%.*s'\n",
- (*request)->headerv[h].name.length,
- (*request)->data + (*request)->headerv[h].name.start,
- (*request)->headerv[h].value.length,
- (*request)->data + (*request)->headerv[h].value.start);
- }
-
- // TODO: Use results from parsing instead of raw data
- lua_getglobal(L, "Handler");
- lua_pushlstring(L, (*request)->data, (*request)->length);
- lua_call(L, 1, 1);
+ // TODO: Push the handler to stack earlier to avoid shifting it.
+ lua_getglobal((*request)->lua, "Handler");
+ lua_insert((*request)->lua, 1);
+ lua_pushlstring((*request)->lua, (*request)->data, (*request)->length);
+ lua_call((*request)->lua, 2, 1);
size_t length;
- const char * body = lua_tolstring(L, -1, &length);
+ const char * body = lua_tolstring((*request)->lua, -1, &length);
if (NULL != body)
{