4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
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
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
20 return item1 == NULL && item2 == NULL;
23 ! #if defined(FEAT_PYTHON) || defined(FEAT_MZSCHEME) || defined(PROTO)
25 * Return the dictitem that an entry in a hashtable points to.
28 return item1 == NULL && item2 == NULL;
31 ! #if defined(FEAT_RUBY) || defined(FEAT_PYTHON) || defined(FEAT_MZSCHEME) \
34 * Return the dictitem that an entry in a hashtable points to.
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
43 static VALUE vim_evaluate(VALUE self UNUSED, VALUE str)
46 ! char_u *value = eval_to_string((char_u *)StringValuePtr(str), NULL, TRUE);
50 ! VALUE val = rb_str_new2((char *)value);
59 static VALUE buffer_new(buf_T *buf)
65 + static VALUE vim_to_ruby(typval_T *tv)
67 + VALUE result = Qnil;
69 + if (tv->v_type == VAR_STRING)
71 + result = rb_str_new2((char *)tv->vval.v_string);
73 + else if (tv->v_type == VAR_NUMBER)
75 + result = INT2NUM(tv->vval.v_number);
78 + else if (tv->v_type == VAR_FLOAT)
80 + result = rb_float_new(tv->vval.v_float);
83 + else if (tv->v_type == VAR_LIST)
85 + list_T *list = tv->vval.v_list;
88 + result = rb_ary_new();
92 + for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
94 + rb_ary_push(result, vim_to_ruby(&curr->li_tv));
98 + else if (tv->v_type == VAR_DICT)
100 + result = rb_hash_new();
102 + if (tv->vval.v_dict != NULL)
104 + hashtab_T *ht = &tv->vval.v_dict->dv_hashtab;
105 + long_u todo = ht->ht_used;
109 + for (hi = ht->ht_array; todo > 0; ++hi)
111 + if (!HASHITEM_EMPTY(hi))
115 + di = dict_lookup(hi);
116 + rb_hash_aset(result, rb_str_new2((char *)hi->hi_key),
117 + vim_to_ruby(&di->di_tv));
121 + } /* else return Qnil; */
127 static VALUE vim_evaluate(VALUE self UNUSED, VALUE str)
133 ! tv = eval_expr((char_u *)StringValuePtr(str), NULL);
138 ! result = vim_to_ruby(tv);
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
154 { /* Add new patch number below this line */
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
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 ///