]>
git.proxmox.com Git - mirror_frr.git/blob - lib/frrlua.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2016-2019 Cumulus Networks, Inc.
4 * Donald Sharp, Quentin Young
18 #include "frrscript.h"
24 DECLARE_MTYPE(SCRIPT_RES
);
27 * gcc-10 is complaining about the wrapper function
28 * not being compatible with lua_pushstring returning
29 * a char *. Let's wrapper it here to make our life
32 static inline void lua_pushstring_wrapper(lua_State
*L
, const char *str
)
34 (void)lua_pushstring(L
, str
);
38 * Converts a prefix to a Lua value and pushes it on the stack.
40 void lua_pushprefix(lua_State
*L
, const struct prefix
*prefix
);
42 void lua_decode_prefix(lua_State
*L
, int idx
, struct prefix
*prefix
);
45 * Converts the Lua value at idx to a prefix.
48 * struct prefix allocated with MTYPE_TMP
50 void *lua_toprefix(lua_State
*L
, int idx
);
53 * Converts an interface to a Lua value and pushes it on the stack.
55 void lua_pushinterface(lua_State
*L
, const struct interface
*ifp
);
57 void lua_decode_interface(lua_State
*L
, int idx
, struct interface
*ifp
);
60 * Converts the Lua value at idx to an interface.
63 * struct interface allocated with MTYPE_TMP. This interface is not hooked
64 * to anything, nor is it inserted in the global interface tree.
66 void *lua_tointerface(lua_State
*L
, int idx
);
69 * Converts an in_addr to a Lua value and pushes it on the stack.
71 void lua_pushinaddr(lua_State
*L
, const struct in_addr
*addr
);
73 void lua_decode_inaddr(lua_State
*L
, int idx
, struct in_addr
*addr
);
76 * Converts the Lua value at idx to an in_addr.
79 * struct in_addr allocated with MTYPE_TMP.
81 void *lua_toinaddr(lua_State
*L
, int idx
);
84 * Converts an in6_addr to a Lua value and pushes it on the stack.
86 void lua_pushin6addr(lua_State
*L
, const struct in6_addr
*addr
);
88 void lua_decode_in6addr(lua_State
*L
, int idx
, struct in6_addr
*addr
);
90 void lua_pushipaddr(lua_State
*L
, const struct ipaddr
*addr
);
92 void lua_pushethaddr(lua_State
*L
, const struct ethaddr
*addr
);
95 * Converts the Lua value at idx to an in6_addr.
98 * struct in6_addr allocated with MTYPE_TMP.
100 void *lua_toin6addr(lua_State
*L
, int idx
);
103 * Converts a time_t to a Lua value and pushes it on the stack.
105 void lua_pushtimet(lua_State
*L
, const time_t *time
);
107 void lua_decode_timet(lua_State
*L
, int idx
, time_t *time
);
110 * Converts the Lua value at idx to a time_t.
113 * time_t allocated with MTYPE_TMP.
115 void *lua_totimet(lua_State
*L
, int idx
);
118 * Converts a sockunion to a Lua value and pushes it on the stack.
120 void lua_pushsockunion(lua_State
*L
, const union sockunion
*su
);
122 void lua_decode_sockunion(lua_State
*L
, int idx
, union sockunion
*su
);
125 * Converts the Lua value at idx to a sockunion.
128 * sockunion allocated with MTYPE_TMP.
130 void *lua_tosockunion(lua_State
*L
, int idx
);
132 void lua_pushnexthop_group(lua_State
*L
, const struct nexthop_group
*ng
);
134 void lua_pushnexthop(lua_State
*L
, const struct nexthop
*nexthop
);
137 * Converts an int to a Lua value and pushes it on the stack.
139 void lua_pushintegerp(lua_State
*L
, const long long *num
);
141 void lua_decode_integerp(lua_State
*L
, int idx
, long long *num
);
144 * Converts the Lua value at idx to an int.
147 * int allocated with MTYPE_TMP.
149 void *lua_tointegerp(lua_State
*L
, int idx
);
151 void lua_decode_stringp(lua_State
*L
, int idx
, char *str
);
156 * Sets *string to a copy of the string at the top of the stack. The copy is
157 * allocated with MTYPE_TMP and the caller is responsible for freeing it.
159 void *lua_tostringp(lua_State
*L
, int idx
);
164 void lua_decode_noop(lua_State
*L
, int idx
, const void *ptr
);
166 void lua_decode_integer_noop(lua_State
*L
, int idx
, int i
);
169 * Retrieve an integer from table on the top of the stack.
172 * Key of string value in table
174 int frrlua_table_get_integer(lua_State
*L
, const char *key
);
177 * Exports a new table containing bindings to FRR zlog functions into the
180 * From Lua, these functions may be accessed as:
187 * They take a single string argument.
189 void frrlua_export_logging(lua_State
*L
);
192 * Dump Lua stack to a string.
194 * Return value must be freed with XFREE(MTYPE_TMP, ...);
196 char *frrlua_stackdump(lua_State
*L
);
202 #endif /* HAVE_SCRIPTING */
204 #endif /* __FRRLUA_H__ */