]> git.proxmox.com Git - mirror_frr.git/blob - lib/frrlua.h
Merge pull request #8978 from kssoman/ospf_new
[mirror_frr.git] / lib / frrlua.h
1 /*
2 * Copyright (C) 2016-2019 Cumulus Networks, Inc.
3 * Donald Sharp, Quentin Young
4 *
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)
8 * any later version.
9 *
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
13 * more details.
14 *
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
18 */
19 #ifndef __FRRLUA_H__
20 #define __FRRLUA_H__
21
22 #include <zebra.h>
23
24 #ifdef HAVE_SCRIPTING
25
26 #include <lua.h>
27 #include <lualib.h>
28 #include <lauxlib.h>
29
30 #include "prefix.h"
31 #include "frrscript.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /*
38 * gcc-10 is complaining about the wrapper function
39 * not being compatible with lua_pushstring returning
40 * a char *. Let's wrapper it here to make our life
41 * easier
42 */
43 static inline void lua_pushstring_wrapper(lua_State *L, const char *str)
44 {
45 (void)lua_pushstring(L, str);
46 }
47
48 /*
49 * Converts a prefix to a Lua value and pushes it on the stack.
50 */
51 void lua_pushprefix(lua_State *L, const struct prefix *prefix);
52
53 void lua_decode_prefix(lua_State *L, int idx, struct prefix *prefix);
54
55 /*
56 * Converts the Lua value at idx to a prefix.
57 *
58 * Returns:
59 * struct prefix allocated with MTYPE_TMP
60 */
61 void *lua_toprefix(lua_State *L, int idx);
62
63 /*
64 * Converts an interface to a Lua value and pushes it on the stack.
65 */
66 void lua_pushinterface(lua_State *L, const struct interface *ifp);
67
68 void lua_decode_interface(lua_State *L, int idx, struct interface *ifp);
69
70 /*
71 * Converts the Lua value at idx to an interface.
72 *
73 * Returns:
74 * struct interface allocated with MTYPE_TMP. This interface is not hooked
75 * to anything, nor is it inserted in the global interface tree.
76 */
77 void *lua_tointerface(lua_State *L, int idx);
78
79 /*
80 * Converts an in_addr to a Lua value and pushes it on the stack.
81 */
82 void lua_pushinaddr(lua_State *L, const struct in_addr *addr);
83
84 void lua_decode_inaddr(lua_State *L, int idx, struct in_addr *addr);
85
86 /*
87 * Converts the Lua value at idx to an in_addr.
88 *
89 * Returns:
90 * struct in_addr allocated with MTYPE_TMP.
91 */
92 void *lua_toinaddr(lua_State *L, int idx);
93
94 /*
95 * Converts an in6_addr to a Lua value and pushes it on the stack.
96 */
97 void lua_pushin6addr(lua_State *L, const struct in6_addr *addr);
98
99 void lua_decode_in6addr(lua_State *L, int idx, struct in6_addr *addr);
100
101 /*
102 * Converts the Lua value at idx to an in6_addr.
103 *
104 * Returns:
105 * struct in6_addr allocated with MTYPE_TMP.
106 */
107 void *lua_toin6addr(lua_State *L, int idx);
108
109 /*
110 * Converts a time_t to a Lua value and pushes it on the stack.
111 */
112 void lua_pushtimet(lua_State *L, const time_t *time);
113
114 void lua_decode_timet(lua_State *L, int idx, time_t *time);
115
116 /*
117 * Converts the Lua value at idx to a time_t.
118 *
119 * Returns:
120 * time_t allocated with MTYPE_TMP.
121 */
122 void *lua_totimet(lua_State *L, int idx);
123
124 /*
125 * Converts a sockunion to a Lua value and pushes it on the stack.
126 */
127 void lua_pushsockunion(lua_State *L, const union sockunion *su);
128
129 void lua_decode_sockunion(lua_State *L, int idx, union sockunion *su);
130
131 /*
132 * Converts the Lua value at idx to a sockunion.
133 *
134 * Returns:
135 * sockunion allocated with MTYPE_TMP.
136 */
137 void *lua_tosockunion(lua_State *L, int idx);
138
139 /*
140 * Converts an int to a Lua value and pushes it on the stack.
141 */
142 void lua_pushintegerp(lua_State *L, const long long *num);
143
144 void lua_decode_integerp(lua_State *L, int idx, long long *num);
145
146 /*
147 * Converts the Lua value at idx to an int.
148 *
149 * Returns:
150 * int allocated with MTYPE_TMP.
151 */
152 void *lua_tointegerp(lua_State *L, int idx);
153
154 void lua_decode_stringp(lua_State *L, int idx, char *str);
155
156 /*
157 * Pop string.
158 *
159 * Sets *string to a copy of the string at the top of the stack. The copy is
160 * allocated with MTYPE_TMP and the caller is responsible for freeing it.
161 */
162 void *lua_tostringp(lua_State *L, int idx);
163
164 /*
165 * No-op decocder
166 */
167 void lua_decode_noop(lua_State *L, int idx, const void *ptr);
168
169 /*
170 * Retrieve an integer from table on the top of the stack.
171 *
172 * key
173 * Key of string value in table
174 */
175 int frrlua_table_get_integer(lua_State *L, const char *key);
176
177 /*
178 * Exports a new table containing bindings to FRR zlog functions into the
179 * global namespace.
180 *
181 * From Lua, these functions may be accessed as:
182 *
183 * - log.debug()
184 * - log.info()
185 * - log.warn()
186 * - log.error()
187 *
188 * They take a single string argument.
189 */
190 void frrlua_export_logging(lua_State *L);
191
192 /*
193 * Dump Lua stack to a string.
194 *
195 * Return value must be freed with XFREE(MTYPE_TMP, ...);
196 */
197 char *frrlua_stackdump(lua_State *L);
198
199 #ifdef __cplusplus
200 }
201 #endif
202
203 #endif /* HAVE_SCRIPTING */
204
205 #endif /* __FRRLUA_H__ */