feature: add bson_to_lightuserdata api. see #2074 (#2075)

This commit is contained in:
涵曦
2025-08-09 18:07:43 +08:00
committed by GitHub
parent b02d619dd8
commit 754932cef4

View File

@@ -327,6 +327,7 @@ append_one(struct bson *bs, lua_State *L, const char *key, size_t sz, int depth)
case LUA_TNUMBER:
append_number(bs, L, key, sz);
break;
case LUA_TLIGHTUSERDATA:
case LUA_TUSERDATA: {
append_key(bs, L, BSON_DOCUMENT, key, sz);
int32_t * doc = (int32_t*)lua_touserdata(L,-1);
@@ -978,6 +979,13 @@ lencode(lua_State *L) {
return 1;
}
static int
lto_lightuserdata(lua_State *L) {
void *p = lua_touserdata(L, 1);
lua_pushlightuserdata(L, p);
return 1;
}
static int
encode_bson_byorder(lua_State *L) {
int n = lua_gettop(L);
@@ -1340,6 +1348,7 @@ luaopen_bson(lua_State *L) {
{ "objectid", lobjectid },
{ "int64", lint64 },
{ "decode", ldecode },
{ "to_lightuserdata", lto_lightuserdata },
{ NULL, NULL },
};