0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

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().
This commit is contained in:
Bram Moolenaar
2021-01-12 21:49:00 +01:00
parent 64ed4d4398
commit a47e05f04a
8 changed files with 52 additions and 4 deletions

View File

@@ -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