Skip to content

Commit e99be0e

Browse files
committed
patch 8.1.1056: no eval function for Ruby
Problem: No eval function for Ruby. Solution: Add rubyeval(). (Ozaki Kiichi, closes #4152)
1 parent 75bf3d2 commit e99be0e

File tree

7 files changed

+432
-184
lines changed

7 files changed

+432
-184
lines changed

runtime/doc/eval.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,6 +2521,7 @@ repeat({expr}, {count}) String repeat {expr} {count} times
25212521
resolve({filename}) String get filename a shortcut points to
25222522
reverse({list}) List reverse {list} in-place
25232523
round({expr}) Float round off {expr}
2524+
rubyeval({expr}) any evaluate |Ruby| expression
25242525
screenattr({row}, {col}) Number attribute at screen position
25252526
screenchar({row}, {col}) Number character at screen position
25262527
screencol() Number current cursor column
@@ -7432,6 +7433,17 @@ round({expr}) *round()*
74327433
< -5.0
74337434
{only available when compiled with the |+float| feature}
74347435

7436+
rubyeval({expr}) *rubyeval()*
7437+
Evaluate Ruby expression {expr} and return its result
7438+
converted to Vim data structures.
7439+
Numbers, floats and strings are returned as they are (strings
7440+
are copied though).
7441+
Arrays are represented as Vim |List| type.
7442+
Hashes are represented as Vim |Dictionary| type.
7443+
Other objects are represented as strings resulted from their
7444+
"Object#to_s" method.
7445+
{only available when compiled with the |+ruby| feature}
7446+
74357447
screenattr({row}, {col}) *screenattr()*
74367448
Like |screenchar()|, but return the attribute. This is a rather
74377449
arbitrary number that can only be used to compare to the

runtime/doc/if_ruby.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ The Ruby Interface to Vim *ruby* *Ruby*
1111
3. Vim::Buffer objects |ruby-buffer|
1212
4. Vim::Window objects |ruby-window|
1313
5. Global variables |ruby-globals|
14-
6. Dynamic loading |ruby-dynamic|
14+
6. rubyeval() Vim function |ruby-rubyeval|
15+
7. Dynamic loading |ruby-dynamic|
1516

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

200201
==============================================================================
201-
6. Dynamic loading *ruby-dynamic*
202+
6. rubyeval() Vim function *ruby-rubyeval*
203+
204+
To facilitate bi-directional interface, you can use |rubyeval()| function to
205+
evaluate Ruby expressions and pass their values to Vim script.
206+
207+
The Ruby value "true", "false" and "nil" are converted to v:true, v:false and
208+
v:null, respectively.
209+
210+
==============================================================================
211+
7. Dynamic loading *ruby-dynamic*
202212

203213
On MS-Windows and Unix the Ruby library can be loaded dynamically. The
204214
|:version| output then includes |+ruby/dyn|.

src/evalfunc.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ static void f_reverse(typval_T *argvars, typval_T *rettv);
338338
#ifdef FEAT_FLOAT
339339
static void f_round(typval_T *argvars, typval_T *rettv);
340340
#endif
341+
#ifdef FEAT_RUBY
342+
static void f_rubyeval(typval_T *argvars, typval_T *rettv);
343+
#endif
341344
static void f_screenattr(typval_T *argvars, typval_T *rettv);
342345
static void f_screenchar(typval_T *argvars, typval_T *rettv);
343346
static void f_screencol(typval_T *argvars, typval_T *rettv);
@@ -828,6 +831,9 @@ static struct fst
828831
{"reverse", 1, 1, f_reverse},
829832
#ifdef FEAT_FLOAT
830833
{"round", 1, 1, f_round},
834+
#endif
835+
#ifdef FEAT_RUBY
836+
{"rubyeval", 1, 1, f_rubyeval},
831837
#endif
832838
{"screenattr", 2, 2, f_screenattr},
833839
{"screenchar", 2, 2, f_screenchar},
@@ -10351,6 +10357,21 @@ f_round(typval_T *argvars, typval_T *rettv)
1035110357
}
1035210358
#endif
1035310359

10360+
#ifdef FEAT_RUBY
10361+
/*
10362+
* "rubyeval()" function
10363+
*/
10364+
static void
10365+
f_rubyeval(typval_T *argvars, typval_T *rettv)
10366+
{
10367+
char_u *str;
10368+
char_u buf[NUMBUFLEN];
10369+
10370+
str = tv_get_string_buf(&argvars[0], buf);
10371+
do_rubyeval(str, rettv);
10372+
}
10373+
#endif
10374+
1035410375
/*
1035510376
* "screenattr()" function
1035610377
*/

0 commit comments

Comments
 (0)