From 85c4718212e44b0e01485260b5f1574d5c7411a9 Mon Sep 17 00:00:00 2001 From: ame Date: Sun, 21 Jan 2024 19:35:25 -0600 Subject: stuff --- src/lua.h | 11 ++++++++--- src/net.c | 8 +++++--- src/reg.c | 56 ++++++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 55 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/lua.h b/src/lua.h index 41d5c89..6b146f6 100644 --- a/src/lua.h +++ b/src/lua.h @@ -1,3 +1,8 @@ -#include -#include -#include +#include +#include +#include + +#define lua_objlen(L,i) lua_rawlen(L,(i)) +#define luaL_register(L, M, F) luaL_newlib(L, F); + + diff --git a/src/net.c b/src/net.c index b0fd09e..7beec3a 100644 --- a/src/net.c +++ b/src/net.c @@ -6,6 +6,7 @@ #else #include #include +#define closesocket close #endif #include @@ -208,11 +209,12 @@ int l_send(lua_State* L){ lua_pushstring(L, "client_fd"); lua_gettable(L, res_idx); int client_fd = luaL_checkinteger(L, -1); - + + /* lua_pushvalue(L, res_idx); lua_pushstring(L, "Content"); - lua_gettable(L, res_idx); - char* content = (char*)luaL_checkstring(L, -1); + lua_gettable(L, res_idx);*/ + char* content = (char*)luaL_checkstring(L, 2); lua_pushvalue(L, res_idx); lua_pushstring(L, "Content-Type"); diff --git a/src/reg.c b/src/reg.c index a9c07bb..030a93f 100644 --- a/src/reg.c +++ b/src/reg.c @@ -5,33 +5,61 @@ #include "io.h" #include "math.h" #include "net.h" +#include + +static int lua_exit(lua_State* L){ + printf("hi\n"); + return 0; +} + +void sigHandle(int s){ + signal(s, SIG_IGN); + printf("meow\n"); + signal(s, sigHandle); +} + int luaopen_llib(lua_State* L) { - lua_newtable(L); + /* + lua_newuserdata(L, sizeof(void*)); + luaL_newmetatable(L, "gc"); + lua_pushstring(L, "__gc"); + lua_pushcfunction(L, &lua_exit); + lua_settable(L, -3); + + lua_setmetatable(L, -2); + lua_setfield(L, LUA_REGISTRYINDEX, "grr"); + signal(SIGTERM, sigHandle); + signal(SIGINT, sigHandle); +*/ //create .array functions lua_newtable(L); + + //lua_newtable(L); + lua_pushstring(L, "array"); luaL_register(L, NULL, array_function_list); - lua_setfield(L, 2, "array"); - - lua_newtable(L); + lua_settable(L, -3); + + lua_pushstring(L, "crypto"); luaL_register(L, NULL, crypto_function_list); - lua_setfield(L, 2, "crypto"); - - lua_newtable(L); + lua_settable(L, -3); + + lua_pushstring(L, "io"); luaL_register(L, NULL, io_function_list); - lua_setfield(L, 2, "io"); + lua_settable(L, -3); - lua_newtable(L); + lua_pushstring(L, "math"); luaL_register(L, NULL, math_function_list); - lua_setfield(L, 2, "math"); + lua_settable(L, -3); - lua_newtable(L); + lua_pushstring(L, "config"); luaL_register(L, NULL, config_function_list); - lua_setfield(L, 2, "config"); + lua_settable(L, -3); - lua_newtable(L); + lua_pushstring(L, "net"); luaL_register(L, NULL, net_function_list); - lua_setfield(L, 2, "net"); + lua_settable(L, -3); + //make llib global lua_setglobal(L, "llib"); return 1; -- cgit v1.2.3