Skip to content

Commit bab9f6d

Browse files
committed
fix encode json.null
1 parent ad07c95 commit bab9f6d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/lualib-src/lua_db_protocol.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ struct lua_db_protocol {
8585
int type = lua_type(L, -1);
8686

8787
size_t stub = pqbuf.size();
88-
if (type != LUA_TNIL) {
88+
if (type != LUA_TNIL && type != LUA_TLIGHTUSERDATA) {
8989
pqbuf.write_integer(static_cast<uint32_t>(0)); // length placeholder
9090
}
9191

9292
switch (type) {
9393
case LUA_TNIL:
94-
pqbuf.write_integer(-1);
94+
pqbuf.write_integer(static_cast<uint32_t>(-1));
9595
break;
9696
case LUA_TNUMBER:
9797
if (lua_isinteger(L, -1)) {
@@ -112,14 +112,19 @@ struct lua_db_protocol {
112112
case LUA_TTABLE:
113113
encode_one<false>(L, pqbuf.get_buffer(), -1, 0, cfg);
114114
break;
115+
case LUA_TLIGHTUSERDATA:
116+
if (lua_touserdata(L, -1) == nullptr) {
117+
pqbuf.write_integer(static_cast<uint32_t>(-1));
118+
break;
119+
}
115120
default:
116121
throw lua_pq_error::format(
117122
"lua_pq_query: unsupported parameter type: %s",
118123
lua_typename(L, type)
119124
);
120125
}
121126

122-
if (type != LUA_TNIL) {
127+
if (type != LUA_TNIL && type != LUA_TLIGHTUSERDATA) {
123128
auto buf_ptr = pqbuf.get_buffer();
124129
auto size = static_cast<uint32_t>(buf_ptr->size() - stub - 4);
125130
moon::host2net(size);
@@ -251,6 +256,11 @@ struct lua_db_protocol {
251256
case LUA_TTABLE:
252257
encode_one<false>(L, buf, index, 0, cfg);
253258
break;
259+
case LUA_TLIGHTUSERDATA:
260+
if (lua_touserdata(L, index) == nullptr) {
261+
buf->write_back("null"sv);
262+
break;
263+
}
254264
default:
255265
throw lua_json_error::format(
256266
"json concat: unsupported value type: %s",

0 commit comments

Comments
 (0)