summaryrefslogtreecommitdiff
path: root/lib/frrlua.c
diff options
context:
space:
mode:
authorDonald Lee <dlqs@gmx.com>2021-08-10 04:41:25 +0800
committerQuentin Young <qlyoung@qlyoung.net>2023-11-20 20:45:02 -0500
commitd2acf63f16837caaadd093927c236b742c19fd75 (patch)
tree9a6b11c90de0c01a40ceb8e8d5fa60afb22bbb3e /lib/frrlua.c
parentac91b343d635f056e8de47224719ed6218e79dfb (diff)
lib: Create encoders for int and rename stuff
Create encoders/decoders for int and rename current int encoders /decoders to long long. Signed-off-by: Donald Lee <dlqs@gmx.com>
Diffstat (limited to 'lib/frrlua.c')
-rw-r--r--lib/frrlua.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/lib/frrlua.c b/lib/frrlua.c
index 720e95491a..0e95e49c6f 100644
--- a/lib/frrlua.c
+++ b/lib/frrlua.c
@@ -259,12 +259,12 @@ void *lua_tosockunion(lua_State *L, int idx)
return su;
}
-void lua_pushintegerp(lua_State *L, const long long *num)
+void lua_pushintegerp(lua_State *L, const int *num)
{
lua_pushinteger(L, *num);
}
-void lua_decode_integerp(lua_State *L, int idx, long long *num)
+void lua_decode_integerp(lua_State *L, int idx, int *num)
{
int isnum;
*num = lua_tonumberx(L, idx, &isnum);
@@ -274,7 +274,7 @@ void lua_decode_integerp(lua_State *L, int idx, long long *num)
void *lua_tointegerp(lua_State *L, int idx)
{
- long long *num = XCALLOC(MTYPE_SCRIPT_RES, sizeof(long long));
+ int *num = XCALLOC(MTYPE_TMP, sizeof(int));
lua_decode_integerp(L, idx, num);
return num;
@@ -332,6 +332,28 @@ void lua_pushnexthop_group(lua_State *L, const struct nexthop_group *ng)
}
}
+void lua_pushlonglongp(lua_State *L, const long long *num)
+{
+ /* lua library function; this can take a long long */
+ lua_pushinteger(L, *num);
+}
+
+void lua_decode_longlongp(lua_State *L, int idx, long long *num)
+{
+ int isnum;
+ *num = lua_tonumberx(L, idx, &isnum);
+ lua_pop(L, 1);
+ assert(isnum);
+}
+
+void *lua_tolonglongp(lua_State *L, int idx)
+{
+ long long *num = XCALLOC(MTYPE_TMP, sizeof(long long));
+
+ lua_decode_longlongp(L, idx, num);
+ return num;
+}
+
void lua_decode_stringp(lua_State *L, int idx, char *str)
{
strlcpy(str, lua_tostring(L, idx), strlen(str) + 1);