mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-03-11 17:08:46 +00:00
Lua: common log functions
This commit is contained in:
parent
033a338907
commit
c9627b4052
@ -1,4 +1,4 @@
|
||||
src := filter.c
|
||||
src := common.c filter.c
|
||||
obj := $(src-o-files)
|
||||
$(all-daemon)
|
||||
#$(cf-local)
|
||||
|
77
lua/common.c
Normal file
77
lua/common.c
Normal file
@ -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");
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
#include "nest/bird.h"
|
||||
#include "filter/filter.h"
|
||||
#include "lua.h"
|
||||
|
||||
#include <lua.h>
|
||||
#include <lualib.h>
|
||||
@ -8,6 +9,7 @@
|
||||
int filter_lua_chunk(const char *chunk, struct rte **e, struct rta *a, struct ea_list **ea, struct linpool *lp) {
|
||||
lua_State *L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
luaB_push_bird_table(L);
|
||||
int le = luaL_dostring(L, chunk);
|
||||
int out;
|
||||
if (le) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user