@@ -142,6 +142,23 @@ static int lua_arraylength(lua_State *l)
142
142
}
143
143
144
144
static 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
+ }
145
162
static void try_to_convert_data_type (struct lua_filter * lf ,
146
163
msgpack_packer * pck ,
147
164
int index )
@@ -154,19 +171,33 @@ static void try_to_convert_data_type(struct lua_filter *lf,
154
171
struct mk_list * head = NULL ;
155
172
struct l2c_type * l2c = NULL ;
156
173
174
+ // convert to int
157
175
if ((lua_type (l , -2 ) == LUA_TSTRING )
158
176
&& lua_type (l , -1 ) == LUA_TNUMBER ){
159
177
tmp = lua_tolstring (l , -2 , & len );
160
178
161
179
mk_list_foreach_safe (head , tmp_list , & lf -> l2c_types ) {
162
180
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 ) {
164
182
lua_tomsgpack (lf , pck , -1 );
165
183
msgpack_pack_int64 (pck , (int64_t )lua_tonumber (l , -1 ));
166
184
return ;
167
185
}
168
186
}
169
187
}
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
+ }
170
201
171
202
/* not matched */
172
203
lua_tomsgpack (lf , pck , -1 );
@@ -585,6 +616,12 @@ static struct flb_config_map config_map[] = {
585
616
"If these keys are matched, the fields are converted to integer. "
586
617
"If more than one key, delimit by space."
587
618
},
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
+ },
588
625
{
589
626
FLB_CONFIG_MAP_BOOL , "protected_mode" , "true" ,
590
627
0 , FLB_TRUE , offsetof(struct lua_filter , protected_mode ),
0 commit comments