summaryrefslogtreecommitdiff
path: root/lua/common.c
diff options
context:
space:
mode:
authorJan Moskyto Matejka <mq@ucw.cz>2017-02-06 15:25:48 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2019-02-22 23:12:41 +0100
commitc2ffaf95e6e5b47c1d14318a88ab32d356464be6 (patch)
tree35a0528cba57b41bcfa64a18df084feecb11c939 /lua/common.c
parent96b1cc6c3f5ab49993ce9373e33f1f8fc04bdc61 (diff)
Lua: common log functions
Diffstat (limited to 'lua/common.c')
-rw-r--r--lua/common.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/lua/common.c b/lua/common.c
new file mode 100644
index 00000000..fea030f5
--- /dev/null
+++ b/lua/common.c
@@ -0,0 +1,77 @@
+#include "nest/bird.h"
+#include "filter/filter.h"
+#include "lua.h"
+
+#include <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+
+static int luaB_err(lua_State *L) {
+ int n = lua_gettop(L);
+ if (n != 1)
+ log(L_WARN "bird.err() accepts exactly 1 argument");
+
+ if (n < 1)
+ return 0;
+
+ log(L_ERR "%s", lua_tostring(L, 1));
+ return 0;
+}
+
+static int luaB_warn(lua_State *L) {
+ int n = lua_gettop(L);
+ if (n != 1)
+ log(L_WARN "bird.warn() accepts exactly 1 argument");
+
+ if (n < 1)
+ return 0;
+
+ log(L_WARN "%s", lua_tostring(L, 1));
+ return 0;
+}
+
+static int luaB_info(lua_State *L) {
+ int n = lua_gettop(L);
+ if (n != 1)
+ log(L_WARN "bird.info() accepts exactly 1 argument");
+
+ if (n < 1)
+ return 0;
+
+ log(L_INFO "%s", lua_tostring(L, 1));
+ return 0;
+}
+
+static int luaB_trace(lua_State *L) {
+ int n = lua_gettop(L);
+ if (n != 1)
+ log(L_WARN "bird.trace() accepts exactly 1 argument");
+
+ if (n < 1)
+ return 0;
+
+ log(L_TRACE "%s", lua_tostring(L, 1));
+ return 0;
+}
+
+void luaB_push_bird_table(lua_State *L) {
+ lua_newtable(L);
+
+ lua_pushstring(L, "err");
+ lua_pushcfunction(L, luaB_err);
+ lua_settable(L, -3);
+
+ lua_pushstring(L, "warn");
+ lua_pushcfunction(L, luaB_warn);
+ lua_settable(L, -3);
+
+ lua_pushstring(L, "info");
+ lua_pushcfunction(L, luaB_info);
+ lua_settable(L, -3);
+
+ lua_pushstring(L, "trace");
+ lua_pushcfunction(L, luaB_trace);
+ lua_settable(L, -3);
+
+ lua_setglobal(L, "bird");
+}