Skip to content

Commit

Permalink
lua: push flb_null as a nil value
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 authored and edsiper committed Sep 23, 2023
1 parent ecdbd6f commit 86672e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions include/fluent-bit/flb_lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include <monkey/mk_core/mk_list.h>
#include <msgpack/pack.h>

/* global variables in Lua */
#define FLB_LUA_VAR_FLB_NULL "flb_null"

#define FLB_LUA_L2C_TYPES_NUM_MAX 16

enum flb_lua_l2c_type_enum {
Expand Down Expand Up @@ -74,5 +77,6 @@ void flb_lua_tompack(lua_State *l,
int index,
struct flb_lua_l2c_config *l2cc);
void flb_lua_dump_stack(FILE *out, lua_State *l);
int flb_lua_enable_flb_null(lua_State *l);

#endif
15 changes: 13 additions & 2 deletions src/flb_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
#include <fluent-bit/flb_lua.h>
#include <stdint.h>

int flb_lua_enable_flb_null(lua_State *l)
{
/* set flb.null */
lua_pushlightuserdata(l, NULL);

flb_info("[%s] set %s", __FUNCTION__, FLB_LUA_VAR_FLB_NULL);
lua_setglobal(l, FLB_LUA_VAR_FLB_NULL);

return 0;
}

void flb_lua_pushtimetable(lua_State *l, struct flb_time *tm)
{
lua_createtable(l, 0, 2);
Expand Down Expand Up @@ -63,7 +74,7 @@ int flb_lua_pushmpack(lua_State *l, mpack_reader_t *reader)
tag = mpack_read_tag(reader);
switch (mpack_tag_type(&tag)) {
case mpack_type_nil:
lua_pushnil(l);
lua_getglobal(l, FLB_LUA_VAR_FLB_NULL);
break;
case mpack_type_bool:
lua_pushboolean(l, mpack_tag_bool_value(&tag));
Expand Down Expand Up @@ -128,7 +139,7 @@ void flb_lua_pushmsgpack(lua_State *l, msgpack_object *o)

switch(o->type) {
case MSGPACK_OBJECT_NIL:
lua_pushnil(l);
lua_getglobal(l, FLB_LUA_VAR_FLB_NULL);
break;

case MSGPACK_OBJECT_BOOLEAN:
Expand Down

0 comments on commit 86672e8

Please sign in to comment.