home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.2 / 7.2.374 < prev    next >
Encoding:
Internet Message Format  |  2010-02-23  |  4.3 KB

  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. +     if (tv->v_type == VAR_STRING)
  69. +     {
  70. +         result = rb_str_new2((char *)tv->vval.v_string);
  71. +     }
  72. +     else if (tv->v_type == VAR_NUMBER)
  73. +     {
  74. +         result = INT2NUM(tv->vval.v_number);
  75. +     }
  76. + # ifdef FEAT_FLOAT
  77. +     else if (tv->v_type == VAR_FLOAT)
  78. +     {
  79. +         result = rb_float_new(tv->vval.v_float);
  80. +     }
  81. + # endif
  82. +     else if (tv->v_type == VAR_LIST)
  83. +     {
  84. +         list_T      *list = tv->vval.v_list;
  85. +         listitem_T  *curr;
  86. +         result = rb_ary_new();
  87. +         if (list != NULL)
  88. +         {
  89. +             for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
  90. +             {
  91. +                 rb_ary_push(result, vim_to_ruby(&curr->li_tv));
  92. +             }
  93. +         }
  94. +     }
  95. +     else if (tv->v_type == VAR_DICT)
  96. +     {
  97. +         result = rb_hash_new();
  98. +         if (tv->vval.v_dict != NULL)
  99. +         {
  100. +             hashtab_T   *ht = &tv->vval.v_dict->dv_hashtab;
  101. +             long_u      todo = ht->ht_used;
  102. +             hashitem_T  *hi;
  103. +             dictitem_T  *di;
  104. +             for (hi = ht->ht_array; todo > 0; ++hi)
  105. +             {
  106. +                 if (!HASHITEM_EMPTY(hi))
  107. +                 {
  108. +                     --todo;
  109. +                     di = dict_lookup(hi);
  110. +                     rb_hash_aset(result, rb_str_new2((char *)hi->hi_key),
  111. +                              vim_to_ruby(&di->di_tv));
  112. +                 }
  113. +             }
  114. +         }
  115. +     } /* else return Qnil; */
  116. +     return result;
  117. + }
  118. + #endif
  119.   static VALUE vim_evaluate(VALUE self UNUSED, VALUE str)
  120.   {
  121.   #ifdef FEAT_EVAL
  122. !     typval_T    *tv;
  123. !     VALUE       result;
  124.   
  125. !     tv = eval_expr((char_u *)StringValuePtr(str), NULL);
  126. !     if (tv == NULL)
  127.       {
  128. !         return Qnil;
  129.       }
  130. !     result = vim_to_ruby(tv);
  131. !     free_tv(tv);
  132. !     return result;
  133. ! #else
  134. !     return Qnil;
  135.   #endif
  136.   }
  137.   
  138.   static VALUE buffer_new(buf_T *buf)
  139. *** ../vim-7.2.373/src/version.c    2010-02-24 15:25:13.000000000 +0100
  140. --- src/version.c    2010-02-24 15:46:57.000000000 +0100
  141. ***************
  142. *** 683,684 ****
  143. --- 683,686 ----
  144.   {   /* Add new patch number below this line */
  145. + /**/
  146. +     374,
  147.   /**/
  148.  
  149. -- 
  150. ARTHUR: (as the MAN next to him is squashed by a sheep) Knights!  Run away!
  151.    Midst echoing shouts of "run away" the KNIGHTS retreat to cover with the odd
  152.    cow or goose hitting them still.  The KNIGHTS crouch down under cover.
  153.                  "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
  154.  
  155.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  156. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  157. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  158.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  159.