mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-23 18:21:54 +00:00
26 lines
619 B
C
26 lines
619 B
C
#include "nest/bird.h"
|
|
#include "filter/filter.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);
|
|
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;
|
|
}
|