@@ -142,6 +142,23 @@ static int lua_arraylength(lua_State *l)
142142}
143143
144144static void lua_tomsgpack (struct lua_filter * lf , msgpack_packer * pck , int index );
145+ static void lua_toarray (struct lua_filter * lf , msgpack_packer * pck , int index )
146+ {
147+ int len ;
148+ int i ;
149+ lua_State * l = lf -> lua -> state ;
150+
151+ lua_pushnumber (l , (lua_Number )lua_objlen (l , -1 )); // lua_len
152+ len = (int )lua_tointeger (l , -1 );
153+ lua_pop (l , 1 );
154+
155+ msgpack_pack_array (pck , len );
156+ for (i = 1 ; i <= len ; i ++ ) {
157+ lua_rawgeti (l , -1 , i );
158+ lua_tomsgpack (lf , pck , 0 );
159+ lua_pop (l , 1 );
160+ }
161+ }
145162static void try_to_convert_data_type (struct lua_filter * lf ,
146163 msgpack_packer * pck ,
147164 int index )
@@ -154,19 +171,33 @@ static void try_to_convert_data_type(struct lua_filter *lf,
154171 struct mk_list * head = NULL ;
155172 struct l2c_type * l2c = NULL ;
156173
174+ // convert to int
157175 if ((lua_type (l , -2 ) == LUA_TSTRING )
158176 && lua_type (l , -1 ) == LUA_TNUMBER ){
159177 tmp = lua_tolstring (l , -2 , & len );
160178
161179 mk_list_foreach_safe (head , tmp_list , & lf -> l2c_types ) {
162180 l2c = mk_list_entry (head , struct l2c_type , _head );
163- if (!strncmp (l2c -> key , tmp , len )) {
181+ if (!strncmp (l2c -> key , tmp , len ) && l2c -> type == L2C_TYPE_INT ) {
164182 lua_tomsgpack (lf , pck , -1 );
165183 msgpack_pack_int64 (pck , (int64_t )lua_tonumber (l , -1 ));
166184 return ;
167185 }
168186 }
169187 }
188+ else if ((lua_type (l , -2 ) == LUA_TSTRING )
189+ && lua_type (l , -1 ) == LUA_TTABLE ){
190+ tmp = lua_tolstring (l , -2 , & len );
191+
192+ mk_list_foreach_safe (head , tmp_list , & lf -> l2c_types ) {
193+ l2c = mk_list_entry (head , struct l2c_type , _head );
194+ if (!strncmp (l2c -> key , tmp , len ) && l2c -> type == L2C_TYPE_ARRAY ) {
195+ lua_tomsgpack (lf , pck , -1 );
196+ lua_toarray (lf , pck , 0 );
197+ return ;
198+ }
199+ }
200+ }
170201
171202 /* not matched */
172203 lua_tomsgpack (lf , pck , -1 );
@@ -585,6 +616,12 @@ static struct flb_config_map config_map[] = {
585616 "If these keys are matched, the fields are converted to integer. "
586617 "If more than one key, delimit by space."
587618 },
619+ {
620+ FLB_CONFIG_MAP_STR , "type_array_key" , NULL ,
621+ 0 , FLB_FALSE , 0 ,
622+ "If these keys are matched, the fields are converted to array. "
623+ "If more than one key, delimit by space."
624+ },
588625 {
589626 FLB_CONFIG_MAP_BOOL , "protected_mode" , "true" ,
590627 0 , FLB_TRUE , offsetof(struct lua_filter , protected_mode ),
0 commit comments