diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-01-12 21:49:00 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-01-12 21:49:00 +0100 |
commit | a47e05f04a5a5c0369c949157c24d09cbe64ad6a (patch) | |
tree | 7d6a27b717ed6c478f4642fd7af13913a4c07f3b /src/vim9type.c | |
parent | 64ed4d4398e92ac56a9bbd66d5ec992dd4c335f7 (diff) | |
download | vim-git-a47e05f04a5a5c0369c949157c24d09cbe64ad6a.tar.gz |
patch 8.2.2339: cannot get the type of a value as a stringv8.2.2339
Problem: Cannot get the type of a value as a string.
Solution: Add typename().
Diffstat (limited to 'src/vim9type.c')
-rw-r--r-- | src/vim9type.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/vim9type.c b/src/vim9type.c index c65f74748..85f9bd834 100644 --- a/src/vim9type.c +++ b/src/vim9type.c @@ -1170,4 +1170,29 @@ type_name(type_T *type, char **tofree) return name; } +/* + * "typename(expr)" function + */ + void +f_typename(typval_T *argvars, typval_T *rettv) +{ + garray_T type_list; + type_T *type; + char *tofree; + char *name; + + rettv->v_type = VAR_STRING; + ga_init2(&type_list, sizeof(type_T *), 10); + type = typval2type(argvars, &type_list); + name = type_name(type, &tofree); + if (tofree != NULL) + rettv->vval.v_string = (char_u *)tofree; + else + { + rettv->vval.v_string = vim_strsave((char_u *)name); + vim_free(tofree); + } + clear_type_list(&type_list); +} + #endif // FEAT_EVAL |