2017-02-06 13:02:11 +00:00
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "filter/filter.h"
|
2017-02-06 14:25:48 +00:00
|
|
|
#include "lua.h"
|
2017-02-06 13:02:11 +00:00
|
|
|
|
|
|
|
#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);
|
2017-02-06 13:02:11 +00:00
|
|
|
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;
|
|
|
|
}
|