diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2021-08-06 17:09:47 +0100 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2021-08-12 22:35:20 +0100 |
commit | 003c8acc8a9863932430bfb51bee8403b964c19b (patch) | |
tree | c7f47d87cbc6152a25dbaeffea225842ffc8306b /src/nvim/eval | |
parent | e6be6c307a832d661d2a6269ad2d322e4bf5e9cc (diff) | |
download | rneovim-003c8acc8a9863932430bfb51bee8403b964c19b.tar.gz rneovim-003c8acc8a9863932430bfb51bee8403b964c19b.tar.bz2 rneovim-003c8acc8a9863932430bfb51bee8403b964c19b.zip |
vim-patch:8.1.1807: more functions can be used as a method
Problem: More functions can be used as a method.
Solution: Add append(), appendbufline(), assert_equal(), etc.
Also add the :eval command.
https://github.com/vim/vim/commit/25e42231d3ee27feec2568fa4be2aa2bfba82ae5
:eval is already ported.
Diffstat (limited to 'src/nvim/eval')
-rw-r--r-- | src/nvim/eval/funcs.c | 5 | ||||
-rw-r--r-- | src/nvim/eval/funcs.h | 6 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 787d5aaf78..e090f3b37f 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -199,7 +199,7 @@ int call_internal_method(const char_u *const fname, const int argcount, FUNC_ATTR_NONNULL_ALL { const VimLFuncDef *const fdef = find_internal_func((const char *)fname); - if (fdef == NULL || fdef->base_arg == 0) { + if (fdef == NULL || fdef->base_arg == BASE_NONE) { return ERROR_UNKNOWN; } else if (argcount + 1 < fdef->min_argc) { return ERROR_TOOFEW; @@ -208,7 +208,8 @@ int call_internal_method(const char_u *const fname, const int argcount, } typval_T argv[MAX_FUNC_ARGS + 1]; - const ptrdiff_t base_index = fdef->base_arg - 1; + const ptrdiff_t base_index + = fdef->base_arg == BASE_LAST ? argcount : fdef->base_arg - 1; memcpy(argv, argvars, base_index * sizeof(typval_T)); argv[base_index] = *basetv; memcpy(argv + base_index + 1, argvars + base_index, diff --git a/src/nvim/eval/funcs.h b/src/nvim/eval/funcs.h index 3ad0b8282a..c6a0cb959e 100644 --- a/src/nvim/eval/funcs.h +++ b/src/nvim/eval/funcs.h @@ -9,12 +9,16 @@ typedef void (*FunPtr)(void); /// Prototype of C function that implements VimL function typedef void (*VimLFunc)(typval_T *args, typval_T *rvar, FunPtr data); +/// Special flags for base_arg @see VimLFuncDef +#define BASE_NONE 0 ///< Not a method (no base argument). +#define BASE_LAST UINT8_MAX ///< Use the last argument as the method base. + /// Structure holding VimL function definition typedef struct fst { char *name; ///< Name of the function. uint8_t min_argc; ///< Minimal number of arguments. uint8_t max_argc; ///< Maximal number of arguments. - uint8_t base_arg; ///< Method base arg # (1-indexed), or 0 if not a method. + uint8_t base_arg; ///< Method base arg # (1-indexed), BASE_NONE or BASE_LAST. VimLFunc func; ///< Function implementation. FunPtr data; ///< Userdata for function implementation. } VimLFuncDef; |