mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
updated for version 7.2.374
Problem: Ruby eval() doesn't understand Vim types. Solution: Add the vim_to_ruby() function. (George Gensure)
This commit is contained in:
@@ -5872,7 +5872,8 @@ list_equal(l1, l2, ic)
|
|||||||
return item1 == NULL && item2 == NULL;
|
return item1 == NULL && item2 == NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(FEAT_PYTHON) || defined(FEAT_MZSCHEME) || defined(PROTO)
|
#if defined(FEAT_RUBY) || defined(FEAT_PYTHON) || defined(FEAT_MZSCHEME) \
|
||||||
|
|| defined(PROTO)
|
||||||
/*
|
/*
|
||||||
* Return the dictitem that an entry in a hashtable points to.
|
* Return the dictitem that an entry in a hashtable points to.
|
||||||
*/
|
*/
|
||||||
|
@@ -660,20 +660,88 @@ static VALUE vim_command(VALUE self UNUSED, VALUE str)
|
|||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef FEAT_EVAL
|
||||||
|
static VALUE vim_to_ruby(typval_T *tv)
|
||||||
|
{
|
||||||
|
VALUE result = Qnil;
|
||||||
|
|
||||||
|
if (tv->v_type == VAR_STRING)
|
||||||
|
{
|
||||||
|
result = rb_str_new2((char *)tv->vval.v_string);
|
||||||
|
}
|
||||||
|
else if (tv->v_type == VAR_NUMBER)
|
||||||
|
{
|
||||||
|
result = INT2NUM(tv->vval.v_number);
|
||||||
|
}
|
||||||
|
# ifdef FEAT_FLOAT
|
||||||
|
else if (tv->v_type == VAR_FLOAT)
|
||||||
|
{
|
||||||
|
result = rb_float_new(tv->vval.v_float);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
else if (tv->v_type == VAR_LIST)
|
||||||
|
{
|
||||||
|
list_T *list = tv->vval.v_list;
|
||||||
|
listitem_T *curr;
|
||||||
|
|
||||||
|
result = rb_ary_new();
|
||||||
|
|
||||||
|
if (list != NULL)
|
||||||
|
{
|
||||||
|
for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
|
||||||
|
{
|
||||||
|
rb_ary_push(result, vim_to_ruby(&curr->li_tv));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (tv->v_type == VAR_DICT)
|
||||||
|
{
|
||||||
|
result = rb_hash_new();
|
||||||
|
|
||||||
|
if (tv->vval.v_dict != NULL)
|
||||||
|
{
|
||||||
|
hashtab_T *ht = &tv->vval.v_dict->dv_hashtab;
|
||||||
|
long_u todo = ht->ht_used;
|
||||||
|
hashitem_T *hi;
|
||||||
|
dictitem_T *di;
|
||||||
|
|
||||||
|
for (hi = ht->ht_array; todo > 0; ++hi)
|
||||||
|
{
|
||||||
|
if (!HASHITEM_EMPTY(hi))
|
||||||
|
{
|
||||||
|
--todo;
|
||||||
|
|
||||||
|
di = dict_lookup(hi);
|
||||||
|
rb_hash_aset(result, rb_str_new2((char *)hi->hi_key),
|
||||||
|
vim_to_ruby(&di->di_tv));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} /* else return Qnil; */
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static VALUE vim_evaluate(VALUE self UNUSED, VALUE str)
|
static VALUE vim_evaluate(VALUE self UNUSED, VALUE str)
|
||||||
{
|
{
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
char_u *value = eval_to_string((char_u *)StringValuePtr(str), NULL, TRUE);
|
typval_T *tv;
|
||||||
|
VALUE result;
|
||||||
|
|
||||||
if (value != NULL)
|
tv = eval_expr((char_u *)StringValuePtr(str), NULL);
|
||||||
|
if (tv == NULL)
|
||||||
{
|
{
|
||||||
VALUE val = rb_str_new2((char *)value);
|
|
||||||
vim_free(value);
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
}
|
||||||
|
result = vim_to_ruby(tv);
|
||||||
|
|
||||||
|
free_tv(tv);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
#else
|
||||||
|
return Qnil;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE buffer_new(buf_T *buf)
|
static VALUE buffer_new(buf_T *buf)
|
||||||
|
@@ -681,6 +681,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
374,
|
||||||
/**/
|
/**/
|
||||||
373,
|
373,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user