diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2021-09-04 17:16:51 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2021-09-09 16:06:43 +0200 |
commit | eaf661dacd74b098de768ddc459ae2e68bb6d668 (patch) | |
tree | 9d002c4ba045377566afd3c59ccfde9893bcd0ac | |
parent | 2a08aeff1a38a1f44336ec1c2d0d2514de482157 (diff) | |
download | rneovim-eaf661dacd74b098de768ddc459ae2e68bb6d668.tar.gz rneovim-eaf661dacd74b098de768ddc459ae2e68bb6d668.tar.bz2 rneovim-eaf661dacd74b098de768ddc459ae2e68bb6d668.zip |
feat(lua): add vim.mpack for msgpack support in lua
-rw-r--r-- | src/mpack/lmpack.c | 6 | ||||
-rw-r--r-- | src/nvim/lua/executor.c | 16 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/mpack/lmpack.c b/src/mpack/lmpack.c index 9f102fc950..a66caf20ca 100644 --- a/src/mpack/lmpack.c +++ b/src/mpack/lmpack.c @@ -1139,16 +1139,19 @@ int luaopen_mpack(lua_State *L) lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); luaL_register(L, NULL, unpacker_methods); + lua_pop(L, 1); /* Packer */ luaL_newmetatable(L, PACKER_META_NAME); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); luaL_register(L, NULL, packer_methods); + lua_pop(L, 1); /* Session */ luaL_newmetatable(L, SESSION_META_NAME); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); luaL_register(L, NULL, session_methods); + lua_pop(L, 1); /* NIL */ /* Check if NIL is already stored in the registry */ lua_getfield(L, LUA_REGISTRYINDEX, NIL_NAME); @@ -1166,6 +1169,9 @@ int luaopen_mpack(lua_State *L) /* Save NIL on the registry so we can access it easily from other functions */ lua_setfield(L, LUA_REGISTRYINDEX, NIL_NAME); } + + lua_pop(L, 1); + /* module */ lua_newtable(L); luaL_register(L, NULL, mpack_functions); diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index a8b10f86f5..2facfa28cd 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -33,6 +33,7 @@ #include "nvim/eval/userfunc.h" #include "nvim/event/time.h" #include "nvim/event/loop.h" +#include "mpack/lmpack.h" #include "nvim/os/os.h" @@ -508,6 +509,21 @@ static int nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL nlua_nil_ref = nlua_ref(lstate, -1); lua_setfield(lstate, -2, "NIL"); + + // vim.mpack + luaopen_mpack(lstate); + lua_pushvalue(lstate, -1); + lua_setfield(lstate, -3, "mpack"); + + // package.loaded.mpack = vim.mpack + // otherwise luv will be reinitialized when require'mpack' + lua_getglobal(lstate, "package"); + lua_getfield(lstate, -1, "loaded"); + lua_pushvalue(lstate, -3); + lua_setfield(lstate, -2, "mpack"); + lua_pop(lstate, 3); + + // vim._empty_dict_mt lua_createtable(lstate, 0, 0); lua_pushcfunction(lstate, &nlua_empty_dict_tostring); |