]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: add more type encoders, register existings
authorQuentin Young <qlyoung@nvidia.com>
Sun, 29 Nov 2020 23:00:35 +0000 (18:00 -0500)
committerQuentin Young <qlyoung@nvidia.com>
Tue, 1 Dec 2020 23:37:14 +0000 (18:37 -0500)
Signed-off-by: Quentin Young <qlyoung@nvidia.com>
lib/frrlua.c
lib/frrlua.h
lib/frrscript.c

index c8a04fb3dcdb99f2f03be2dfc3b6f92d822f259d..dd468a3def1f357eb6916c53a8555929d2c79f93 100644 (file)
@@ -150,6 +150,11 @@ void lua_pushtimet(lua_State *L, const time_t *time)
        lua_pushinteger(L, *time);
 }
 
+void lua_pushintegerp(lua_State *L, const int *num)
+{
+       lua_pushinteger(L, *num);
+}
+
 /*
  * Logging.
  *
index 8db5cec58616b697729b4e0e9edf36732df5c916..f9ab5509a65da22c01c4026e91afe411323fee5c 100644 (file)
@@ -64,6 +64,12 @@ void lua_pushtimet(lua_State *L, const time_t *time);
  */
 void lua_pushsockunion(lua_State *L, const union sockunion *su);
 
+/*
+ * Push integer. This just wraps lua_pushinteger(), but it takes a pointer, so
+ * as to be compatible with the encoder_func signature.
+ */
+void lua_pushintegerp(lua_State *L, const int *num);
+
 /*
  * Retrieve an integer from table on the top of the stack.
  *
index f4b696709acba54d7337b06bd254e1c56b5cbdc1..081ecd026f224b2c641cf9ba825178e3e9bc97c5 100644 (file)
@@ -220,7 +220,13 @@ void frrscript_init()
                                   "Lua type encoders");
 
        /* Register core library types */
+       frrscript_register_type_encoder("integer", (encoder_func) lua_pushintegerp);
+       frrscript_register_type_encoder("string", (encoder_func) lua_pushstring);
        frrscript_register_type_encoder("prefix", (encoder_func)lua_pushprefix);
        frrscript_register_type_encoder("interface",
                                        (encoder_func)lua_pushinterface);
+       frrscript_register_type_encoder("sockunion", (encoder_func) lua_pushsockunion);
+       frrscript_register_type_encoder("in_addr", (encoder_func) lua_pushinaddr);
+       frrscript_register_type_encoder("in6_addr", (encoder_func) lua_pushin6addr);
+       frrscript_register_type_encoder("time_t", (encoder_func) lua_pushtimet);
 }