diff options
| author | amelia squires <[email protected]> | 2025-10-15 16:50:46 -0500 |
|---|---|---|
| committer | amelia squires <[email protected]> | 2025-10-15 16:50:46 -0500 |
| commit | b94f6d148193f91cab50d16e2873095827b89b1b (patch) | |
| tree | f550bd912cdd4c5469cec1ac320cb9c874df3476 /src | |
| parent | 8c2893be56c10af0a696282386b49fdb3c1e4a81 (diff) | |
better errors and docs
Diffstat (limited to 'src')
| -rw-r--r-- | src/lua.h | 12 | ||||
| -rw-r--r-- | src/lullaby.c | 3 | ||||
| -rw-r--r-- | src/lullaby.h | 13 | ||||
| -rw-r--r-- | src/net.c | 3 | ||||
| -rw-r--r-- | src/net/lua.c | 8 | ||||
| -rw-r--r-- | src/reg.c | 4 |
6 files changed, 35 insertions, 8 deletions
@@ -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 @@ -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); @@ -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;
}
|
