]> git.pld-linux.org Git - packages/vim.git/blob - 7.2.374
- new
[packages/vim.git] / 7.2.374
1 To: vim-dev@vim.org
2 Subject: Patch 7.2.374
3 Fcc: outbox
4 From: Bram Moolenaar <Bram@moolenaar.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8 ------------
9
10 Patch 7.2.374
11 Problem:    Ruby eval() doesn't understand Vim types.
12 Solution:   Add the vim_to_ruby() function.  (George Gensure)
13 Files:      src/eval.c, src/if_ruby.c
14
15
16 *** ../vim-7.2.373/src/eval.c   2010-01-19 15:51:29.000000000 +0100
17 --- src/eval.c  2010-02-24 15:36:40.000000000 +0100
18 ***************
19 *** 5872,5878 ****
20       return item1 == NULL && item2 == NULL;
21   }
22   
23 ! #if defined(FEAT_PYTHON) || defined(FEAT_MZSCHEME) || defined(PROTO)
24   /*
25    * Return the dictitem that an entry in a hashtable points to.
26    */
27 --- 5872,5879 ----
28       return item1 == NULL && item2 == NULL;
29   }
30   
31 ! #if defined(FEAT_RUBY) || defined(FEAT_PYTHON) || defined(FEAT_MZSCHEME) \
32 !       || defined(PROTO)
33   /*
34    * Return the dictitem that an entry in a hashtable points to.
35    */
36 *** ../vim-7.2.373/src/if_ruby.c        2010-02-18 15:51:25.000000000 +0100
37 --- src/if_ruby.c       2010-02-24 15:45:15.000000000 +0100
38 ***************
39 *** 660,679 ****
40       return Qnil;
41   }
42   
43   static VALUE vim_evaluate(VALUE self UNUSED, VALUE str)
44   {
45   #ifdef FEAT_EVAL
46 !     char_u *value = eval_to_string((char_u *)StringValuePtr(str), NULL, TRUE);
47   
48 !     if (value != NULL)
49       {
50 !       VALUE val = rb_str_new2((char *)value);
51 !       vim_free(value);
52 !       return val;
53       }
54 !     else
55   #endif
56 -       return Qnil;
57   }
58   
59   static VALUE buffer_new(buf_T *buf)
60 --- 660,747 ----
61       return Qnil;
62   }
63   
64 + #ifdef FEAT_EVAL
65 + static VALUE vim_to_ruby(typval_T *tv)
66 + {
67 +     VALUE result = Qnil;
68
69 +     if (tv->v_type == VAR_STRING)
70 +     {
71 +         result = rb_str_new2((char *)tv->vval.v_string);
72 +     }
73 +     else if (tv->v_type == VAR_NUMBER)
74 +     {
75 +         result = INT2NUM(tv->vval.v_number);
76 +     }
77 + # ifdef FEAT_FLOAT
78 +     else if (tv->v_type == VAR_FLOAT)
79 +     {
80 +         result = rb_float_new(tv->vval.v_float);
81 +     }
82 + # endif
83 +     else if (tv->v_type == VAR_LIST)
84 +     {
85 +         list_T      *list = tv->vval.v_list;
86 +         listitem_T  *curr;
87
88 +         result = rb_ary_new();
89
90 +         if (list != NULL)
91 +         {
92 +             for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
93 +             {
94 +                 rb_ary_push(result, vim_to_ruby(&curr->li_tv));
95 +             }
96 +         }
97 +     }
98 +     else if (tv->v_type == VAR_DICT)
99 +     {
100 +         result = rb_hash_new();
101
102 +         if (tv->vval.v_dict != NULL)
103 +         {
104 +             hashtab_T   *ht = &tv->vval.v_dict->dv_hashtab;
105 +             long_u      todo = ht->ht_used;
106 +             hashitem_T  *hi;
107 +             dictitem_T  *di;
108
109 +             for (hi = ht->ht_array; todo > 0; ++hi)
110 +             {
111 +                 if (!HASHITEM_EMPTY(hi))
112 +                 {
113 +                     --todo;
114
115 +                     di = dict_lookup(hi);
116 +                     rb_hash_aset(result, rb_str_new2((char *)hi->hi_key),
117 +                                                    vim_to_ruby(&di->di_tv));
118 +                 }
119 +             }
120 +         }
121 +     } /* else return Qnil; */
122
123 +     return result;
124 + }
125 + #endif
126
127   static VALUE vim_evaluate(VALUE self UNUSED, VALUE str)
128   {
129   #ifdef FEAT_EVAL
130 !     typval_T    *tv;
131 !     VALUE       result;
132   
133 !     tv = eval_expr((char_u *)StringValuePtr(str), NULL);
134 !     if (tv == NULL)
135       {
136 !         return Qnil;
137       }
138 !     result = vim_to_ruby(tv);
139
140 !     free_tv(tv);
141
142 !     return result;
143 ! #else
144 !     return Qnil;
145   #endif
146   }
147   
148   static VALUE buffer_new(buf_T *buf)
149 *** ../vim-7.2.373/src/version.c        2010-02-24 15:25:13.000000000 +0100
150 --- src/version.c       2010-02-24 15:46:57.000000000 +0100
151 ***************
152 *** 683,684 ****
153 --- 683,686 ----
154   {   /* Add new patch number below this line */
155 + /**/
156 +     374,
157   /**/
158
159 -- 
160 ARTHUR: (as the MAN next to him is squashed by a sheep) Knights!  Run away!
161    Midst echoing shouts of "run away" the KNIGHTS retreat to cover with the odd
162    cow or goose hitting them still.  The KNIGHTS crouch down under cover.
163                  "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
164
165  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
166 ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
167 \\\        download, build and distribute -- http://www.A-A-P.org        ///
168  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
This page took 0.040666 seconds and 3 git commands to generate.