aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2021-08-02 19:35:06 +0100
committerSean Dewar <seandewar@users.noreply.github.com>2021-09-15 21:19:29 +0100
commit10aa60e806c300cc7bd1f84e52b4b043d6fac537 (patch)
treeb57fac817affcae0a53d5a2e1fbe79266c0a17ec
parentbfeecd0b418cf03a974c57082f4fc647b90aef06 (diff)
downloadrneovim-10aa60e806c300cc7bd1f84e52b4b043d6fac537.tar.gz
rneovim-10aa60e806c300cc7bd1f84e52b4b043d6fac537.tar.bz2
rneovim-10aa60e806c300cc7bd1f84e52b4b043d6fac537.zip
feat(nlua): convert Blobs to strings
-rw-r--r--src/nvim/lua/converter.c7
-rw-r--r--test/functional/lua/luaeval_spec.lua5
2 files changed, 11 insertions, 1 deletions
diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c
index 007ef336cd..0adbbdb953 100644
--- a/src/nvim/lua/converter.c
+++ b/src/nvim/lua/converter.c
@@ -482,7 +482,12 @@ static bool typval_conv_special = false;
TYPVAL_ENCODE_CONV_NIL(tv)
#define TYPVAL_ENCODE_CONV_BLOB(tv, blob, len) \
- abort() /* TODO(seandewar) */ \
+ do { \
+ const blob_T *const blob_ = (blob); \
+ lua_pushlstring(lstate, \
+ blob_ != NULL ? (const char *)blob_->bv_ga.ga_data : "", \
+ (size_t)(len)); \
+ } while (0)
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun) \
do { \
diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua
index 8ef77faa0f..36f6d4025f 100644
--- a/test/functional/lua/luaeval_spec.lua
+++ b/test/functional/lua/luaeval_spec.lua
@@ -458,6 +458,9 @@ describe('v:lua', function()
function mymod.crashy()
nonexistent()
end
+ function mymod.whatis(value)
+ return type(value) .. ": " .. tostring(value)
+ end
function mymod.omni(findstart, base)
if findstart == 1 then
return 5
@@ -476,6 +479,8 @@ describe('v:lua', function()
eq(true, exec_lua([[return _G.val == vim.NIL]]))
eq(NIL, eval('v:lua.mymod.noisy("eval")'))
eq("hey eval", meths.get_current_line())
+ eq("string: abc", eval('v:lua.mymod.whatis(0z616263)'))
+ eq("string: ", eval('v:lua.mymod.whatis(v:_null_blob)'))
eq("Vim:E5108: Error executing lua [string \"<nvim>\"]:0: attempt to call global 'nonexistent' (a nil value)",
pcall_err(eval, 'v:lua.mymod.crashy()'))