aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoramelia squires <[email protected]>2025-10-15 16:50:46 -0500
committeramelia squires <[email protected]>2025-10-15 16:50:46 -0500
commitb94f6d148193f91cab50d16e2873095827b89b1b (patch)
treef550bd912cdd4c5469cec1ac320cb9c874df3476 /src
parent8c2893be56c10af0a696282386b49fdb3c1e4a81 (diff)
better errors and docs
Diffstat (limited to 'src')
-rw-r--r--src/lua.h12
-rw-r--r--src/lullaby.c3
-rw-r--r--src/lullaby.h13
-rw-r--r--src/net.c3
-rw-r--r--src/net/lua.c8
-rw-r--r--src/reg.c4
6 files changed, 35 insertions, 8 deletions
diff --git a/src/lua.h b/src/lua.h
index 1d5bea1..8fc934c 100644
--- a/src/lua.h
+++ b/src/lua.h
@@ -7,6 +7,7 @@
#ifndef __lua_h
#define __lua_h
+
enum deep_copy_flags {
SKIP_META = (1 << 0),
SKIP_GC = (1 << 1),
@@ -81,12 +82,21 @@ void luaI_jointable(lua_State* L);
lua_settable(L, Tidx);\
lua_pop(L, 1);}
+//in lullaby.h
+extern int _print_errors;
+
#define luaI_error(L, en, str){\
lua_pushnil(L);\
lua_pushstring(L, str);\
+ if(_print_errors) printf("%s\n",str);\
lua_pushinteger(L, en);\
return 3;}
-
+#define luaI_assert(L, eq){_helperluaI_assert(L, eq, __FILE__, __LINE__);}
+#define _helperluaI_assert(L, eq, file, line){\
+ if(!(eq)){\
+ char err[1024] = {0};\
+ sprintf(err, "(%s:%i) %s assertion failed", file, line, #eq);\
+ luaI_error(L, -1, err);}}
int writer(lua_State*, const void*, size_t, void*);
diff --git a/src/lullaby.c b/src/lullaby.c
new file mode 100644
index 0000000..9033297
--- /dev/null
+++ b/src/lullaby.c
@@ -0,0 +1,3 @@
+#include "lullaby.h"
+
+int _print_errors = 0;
diff --git a/src/lullaby.h b/src/lullaby.h
new file mode 100644
index 0000000..9474a08
--- /dev/null
+++ b/src/lullaby.h
@@ -0,0 +1,13 @@
+#ifndef LULLABY_H
+#define LULLABY_H
+#pragma once
+#include "config.h"
+
+extern int _print_errors;
+
+static struct config lullaby_config[] = {
+ {.name = "print_errors", .type = c_int, .value = {.c_int = &_print_errors}},
+ {.type = c_none}
+};
+
+#endif
diff --git a/src/net.c b/src/net.c
index 71168c0..36b37b9 100644
--- a/src/net.c
+++ b/src/net.c
@@ -1057,7 +1057,8 @@ net_end:
}
parray_lclear(paths);
- luaI_error(L, 0, "close eventfd signal");
+ lua_pushnil(L);
+ return 1;
}
//TODO reformat all of this code and the structs (use more common/generic ones)
diff --git a/src/net/lua.c b/src/net/lua.c
index ab112fe..829c2f7 100644
--- a/src/net/lua.c
+++ b/src/net/lua.c
@@ -221,12 +221,8 @@ int l_sendfile(lua_State* L){
lua_gettable(L, -2);
int header = lua_gettop(L);
- if(access(path, F_OK)) {
- p_fatal("file not found"); //TODO: use diff errors here
- }
- if(access(path, R_OK)){
- p_fatal("missing permissions");
- }
+ luaI_assert(L, !access(path, F_OK) /*file not found*/);
+ luaI_assert(L, !access(path, R_OK) /*missing permissions*/);
lua_pushstring(L, "Content-Type");
lua_gettable(L, header);
diff --git a/src/reg.c b/src/reg.c
index 440a6f0..58acc40 100644
--- a/src/reg.c
+++ b/src/reg.c
@@ -7,6 +7,7 @@
#include "thread.h"
#include "test.h"
#include "config.h"
+#include "lullaby.h"
#define open_common(name, config)\
int luaopen_lullaby_##name (lua_State* L){\
@@ -49,6 +50,9 @@ int luaopen_lullaby(lua_State* L) {
push(top, test);
luaI_tsets(L, top, "version", GIT_COMMIT);
+ lua_pushvalue(L, top);
+ int idx = i_config_metatable(L, lullaby_config);
+
lua_settop(L, top);
return 1;
}