Skip to content

Commit fc63f8c

Browse files
committed
fix: remove null userdata from wrapped function results
1 parent 31cf09b commit fc63f8c

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

lua/jupyter-api/rust/init.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ local M = {}
66

77
local PENDING = (coroutine.wrap(jupyter_api_nvim.PENDING))()
88

9+
local denull
10+
denull = function (input)
11+
if type(input) == "table" then
12+
local denulled = {}
13+
for key, value in pairs(denulled) do
14+
denulled[key] = denull(value)
15+
end
16+
elseif type(input) == "userdata" then
17+
if tostring(input) == "userdata (NULL)" then
18+
return nil
19+
else
20+
return input
21+
end
22+
else
23+
return input
24+
end
25+
end
26+
927
---Wrap an async rust function in a coroutine that neovim will poll. Return a function that takes
1028
---function args and a callback function
1129
---@param async_fn any
@@ -23,7 +41,7 @@ local wrap = function(async_fn)
2341
if res == PENDING then
2442
vim.defer_fn(exec, 10)
2543
else
26-
cb(res)
44+
cb(denull(res))
2745
end
2846
end
2947
vim.schedule(exec)

0 commit comments

Comments
 (0)