Mercurial > vim
comparison src/eval.c @ 7712:bce3b5ddb393 v7.4.1154
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 23 19:46:28 2016 +0100
patch 7.4.1154
Problem: No support for JSON.
Solution: Add jsonencode() and jsondecode(). Also add v:false, v:true,
v:null and v:none.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 23 Jan 2016 20:00:04 +0100 |
parents | 1b9a1c10806b |
children | c29a7e38b8ac |
comparison
equal
deleted
inserted
replaced
7711:5fe266fb2a6e | 7712:bce3b5ddb393 |
---|---|
97 static char *e_listidx = N_("E684: list index out of range: %ld"); | 97 static char *e_listidx = N_("E684: list index out of range: %ld"); |
98 static char *e_undefvar = N_("E121: Undefined variable: %s"); | 98 static char *e_undefvar = N_("E121: Undefined variable: %s"); |
99 static char *e_missbrac = N_("E111: Missing ']'"); | 99 static char *e_missbrac = N_("E111: Missing ']'"); |
100 static char *e_listarg = N_("E686: Argument of %s must be a List"); | 100 static char *e_listarg = N_("E686: Argument of %s must be a List"); |
101 static char *e_listdictarg = N_("E712: Argument of %s must be a List or Dictionary"); | 101 static char *e_listdictarg = N_("E712: Argument of %s must be a List or Dictionary"); |
102 static char *e_emptykey = N_("E713: Cannot use empty key for Dictionary"); | |
103 static char *e_listreq = N_("E714: List required"); | 102 static char *e_listreq = N_("E714: List required"); |
104 static char *e_dictreq = N_("E715: Dictionary required"); | 103 static char *e_dictreq = N_("E715: Dictionary required"); |
105 static char *e_toomanyarg = N_("E118: Too many arguments for function: %s"); | 104 static char *e_toomanyarg = N_("E118: Too many arguments for function: %s"); |
106 static char *e_dictkey = N_("E716: Key not present in Dictionary: %s"); | 105 static char *e_dictkey = N_("E716: Key not present in Dictionary: %s"); |
107 static char *e_funcexts = N_("E122: Function %s already exists, add ! to replace it"); | 106 static char *e_funcexts = N_("E122: Function %s already exists, add ! to replace it"); |
369 {VV_NAME("completed_item", VAR_DICT), VV_RO}, | 368 {VV_NAME("completed_item", VAR_DICT), VV_RO}, |
370 {VV_NAME("option_new", VAR_STRING), VV_RO}, | 369 {VV_NAME("option_new", VAR_STRING), VV_RO}, |
371 {VV_NAME("option_old", VAR_STRING), VV_RO}, | 370 {VV_NAME("option_old", VAR_STRING), VV_RO}, |
372 {VV_NAME("option_type", VAR_STRING), VV_RO}, | 371 {VV_NAME("option_type", VAR_STRING), VV_RO}, |
373 {VV_NAME("errors", VAR_LIST), 0}, | 372 {VV_NAME("errors", VAR_LIST), 0}, |
373 {VV_NAME("false", VAR_SPECIAL), VV_RO}, | |
374 {VV_NAME("true", VAR_SPECIAL), VV_RO}, | |
375 {VV_NAME("null", VAR_SPECIAL), VV_RO}, | |
376 {VV_NAME("none", VAR_SPECIAL), VV_RO}, | |
374 }; | 377 }; |
375 | 378 |
376 /* shorthand */ | 379 /* shorthand */ |
377 #define vv_type vv_di.di_tv.v_type | 380 #define vv_type vv_di.di_tv.v_type |
378 #define vv_nr vv_di.di_tv.vval.v_number | 381 #define vv_nr vv_di.di_tv.vval.v_number |
426 static int eval_index __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose)); | 429 static int eval_index __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose)); |
427 static int get_option_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); | 430 static int get_option_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
428 static int get_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); | 431 static int get_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
429 static int get_lit_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); | 432 static int get_lit_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
430 static int get_list_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); | 433 static int get_list_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
431 static int rettv_list_alloc __ARGS((typval_T *rettv)); | |
432 static long list_len __ARGS((list_T *l)); | 434 static long list_len __ARGS((list_T *l)); |
433 static int list_equal __ARGS((list_T *l1, list_T *l2, int ic, int recursive)); | 435 static int list_equal __ARGS((list_T *l1, list_T *l2, int ic, int recursive)); |
434 static int dict_equal __ARGS((dict_T *d1, dict_T *d2, int ic, int recursive)); | 436 static int dict_equal __ARGS((dict_T *d1, dict_T *d2, int ic, int recursive)); |
435 static int tv_equal __ARGS((typval_T *tv1, typval_T *tv2, int ic, int recursive)); | 437 static int tv_equal __ARGS((typval_T *tv1, typval_T *tv2, int ic, int recursive)); |
436 static long list_find_nr __ARGS((list_T *l, long idx, int *errorp)); | 438 static long list_find_nr __ARGS((list_T *l, long idx, int *errorp)); |
441 static list_T *list_copy __ARGS((list_T *orig, int deep, int copyID)); | 443 static list_T *list_copy __ARGS((list_T *orig, int deep, int copyID)); |
442 static char_u *list2string __ARGS((typval_T *tv, int copyID)); | 444 static char_u *list2string __ARGS((typval_T *tv, int copyID)); |
443 static int list_join_inner __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo_style, int copyID, garray_T *join_gap)); | 445 static int list_join_inner __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo_style, int copyID, garray_T *join_gap)); |
444 static int list_join __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo, int copyID)); | 446 static int list_join __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo, int copyID)); |
445 static int free_unref_items __ARGS((int copyID)); | 447 static int free_unref_items __ARGS((int copyID)); |
446 static int rettv_dict_alloc __ARGS((typval_T *rettv)); | |
447 static dictitem_T *dictitem_copy __ARGS((dictitem_T *org)); | 448 static dictitem_T *dictitem_copy __ARGS((dictitem_T *org)); |
448 static void dictitem_remove __ARGS((dict_T *dict, dictitem_T *item)); | 449 static void dictitem_remove __ARGS((dict_T *dict, dictitem_T *item)); |
449 static dict_T *dict_copy __ARGS((dict_T *orig, int deep, int copyID)); | 450 static dict_T *dict_copy __ARGS((dict_T *orig, int deep, int copyID)); |
450 static long dict_len __ARGS((dict_T *d)); | 451 static long dict_len __ARGS((dict_T *d)); |
451 static char_u *dict2string __ARGS((typval_T *tv, int copyID)); | 452 static char_u *dict2string __ARGS((typval_T *tv, int copyID)); |
452 static int get_dict_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); | 453 static int get_dict_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
453 static char_u *echo_string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf, int copyID)); | 454 static char_u *echo_string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf, int copyID)); |
454 static char_u *tv2string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf, int copyID)); | 455 static char_u *tv2string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf, int copyID)); |
455 static char_u *string_quote __ARGS((char_u *str, int function)); | 456 static char_u *string_quote __ARGS((char_u *str, int function)); |
456 #ifdef FEAT_FLOAT | |
457 static int string2float __ARGS((char_u *text, float_T *value)); | |
458 #endif | |
459 static int get_env_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); | 457 static int get_env_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
460 static int find_internal_func __ARGS((char_u *name)); | 458 static int find_internal_func __ARGS((char_u *name)); |
461 static char_u *deref_func_name __ARGS((char_u *name, int *lenp, int no_autoload)); | 459 static char_u *deref_func_name __ARGS((char_u *name, int *lenp, int no_autoload)); |
462 static int get_func_tv __ARGS((char_u *name, int len, typval_T *rettv, char_u **arg, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict)); | 460 static int get_func_tv __ARGS((char_u *name, int len, typval_T *rettv, char_u **arg, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict)); |
463 static int call_func __ARGS((char_u *funcname, int len, typval_T *rettv, int argcount, typval_T *argvars, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict)); | 461 static int call_func __ARGS((char_u *funcname, int len, typval_T *rettv, int argcount, typval_T *argvars, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict)); |
615 static void f_invert __ARGS((typval_T *argvars, typval_T *rettv)); | 613 static void f_invert __ARGS((typval_T *argvars, typval_T *rettv)); |
616 static void f_isdirectory __ARGS((typval_T *argvars, typval_T *rettv)); | 614 static void f_isdirectory __ARGS((typval_T *argvars, typval_T *rettv)); |
617 static void f_islocked __ARGS((typval_T *argvars, typval_T *rettv)); | 615 static void f_islocked __ARGS((typval_T *argvars, typval_T *rettv)); |
618 static void f_items __ARGS((typval_T *argvars, typval_T *rettv)); | 616 static void f_items __ARGS((typval_T *argvars, typval_T *rettv)); |
619 static void f_join __ARGS((typval_T *argvars, typval_T *rettv)); | 617 static void f_join __ARGS((typval_T *argvars, typval_T *rettv)); |
618 static void f_jsondecode __ARGS((typval_T *argvars, typval_T *rettv)); | |
619 static void f_jsonencode __ARGS((typval_T *argvars, typval_T *rettv)); | |
620 static void f_keys __ARGS((typval_T *argvars, typval_T *rettv)); | 620 static void f_keys __ARGS((typval_T *argvars, typval_T *rettv)); |
621 static void f_last_buffer_nr __ARGS((typval_T *argvars, typval_T *rettv)); | 621 static void f_last_buffer_nr __ARGS((typval_T *argvars, typval_T *rettv)); |
622 static void f_len __ARGS((typval_T *argvars, typval_T *rettv)); | 622 static void f_len __ARGS((typval_T *argvars, typval_T *rettv)); |
623 static void f_libcall __ARGS((typval_T *argvars, typval_T *rettv)); | 623 static void f_libcall __ARGS((typval_T *argvars, typval_T *rettv)); |
624 static void f_libcallnr __ARGS((typval_T *argvars, typval_T *rettv)); | 624 static void f_libcallnr __ARGS((typval_T *argvars, typval_T *rettv)); |
814 #endif | 814 #endif |
815 static linenr_T get_tv_lnum __ARGS((typval_T *argvars)); | 815 static linenr_T get_tv_lnum __ARGS((typval_T *argvars)); |
816 static linenr_T get_tv_lnum_buf __ARGS((typval_T *argvars, buf_T *buf)); | 816 static linenr_T get_tv_lnum_buf __ARGS((typval_T *argvars, buf_T *buf)); |
817 static char_u *get_tv_string __ARGS((typval_T *varp)); | 817 static char_u *get_tv_string __ARGS((typval_T *varp)); |
818 static char_u *get_tv_string_buf __ARGS((typval_T *varp, char_u *buf)); | 818 static char_u *get_tv_string_buf __ARGS((typval_T *varp, char_u *buf)); |
819 static char_u *get_tv_string_buf_chk __ARGS((typval_T *varp, char_u *buf)); | |
820 static dictitem_T *find_var __ARGS((char_u *name, hashtab_T **htp, int no_autoload)); | 819 static dictitem_T *find_var __ARGS((char_u *name, hashtab_T **htp, int no_autoload)); |
821 static dictitem_T *find_var_in_ht __ARGS((hashtab_T *ht, int htname, char_u *varname, int no_autoload)); | 820 static dictitem_T *find_var_in_ht __ARGS((hashtab_T *ht, int htname, char_u *varname, int no_autoload)); |
822 static hashtab_T *find_var_ht __ARGS((char_u *name, char_u **varname)); | 821 static hashtab_T *find_var_ht __ARGS((char_u *name, char_u **varname)); |
823 static funccall_T *get_funccal __ARGS((void)); | 822 static funccall_T *get_funccal __ARGS((void)); |
824 static void vars_clear_ext __ARGS((hashtab_T *ht, int free_val)); | 823 static void vars_clear_ext __ARGS((hashtab_T *ht, int free_val)); |
913 } | 912 } |
914 set_vim_var_nr(VV_SEARCHFORWARD, 1L); | 913 set_vim_var_nr(VV_SEARCHFORWARD, 1L); |
915 set_vim_var_nr(VV_HLSEARCH, 1L); | 914 set_vim_var_nr(VV_HLSEARCH, 1L); |
916 set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc()); | 915 set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc()); |
917 set_vim_var_list(VV_ERRORS, list_alloc()); | 916 set_vim_var_list(VV_ERRORS, list_alloc()); |
917 | |
918 set_vim_var_nr(VV_FALSE, VVAL_FALSE); | |
919 set_vim_var_nr(VV_TRUE, VVAL_TRUE); | |
920 set_vim_var_nr(VV_NONE, VVAL_NONE); | |
921 set_vim_var_nr(VV_NULL, VVAL_NULL); | |
922 | |
918 set_reg_var(0); /* default for v:register is not 0 but '"' */ | 923 set_reg_var(0); /* default for v:register is not 0 but '"' */ |
919 | 924 |
920 #ifdef EBCDIC | 925 #ifdef EBCDIC |
921 /* | 926 /* |
922 * Sort the function table, to enable binary search. | 927 * Sort the function table, to enable binary search. |
3078 { | 3083 { |
3079 long n; | 3084 long n; |
3080 char_u numbuf[NUMBUFLEN]; | 3085 char_u numbuf[NUMBUFLEN]; |
3081 char_u *s; | 3086 char_u *s; |
3082 | 3087 |
3083 /* Can't do anything with a Funcref or a Dict on the right. */ | 3088 /* Can't do anything with a Funcref, Dict, v:true on the right. */ |
3084 if (tv2->v_type != VAR_FUNC && tv2->v_type != VAR_DICT) | 3089 if (tv2->v_type != VAR_FUNC && tv2->v_type != VAR_DICT |
3090 && tv2->v_type != VAR_SPECIAL) | |
3085 { | 3091 { |
3086 switch (tv1->v_type) | 3092 switch (tv1->v_type) |
3087 { | 3093 { |
3088 case VAR_DICT: | 3094 case VAR_DICT: |
3089 case VAR_FUNC: | 3095 case VAR_FUNC: |
3096 case VAR_SPECIAL: | |
3090 break; | 3097 break; |
3091 | 3098 |
3092 case VAR_LIST: | 3099 case VAR_LIST: |
3093 if (*op != '+' || tv2->v_type != VAR_LIST) | 3100 if (*op != '+' || tv2->v_type != VAR_LIST) |
3094 break; | 3101 break; |
5388 if (verbose) | 5395 if (verbose) |
5389 EMSG(_(e_float_as_string)); | 5396 EMSG(_(e_float_as_string)); |
5390 return FAIL; | 5397 return FAIL; |
5391 } | 5398 } |
5392 #endif | 5399 #endif |
5400 else if (rettv->v_type == VAR_SPECIAL) | |
5401 { | |
5402 return FAIL; | |
5403 } | |
5393 | 5404 |
5394 init_tv(&var1); | 5405 init_tv(&var1); |
5395 init_tv(&var2); | 5406 init_tv(&var2); |
5396 if (**arg == '.') | 5407 if (**arg == '.') |
5397 { | 5408 { |
5997 | 6008 |
5998 /* | 6009 /* |
5999 * Allocate an empty list for a return value. | 6010 * Allocate an empty list for a return value. |
6000 * Returns OK or FAIL. | 6011 * Returns OK or FAIL. |
6001 */ | 6012 */ |
6002 static int | 6013 int |
6003 rettv_list_alloc(rettv) | 6014 rettv_list_alloc(rettv) |
6004 typval_T *rettv; | 6015 typval_T *rettv; |
6005 { | 6016 { |
6006 list_T *l = list_alloc(); | 6017 list_T *l = list_alloc(); |
6007 | 6018 |
6244 | 6255 |
6245 case VAR_STRING: | 6256 case VAR_STRING: |
6246 s1 = get_tv_string_buf(tv1, buf1); | 6257 s1 = get_tv_string_buf(tv1, buf1); |
6247 s2 = get_tv_string_buf(tv2, buf2); | 6258 s2 = get_tv_string_buf(tv2, buf2); |
6248 return ((ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2)) == 0); | 6259 return ((ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2)) == 0); |
6260 | |
6261 case VAR_SPECIAL: | |
6262 return tv1->vval.v_number == tv2->vval.v_number; | |
6249 } | 6263 } |
6250 | 6264 |
6251 EMSG2(_(e_intern2), "tv_equal()"); | 6265 EMSG2(_(e_intern2), "tv_equal()"); |
6252 return TRUE; | 6266 return TRUE; |
6253 } | 6267 } |
6833 } | 6847 } |
6834 ga_clear(&join_ga); | 6848 ga_clear(&join_ga); |
6835 } | 6849 } |
6836 | 6850 |
6837 return retval; | 6851 return retval; |
6852 } | |
6853 | |
6854 /* | |
6855 * Return the next (unique) copy ID. | |
6856 * Used for serializing nested structures. | |
6857 */ | |
6858 int | |
6859 get_copyID() | |
6860 { | |
6861 current_copyID += COPYID_INC; | |
6862 return current_copyID; | |
6838 } | 6863 } |
6839 | 6864 |
6840 /* | 6865 /* |
6841 * Garbage collection for lists and dictionaries. | 6866 * Garbage collection for lists and dictionaries. |
6842 * | 6867 * |
6881 may_garbage_collect = FALSE; | 6906 may_garbage_collect = FALSE; |
6882 garbage_collect_at_exit = FALSE; | 6907 garbage_collect_at_exit = FALSE; |
6883 | 6908 |
6884 /* We advance by two because we add one for items referenced through | 6909 /* We advance by two because we add one for items referenced through |
6885 * previous_funccal. */ | 6910 * previous_funccal. */ |
6886 current_copyID += COPYID_INC; | 6911 copyID = get_copyID(); |
6887 copyID = current_copyID; | |
6888 | 6912 |
6889 /* | 6913 /* |
6890 * 1. Go through all accessible variables and mark all lists and dicts | 6914 * 1. Go through all accessible variables and mark all lists and dicts |
6891 * with copyID. | 6915 * with copyID. |
6892 */ | 6916 */ |
7234 | 7258 |
7235 /* | 7259 /* |
7236 * Allocate an empty dict for a return value. | 7260 * Allocate an empty dict for a return value. |
7237 * Returns OK or FAIL. | 7261 * Returns OK or FAIL. |
7238 */ | 7262 */ |
7239 static int | 7263 int |
7240 rettv_dict_alloc(rettv) | 7264 rettv_dict_alloc(rettv) |
7241 typval_T *rettv; | 7265 typval_T *rettv; |
7242 { | 7266 { |
7243 dict_T *d = dict_alloc(); | 7267 dict_T *d = dict_alloc(); |
7244 | 7268 |
7889 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv->vval.v_float); | 7913 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv->vval.v_float); |
7890 r = numbuf; | 7914 r = numbuf; |
7891 break; | 7915 break; |
7892 #endif | 7916 #endif |
7893 | 7917 |
7918 case VAR_SPECIAL: | |
7919 *tofree = NULL; | |
7920 switch (tv->vval.v_number) | |
7921 { | |
7922 case VVAL_FALSE: r = (char_u *)"false"; break; | |
7923 case VVAL_TRUE: r = (char_u *)"true"; break; | |
7924 case VVAL_NONE: r = (char_u *)"none"; break; | |
7925 case VVAL_NULL: r = (char_u *)"null"; break; | |
7926 default: EMSG2(_(e_intern2), "echo_string(special)"); | |
7927 } | |
7928 break; | |
7929 | |
7894 default: | 7930 default: |
7895 EMSG2(_(e_intern2), "echo_string()"); | 7931 EMSG2(_(e_intern2), "echo_string()"); |
7896 *tofree = NULL; | 7932 *tofree = NULL; |
7897 } | 7933 } |
7898 | 7934 |
7930 return numbuf; | 7966 return numbuf; |
7931 #endif | 7967 #endif |
7932 case VAR_NUMBER: | 7968 case VAR_NUMBER: |
7933 case VAR_LIST: | 7969 case VAR_LIST: |
7934 case VAR_DICT: | 7970 case VAR_DICT: |
7971 case VAR_SPECIAL: | |
7935 break; | 7972 break; |
7936 default: | 7973 default: |
7937 EMSG2(_(e_intern2), "tv2string()"); | 7974 EMSG2(_(e_intern2), "tv2string()"); |
7938 } | 7975 } |
7939 return echo_string(tv, tofree, numbuf, copyID); | 7976 return echo_string(tv, tofree, numbuf, copyID); |
7983 *r++ = NUL; | 8020 *r++ = NUL; |
7984 } | 8021 } |
7985 return s; | 8022 return s; |
7986 } | 8023 } |
7987 | 8024 |
7988 #ifdef FEAT_FLOAT | 8025 #if defined(FEAT_FLOAT) || defined(PROTO) |
7989 /* | 8026 /* |
7990 * Convert the string "text" to a floating point number. | 8027 * Convert the string "text" to a floating point number. |
7991 * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure | 8028 * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure |
7992 * this always uses a decimal point. | 8029 * this always uses a decimal point. |
7993 * Returns the length of the text that was consumed. | 8030 * Returns the length of the text that was consumed. |
7994 */ | 8031 */ |
7995 static int | 8032 int |
7996 string2float(text, value) | 8033 string2float(text, value) |
7997 char_u *text; | 8034 char_u *text; |
7998 float_T *value; /* result stored here */ | 8035 float_T *value; /* result stored here */ |
7999 { | 8036 { |
8000 char *s = (char *)text; | 8037 char *s = (char *)text; |
8235 {"invert", 1, 1, f_invert}, | 8272 {"invert", 1, 1, f_invert}, |
8236 {"isdirectory", 1, 1, f_isdirectory}, | 8273 {"isdirectory", 1, 1, f_isdirectory}, |
8237 {"islocked", 1, 1, f_islocked}, | 8274 {"islocked", 1, 1, f_islocked}, |
8238 {"items", 1, 1, f_items}, | 8275 {"items", 1, 1, f_items}, |
8239 {"join", 1, 2, f_join}, | 8276 {"join", 1, 2, f_join}, |
8277 {"jsondecode", 1, 1, f_jsondecode}, | |
8278 {"jsonencode", 1, 1, f_jsonencode}, | |
8240 {"keys", 1, 1, f_keys}, | 8279 {"keys", 1, 1, f_keys}, |
8241 {"last_buffer_nr", 0, 0, f_last_buffer_nr},/* obsolete */ | 8280 {"last_buffer_nr", 0, 0, f_last_buffer_nr},/* obsolete */ |
8242 {"len", 1, 1, f_len}, | 8281 {"len", 1, 1, f_len}, |
8243 {"libcall", 3, 3, f_libcall}, | 8282 {"libcall", 3, 3, f_libcall}, |
8244 {"libcallnr", 3, 3, f_libcallnr}, | 8283 {"libcallnr", 3, 3, f_libcallnr}, |
14389 ga_append(&ga, NUL); | 14428 ga_append(&ga, NUL); |
14390 rettv->vval.v_string = (char_u *)ga.ga_data; | 14429 rettv->vval.v_string = (char_u *)ga.ga_data; |
14391 } | 14430 } |
14392 else | 14431 else |
14393 rettv->vval.v_string = NULL; | 14432 rettv->vval.v_string = NULL; |
14433 } | |
14434 | |
14435 /* | |
14436 * "jsondecode()" function | |
14437 */ | |
14438 static void | |
14439 f_jsondecode(argvars, rettv) | |
14440 typval_T *argvars; | |
14441 typval_T *rettv; | |
14442 { | |
14443 js_read_T reader; | |
14444 | |
14445 reader.js_buf = get_tv_string(&argvars[0]); | |
14446 reader.js_eof = TRUE; | |
14447 reader.js_used = 0; | |
14448 json_decode(&reader, rettv); | |
14449 } | |
14450 | |
14451 /* | |
14452 * "jsonencode()" function | |
14453 */ | |
14454 static void | |
14455 f_jsonencode(argvars, rettv) | |
14456 typval_T *argvars; | |
14457 typval_T *rettv; | |
14458 { | |
14459 rettv->v_type = VAR_STRING; | |
14460 rettv->vval.v_string = json_encode(&argvars[0]); | |
14394 } | 14461 } |
14395 | 14462 |
14396 /* | 14463 /* |
14397 * "keys()" function | 14464 * "keys()" function |
14398 */ | 14465 */ |
21556 case VAR_DICT: | 21623 case VAR_DICT: |
21557 dict_unref(varp->vval.v_dict); | 21624 dict_unref(varp->vval.v_dict); |
21558 varp->vval.v_dict = NULL; | 21625 varp->vval.v_dict = NULL; |
21559 break; | 21626 break; |
21560 case VAR_NUMBER: | 21627 case VAR_NUMBER: |
21628 case VAR_SPECIAL: | |
21561 varp->vval.v_number = 0; | 21629 varp->vval.v_number = 0; |
21562 break; | 21630 break; |
21563 #ifdef FEAT_FLOAT | 21631 #ifdef FEAT_FLOAT |
21564 case VAR_FLOAT: | 21632 case VAR_FLOAT: |
21565 varp->vval.v_float = 0.0; | 21633 varp->vval.v_float = 0.0; |
21757 static char_u mybuf[NUMBUFLEN]; | 21825 static char_u mybuf[NUMBUFLEN]; |
21758 | 21826 |
21759 return get_tv_string_buf_chk(varp, mybuf); | 21827 return get_tv_string_buf_chk(varp, mybuf); |
21760 } | 21828 } |
21761 | 21829 |
21762 static char_u * | 21830 char_u * |
21763 get_tv_string_buf_chk(varp, buf) | 21831 get_tv_string_buf_chk(varp, buf) |
21764 typval_T *varp; | 21832 typval_T *varp; |
21765 char_u *buf; | 21833 char_u *buf; |
21766 { | 21834 { |
21767 switch (varp->v_type) | 21835 switch (varp->v_type) |
22118 { | 22186 { |
22119 char_u *tofree; | 22187 char_u *tofree; |
22120 char_u *s; | 22188 char_u *s; |
22121 char_u numbuf[NUMBUFLEN]; | 22189 char_u numbuf[NUMBUFLEN]; |
22122 | 22190 |
22123 current_copyID += COPYID_INC; | 22191 s = echo_string(&v->di_tv, &tofree, numbuf, get_copyID()); |
22124 s = echo_string(&v->di_tv, &tofree, numbuf, current_copyID); | |
22125 list_one_var_a(prefix, v->di_key, v->di_tv.v_type, | 22192 list_one_var_a(prefix, v->di_key, v->di_tv.v_type, |
22126 s == NULL ? (char_u *)"" : s, first); | 22193 s == NULL ? (char_u *)"" : s, first); |
22127 vim_free(tofree); | 22194 vim_free(tofree); |
22128 } | 22195 } |
22129 | 22196 |
22433 to->v_type = from->v_type; | 22500 to->v_type = from->v_type; |
22434 to->v_lock = 0; | 22501 to->v_lock = 0; |
22435 switch (from->v_type) | 22502 switch (from->v_type) |
22436 { | 22503 { |
22437 case VAR_NUMBER: | 22504 case VAR_NUMBER: |
22505 case VAR_SPECIAL: | |
22438 to->vval.v_number = from->vval.v_number; | 22506 to->vval.v_number = from->vval.v_number; |
22439 break; | 22507 break; |
22440 #ifdef FEAT_FLOAT | 22508 #ifdef FEAT_FLOAT |
22441 case VAR_FLOAT: | 22509 case VAR_FLOAT: |
22442 to->vval.v_float = from->vval.v_float; | 22510 to->vval.v_float = from->vval.v_float; |
22607 msg_start(); | 22675 msg_start(); |
22608 } | 22676 } |
22609 } | 22677 } |
22610 else if (eap->cmdidx == CMD_echo) | 22678 else if (eap->cmdidx == CMD_echo) |
22611 msg_puts_attr((char_u *)" ", echo_attr); | 22679 msg_puts_attr((char_u *)" ", echo_attr); |
22612 current_copyID += COPYID_INC; | 22680 p = echo_string(&rettv, &tofree, numbuf, get_copyID()); |
22613 p = echo_string(&rettv, &tofree, numbuf, current_copyID); | |
22614 if (p != NULL) | 22681 if (p != NULL) |
22615 for ( ; *p != NUL && !got_int; ++p) | 22682 for ( ; *p != NUL && !got_int; ++p) |
22616 { | 22683 { |
22617 if (*p == '\n' || *p == '\r' || *p == TAB) | 22684 if (*p == '\n' || *p == '\r' || *p == TAB) |
22618 { | 22685 { |