Mercurial > vim
diff src/vim9type.c @ 23594:d3e064f54890 v8.2.2339
patch 8.2.2339: cannot get the type of a value as a string
Commit: https://github.com/vim/vim/commit/a47e05f04a5a5c0369c949157c24d09cbe64ad6a
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 12 21:49:00 2021 +0100
patch 8.2.2339: cannot get the type of a value as a string
Problem: Cannot get the type of a value as a string.
Solution: Add typename().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 12 Jan 2021 22:00:06 +0100 |
parents | 27ca5534a408 |
children | 8dcb2255ff9a |
line wrap: on
line diff
--- 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