]>
git.proxmox.com Git - mirror_frr.git/blob - lib/frrlua.h
2 * Copyright (C) 2016-2019 Cumulus Networks, Inc.
3 * Donald Sharp, Quentin Young
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #include "frrscript.h"
37 DECLARE_MTYPE(SCRIPT_RES
);
40 * gcc-10 is complaining about the wrapper function
41 * not being compatible with lua_pushstring returning
42 * a char *. Let's wrapper it here to make our life
45 static inline void lua_pushstring_wrapper(lua_State
*L
, const char *str
)
47 (void)lua_pushstring(L
, str
);
51 * Converts a prefix to a Lua value and pushes it on the stack.
53 void lua_pushprefix(lua_State
*L
, const struct prefix
*prefix
);
55 void lua_decode_prefix(lua_State
*L
, int idx
, struct prefix
*prefix
);
58 * Converts the Lua value at idx to a prefix.
61 * struct prefix allocated with MTYPE_TMP
63 void *lua_toprefix(lua_State
*L
, int idx
);
66 * Converts an interface to a Lua value and pushes it on the stack.
68 void lua_pushinterface(lua_State
*L
, const struct interface
*ifp
);
70 void lua_decode_interface(lua_State
*L
, int idx
, struct interface
*ifp
);
73 * Converts the Lua value at idx to an interface.
76 * struct interface allocated with MTYPE_TMP. This interface is not hooked
77 * to anything, nor is it inserted in the global interface tree.
79 void *lua_tointerface(lua_State
*L
, int idx
);
82 * Converts an in_addr to a Lua value and pushes it on the stack.
84 void lua_pushinaddr(lua_State
*L
, const struct in_addr
*addr
);
86 void lua_decode_inaddr(lua_State
*L
, int idx
, struct in_addr
*addr
);
89 * Converts the Lua value at idx to an in_addr.
92 * struct in_addr allocated with MTYPE_TMP.
94 void *lua_toinaddr(lua_State
*L
, int idx
);
97 * Converts an in6_addr to a Lua value and pushes it on the stack.
99 void lua_pushin6addr(lua_State
*L
, const struct in6_addr
*addr
);
101 void lua_decode_in6addr(lua_State
*L
, int idx
, struct in6_addr
*addr
);
103 void lua_pushipaddr(lua_State
*L
, const struct ipaddr
*addr
);
105 void lua_pushethaddr(lua_State
*L
, const struct ethaddr
*addr
);
108 * Converts the Lua value at idx to an in6_addr.
111 * struct in6_addr allocated with MTYPE_TMP.
113 void *lua_toin6addr(lua_State
*L
, int idx
);
116 * Converts a time_t to a Lua value and pushes it on the stack.
118 void lua_pushtimet(lua_State
*L
, const time_t *time
);
120 void lua_decode_timet(lua_State
*L
, int idx
, time_t *time
);
123 * Converts the Lua value at idx to a time_t.
126 * time_t allocated with MTYPE_TMP.
128 void *lua_totimet(lua_State
*L
, int idx
);
131 * Converts a sockunion to a Lua value and pushes it on the stack.
133 void lua_pushsockunion(lua_State
*L
, const union sockunion
*su
);
135 void lua_decode_sockunion(lua_State
*L
, int idx
, union sockunion
*su
);
138 * Converts the Lua value at idx to a sockunion.
141 * sockunion allocated with MTYPE_TMP.
143 void *lua_tosockunion(lua_State
*L
, int idx
);
145 void lua_pushnexthop_group(lua_State
*L
, const struct nexthop_group
*ng
);
147 void lua_pushnexthop(lua_State
*L
, const struct nexthop
*nexthop
);
150 * Converts an int to a Lua value and pushes it on the stack.
152 void lua_pushintegerp(lua_State
*L
, const long long *num
);
154 void lua_decode_integerp(lua_State
*L
, int idx
, long long *num
);
157 * Converts the Lua value at idx to an int.
160 * int allocated with MTYPE_TMP.
162 void *lua_tointegerp(lua_State
*L
, int idx
);
164 void lua_decode_stringp(lua_State
*L
, int idx
, char *str
);
169 * Sets *string to a copy of the string at the top of the stack. The copy is
170 * allocated with MTYPE_TMP and the caller is responsible for freeing it.
172 void *lua_tostringp(lua_State
*L
, int idx
);
177 void lua_decode_noop(lua_State
*L
, int idx
, const void *ptr
);
179 void lua_decode_integer_noop(lua_State
*L
, int idx
, int i
);
182 * Retrieve an integer from table on the top of the stack.
185 * Key of string value in table
187 int frrlua_table_get_integer(lua_State
*L
, const char *key
);
190 * Exports a new table containing bindings to FRR zlog functions into the
193 * From Lua, these functions may be accessed as:
200 * They take a single string argument.
202 void frrlua_export_logging(lua_State
*L
);
205 * Dump Lua stack to a string.
207 * Return value must be freed with XFREE(MTYPE_TMP, ...);
209 char *frrlua_stackdump(lua_State
*L
);
215 #endif /* HAVE_SCRIPTING */
217 #endif /* __FRRLUA_H__ */