]>
git.proxmox.com Git - mirror_frr.git/blob - lib/frrlua.c
2 * This file defines the lua interface into
5 * Copyright (C) 2016 Cumulus Networks, Inc.
8 * This file is part of FreeRangeRouting (FRR).
10 * FRR is free software; you can redistribute it and/or modify it under the
11 * terms of the GNU General Public License as published by the Free Software
12 * Foundation; either version 2, or (at your option) any later version.
14 * FRR is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along
20 * with FRR; see the file COPYING. If not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 static int lua_zlog_debug(lua_State
*L
)
34 const char *string
= lua_tostring(L
, 1);
37 zlog_debug("%s", string
);
42 const char *get_string(lua_State
*L
, const char *key
)
46 lua_pushstring(L
, key
);
49 str
= (const char *)lua_tostring(L
, -1);
55 int get_integer(lua_State
*L
, const char *key
)
59 lua_pushstring(L
, key
);
62 result
= lua_tointeger(L
, -1);
68 static void *lua_alloc(void *ud
, void *ptr
, size_t osize
,
71 (void)ud
; (void)osize
; /* not used */
76 return realloc(ptr
, nsize
);
79 lua_State
*lua_initialize(const char *file
)
82 lua_State
*L
= lua_newstate(lua_alloc
, NULL
);
84 zlog_debug("Newstate: %p", L
);
86 zlog_debug("Opened lib");
87 status
= luaL_loadfile(L
, file
);
89 zlog_debug("Failure to open %s %d", file
, status
);
94 lua_pcall(L
, 0, LUA_MULTRET
, 0);
95 zlog_debug("Setting global function");
96 lua_pushcfunction(L
, lua_zlog_debug
);
97 lua_setglobal(L
, "zlog_debug");
102 void lua_setup_prefix_table(lua_State
*L
, const struct prefix
*prefix
)
107 lua_pushstring(L
, prefix2str(prefix
, buffer
, 100));
108 lua_setfield(L
, -2, "route");
109 lua_pushinteger(L
, prefix
->family
);
110 lua_setfield(L
, -2, "family");
111 lua_setglobal(L
, "prefix");
114 enum lua_rm_status
lua_run_rm_rule(lua_State
*L
, const char *rule
)
118 lua_getglobal(L
, rule
);
119 status
= lua_pcall(L
, 0, 1, 0);
121 zlog_debug("Executing Failure with function: %s: %d",
123 return LUA_RM_FAILURE
;
126 status
= lua_tonumber(L
, -1);