0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-23 10:11:53 +00:00
bird/lua/filter.c

28 lines
663 B
C
Raw Normal View History

#include "nest/bird.h"
#include "filter/filter.h"
2017-02-06 14:25:48 +00:00
#include "lua.h"
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
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);
2017-02-06 14:25:48 +00:00
luaB_push_bird_table(L);
int le = luaL_dostring(L, chunk);
int out;
if (le) {
log(L_WARN "bad lua: %s", lua_tostring(L, -1));
out = F_ERROR;
} else if (lua_isnumber(L, -1)) {
out = lua_tonumber(L, -1);
} else {
log(L_WARN "lua return value is not a number: %s", lua_tostring(L, -1));
out = F_ERROR;
}
lua_close(L);
return out;
}