Skip to content
Browse files

patch 8.1.1056: no eval function for Ruby

Problem:    No eval function for Ruby.
Solution:   Add rubyeval(). (Ozaki Kiichi, closes #4152)
  • Loading branch information...
brammool committed Mar 26, 2019
1 parent 75bf3d2 commit e99be0e6d28fad96efd2b2be23fa38e7559e80e1
Showing with 432 additions and 184 deletions.
  1. +12 −0 runtime/doc/eval.txt
  2. +12 −2 runtime/doc/if_ruby.txt
  3. +21 −0 src/evalfunc.c
  4. +309 −113 src/if_ruby.c
  5. +1 −0 src/proto/
  6. +75 −69 src/testdir/test_ruby.vim
  7. +2 −0 src/version.c
@@ -2521,6 +2521,7 @@ repeat({expr}, {count}) String repeat {expr} {count} times
resolve({filename}) String get filename a shortcut points to
reverse({list}) List reverse {list} in-place
round({expr}) Float round off {expr}
rubyeval({expr}) any evaluate |Ruby| expression
screenattr({row}, {col}) Number attribute at screen position
screenchar({row}, {col}) Number character at screen position
screencol() Number current cursor column
@@ -7432,6 +7433,17 @@ round({expr}) *round()*
< -5.0
{only available when compiled with the |+float| feature}

rubyeval({expr}) *rubyeval()*
Evaluate Ruby expression {expr} and return its result
converted to Vim data structures.
Numbers, floats and strings are returned as they are (strings
are copied though).
Arrays are represented as Vim |List| type.
Hashes are represented as Vim |Dictionary| type.
Other objects are represented as strings resulted from their
"Object#to_s" method.
{only available when compiled with the |+ruby| feature}

screenattr({row}, {col}) *screenattr()*
Like |screenchar()|, but return the attribute. This is a rather
arbitrary number that can only be used to compare to the
@@ -11,7 +11,8 @@ The Ruby Interface to Vim *ruby* *Ruby*
3. Vim::Buffer objects |ruby-buffer|
4. Vim::Window objects |ruby-window|
5. Global variables |ruby-globals|
6. Dynamic loading |ruby-dynamic|
6. rubyeval() Vim function |ruby-rubyeval|
7. Dynamic loading |ruby-dynamic|

{Vi does not have any of these commands}
*E266* *E267* *E268* *E269* *E270* *E271* *E272* *E273*
@@ -198,7 +199,16 @@ $curwin The current window object.
$curbuf The current buffer object.

6. Dynamic loading *ruby-dynamic*
6. rubyeval() Vim function *ruby-rubyeval*

To facilitate bi-directional interface, you can use |rubyeval()| function to
evaluate Ruby expressions and pass their values to Vim script.

The Ruby value "true", "false" and "nil" are converted to v:true, v:false and
v:null, respectively.

7. Dynamic loading *ruby-dynamic*

On MS-Windows and Unix the Ruby library can be loaded dynamically. The
|:version| output then includes |+ruby/dyn|.
@@ -338,6 +338,9 @@ static void f_reverse(typval_T *argvars, typval_T *rettv);
static void f_round(typval_T *argvars, typval_T *rettv);
#ifdef FEAT_RUBY
static void f_rubyeval(typval_T *argvars, typval_T *rettv);
static void f_screenattr(typval_T *argvars, typval_T *rettv);
static void f_screenchar(typval_T *argvars, typval_T *rettv);
static void f_screencol(typval_T *argvars, typval_T *rettv);
@@ -828,6 +831,9 @@ static struct fst
{"reverse", 1, 1, f_reverse},
{"round", 1, 1, f_round},
#ifdef FEAT_RUBY
{"rubyeval", 1, 1, f_rubyeval},
{"screenattr", 2, 2, f_screenattr},
{"screenchar", 2, 2, f_screenchar},
@@ -10351,6 +10357,21 @@ f_round(typval_T *argvars, typval_T *rettv)

#ifdef FEAT_RUBY
* "rubyeval()" function
static void
f_rubyeval(typval_T *argvars, typval_T *rettv)
char_u *str;
char_u buf[NUMBUFLEN];

str = tv_get_string_buf(&argvars[0], buf);
do_rubyeval(str, rettv);

* "screenattr()" function

0 comments on commit e99be0e

Please sign in to comment.
You can’t perform that action at this time.