diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2021-10-30 06:59:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-30 06:59:59 -0700 |
commit | a141f6e9225fea065d8580b37510de2de168f9de (patch) | |
tree | 93ef10f8cbe0f7c6e95a08e9b0babb70da7874aa /src/mpack/lmpack.c | |
parent | eb6a1039c500dc901563b786b3cd06ff740ab152 (diff) | |
download | rneovim-a141f6e9225fea065d8580b37510de2de168f9de.tar.gz rneovim-a141f6e9225fea065d8580b37510de2de168f9de.tar.bz2 rneovim-a141f6e9225fea065d8580b37510de2de168f9de.zip |
fix(vim.mpack): rename pack/unpack => encode/decode #16175
Problem:
1. "unpack" has an unrelated meaning in Lua:
https://www.lua.org/manual/5.1/manual.html#pdf-unpack
2. We already have msgpackparse()/msgpackdump() and
json_encode()/json_decode(), so introducing another name for the same
thing is entropy.
Solution:
- Rename vim.mpack.pack/unpack => vim.mpack.encode/decode
Caveat:
This is incongruent with the `Unpacker` and `Packer` functions.
- It's probably too invasive to rename those.
- They also aren't part of our documented interface.
- This commit is "reversible" in the sense that we can always revert
it and add `vim.mpack.encode/decode` as _aliases_ to
`vim.mpack.pack/unpack`, at any time in the future, if we want
stricter fidelity with upstream libmpack. Meanwhile,
`vim.mpack.encode/decode` is currently the total _documented_
interface of `vim.mpack`, so this change serves the purpose of
consistent naming in the Nvim stdlib.
Diffstat (limited to 'src/mpack/lmpack.c')
-rw-r--r-- | src/mpack/lmpack.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/mpack/lmpack.c b/src/mpack/lmpack.c index 24d27fd17a..87acf46592 100644 --- a/src/mpack/lmpack.c +++ b/src/mpack/lmpack.c @@ -34,7 +34,9 @@ #include "rpc.h" #define UNPACKER_META_NAME "mpack.Unpacker" +#define UNPACK_FN_NAME "decode" #define PACKER_META_NAME "mpack.Packer" +#define PACK_FN_NAME "encode" #define SESSION_META_NAME "mpack.Session" #define NIL_NAME "mpack.NIL" #define EMPTY_DICT_NAME "mpack.empty_dict" @@ -432,8 +434,8 @@ static int lmpack_unpacker_unpack_str(lua_State *L, Unpacker *unpacker, if (unpacker->unpacking) { return luaL_error(L, "Unpacker instance already working. Use another " - "Unpacker or the module's \"unpack\" function if you " - "need to unpack from the ext handler"); + "Unpacker or mpack." UNPACK_FN_NAME "() if you " + "need to " UNPACK_FN_NAME " from the ext handler"); } do { @@ -784,8 +786,8 @@ static int lmpack_packer_pack(lua_State *L) if (packer->packing) { return luaL_error(L, "Packer instance already working. Use another Packer " - "or the module's \"pack\" function if you need to " - "pack from the ext handler"); + "or mpack." PACK_FN_NAME "() if you need to " + PACK_FN_NAME " from the ext handler"); } do { @@ -1161,8 +1163,8 @@ static const luaL_reg mpack_functions[] = { {"Unpacker", lmpack_unpacker_new}, {"Packer", lmpack_packer_new}, {"Session", lmpack_session_new}, - {"unpack", lmpack_unpack}, - {"pack", lmpack_pack}, + {UNPACK_FN_NAME, lmpack_unpack}, + {PACK_FN_NAME, lmpack_pack}, {NULL, NULL} }; |