Mercurial > vim
annotate src/if_ruby.c @ 14389:424ccd85d5c6 v8.1.0209
patch 8.1.0209: stderr output from Ruby messes up display
commit https://github.com/vim/vim/commit/b6c8cd8dc3fbbe9da1180ce1b75f2252df2c1318
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jul 24 05:41:30 2018 +0200
patch 8.1.0209: stderr output from Ruby messes up display
Problem: Stderr output from Ruby messes up display.
Solution: Turn the stderr output into a Vim message. (Masataka Pocke
Kuwabara, closes #3238)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 24 Jul 2018 05:45:05 +0200 |
parents | fbd4f9645b57 |
children | c15bef307de6 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
779 | 4 * |
5 * Ruby interface by Shugo Maeda | |
6 * with improvements by SegPhault (Ryan Paul) | |
2589 | 7 * with improvements by Jon Maken |
7 | 8 * |
9 * Do ":help uganda" in Vim to read copying and usage conditions. | |
10 * Do ":help credits" in Vim to see a list of people who contributed. | |
11 * See README.txt for an overview of the Vim source code. | |
12 */ | |
13 | |
2624 | 14 #ifdef HAVE_CONFIG_H |
15 # include "auto/config.h" | |
16 #endif | |
2621 | 17 |
2683 | 18 #include <stdio.h> |
19 #include <string.h> | |
20 | |
7 | 21 #ifdef _WIN32 |
22 # if !defined(DYNAMIC_RUBY_VER) || (DYNAMIC_RUBY_VER < 18) | |
23 # define NT | |
24 # endif | |
25 # ifndef DYNAMIC_RUBY | |
26 # define IMPORT /* For static dll usage __declspec(dllimport) */ | |
27 # define RUBYEXTERN __declspec(dllimport) | |
28 # endif | |
29 #endif | |
30 #ifndef RUBYEXTERN | |
31 # define RUBYEXTERN extern | |
32 #endif | |
33 | |
9293
946b62bbd871
commit https://github.com/vim/vim/commit/2016ae586b12513d973aabc30ed758b543114cbe
Christian Brabandt <cb@256bit.org>
parents:
9278
diff
changeset
|
34 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 24 |
946b62bbd871
commit https://github.com/vim/vim/commit/2016ae586b12513d973aabc30ed758b543114cbe
Christian Brabandt <cb@256bit.org>
parents:
9278
diff
changeset
|
35 # define USE_RUBY_INTEGER |
9278
97b0b568f820
commit https://github.com/vim/vim/commit/06469e979fe524ac6cb8f705ed4221aa267de11d
Christian Brabandt <cb@256bit.org>
parents:
9159
diff
changeset
|
36 #endif |
97b0b568f820
commit https://github.com/vim/vim/commit/06469e979fe524ac6cb8f705ed4221aa267de11d
Christian Brabandt <cb@256bit.org>
parents:
9159
diff
changeset
|
37 |
2589 | 38 #ifdef DYNAMIC_RUBY |
7 | 39 /* |
40 * This is tricky. In ruby.h there is (inline) function rb_class_of() | |
41 * definition. This function use these variables. But we want function to | |
42 * use dll_* variables. | |
43 */ | |
44 # define rb_cFalseClass (*dll_rb_cFalseClass) | |
45 # define rb_cFixnum (*dll_rb_cFixnum) | |
9293
946b62bbd871
commit https://github.com/vim/vim/commit/2016ae586b12513d973aabc30ed758b543114cbe
Christian Brabandt <cb@256bit.org>
parents:
9278
diff
changeset
|
46 # if defined(USE_RUBY_INTEGER) |
946b62bbd871
commit https://github.com/vim/vim/commit/2016ae586b12513d973aabc30ed758b543114cbe
Christian Brabandt <cb@256bit.org>
parents:
9278
diff
changeset
|
47 # define rb_cInteger (*dll_rb_cInteger) |
9278
97b0b568f820
commit https://github.com/vim/vim/commit/06469e979fe524ac6cb8f705ed4221aa267de11d
Christian Brabandt <cb@256bit.org>
parents:
9159
diff
changeset
|
48 # endif |
4193 | 49 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20 |
50 # define rb_cFloat (*dll_rb_cFloat) | |
51 # endif | |
7 | 52 # define rb_cNilClass (*dll_rb_cNilClass) |
53 # define rb_cSymbol (*dll_rb_cSymbol) | |
54 # define rb_cTrueClass (*dll_rb_cTrueClass) | |
55 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 | |
56 /* | |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
57 * On ver 1.8, all Ruby functions are exported with "__declspec(dllimport)" |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
58 * in ruby.h. But it causes trouble for these variables, because it is |
7 | 59 * defined in this file. When defined this RUBY_EXPORT it modified to |
60 * "extern" and be able to avoid this problem. | |
61 */ | |
62 # define RUBY_EXPORT | |
63 # endif | |
2589 | 64 |
2624 | 65 #if !(defined(WIN32) || defined(_WIN64)) |
2589 | 66 # include <dlfcn.h> |
2621 | 67 # define HINSTANCE void* |
68 # define RUBY_PROC void* | |
2589 | 69 # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL) |
70 # define symbol_from_dll dlsym | |
71 # define close_dll dlclose | |
72 #else | |
2621 | 73 # define RUBY_PROC FARPROC |
2612 | 74 # define load_dll vimLoadLib |
2589 | 75 # define symbol_from_dll GetProcAddress |
76 # define close_dll FreeLibrary | |
7 | 77 #endif |
78 | |
2589 | 79 #endif /* ifdef DYNAMIC_RUBY */ |
80 | |
2076
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
81 /* suggested by Ariya Mizutani */ |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
82 #if (_MSC_VER == 1200) |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
83 # undef _WIN32_WINNT |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
84 #endif |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
85 |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
86 #if (defined(RUBY_VERSION) && RUBY_VERSION >= 19) \ |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
87 || (defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19) |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
88 # define RUBY19_OR_LATER 1 |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
89 #endif |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
90 |
7364
fe2f6b92d806
commit https://github.com/vim/vim/commit/0d27f64f7188efef99062a3c5694027c12401670
Christian Brabandt <cb@256bit.org>
parents:
7360
diff
changeset
|
91 #if (defined(RUBY_VERSION) && RUBY_VERSION >= 20) \ |
fe2f6b92d806
commit https://github.com/vim/vim/commit/0d27f64f7188efef99062a3c5694027c12401670
Christian Brabandt <cb@256bit.org>
parents:
7360
diff
changeset
|
92 || (defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20) |
fe2f6b92d806
commit https://github.com/vim/vim/commit/0d27f64f7188efef99062a3c5694027c12401670
Christian Brabandt <cb@256bit.org>
parents:
7360
diff
changeset
|
93 # define RUBY20_OR_LATER 1 |
fe2f6b92d806
commit https://github.com/vim/vim/commit/0d27f64f7188efef99062a3c5694027c12401670
Christian Brabandt <cb@256bit.org>
parents:
7360
diff
changeset
|
94 #endif |
fe2f6b92d806
commit https://github.com/vim/vim/commit/0d27f64f7188efef99062a3c5694027c12401670
Christian Brabandt <cb@256bit.org>
parents:
7360
diff
changeset
|
95 |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
96 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19 |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
97 /* Ruby 1.9 defines a number of static functions which use rb_num2long and |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
98 * rb_int2big */ |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
99 # define rb_num2long rb_num2long_stub |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
100 # define rb_int2big rb_int2big_stub |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
101 #endif |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
102 |
5766 | 103 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19 \ |
104 && VIM_SIZEOF_INT < VIM_SIZEOF_LONG | |
105 /* Ruby 1.9 defines a number of static functions which use rb_fix2int and | |
5684 | 106 * rb_num2int if VIM_SIZEOF_INT < VIM_SIZEOF_LONG (64bit) */ |
4279 | 107 # define rb_fix2int rb_fix2int_stub |
108 # define rb_num2int rb_num2int_stub | |
109 #endif | |
110 | |
6485 | 111 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER == 21 |
5643 | 112 /* Ruby 2.1 adds new GC called RGenGC and RARRAY_PTR uses |
113 * rb_gc_writebarrier_unprotect_promoted if USE_RGENGC */ | |
6406 | 114 # define rb_gc_writebarrier_unprotect_promoted rb_gc_writebarrier_unprotect_promoted_stub |
115 #endif | |
6485 | 116 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 22 |
117 # define rb_gc_writebarrier_unprotect rb_gc_writebarrier_unprotect_stub | |
118 #endif | |
5643 | 119 |
7 | 120 #include <ruby.h> |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
121 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
122 # include <ruby/encoding.h> |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
123 #endif |
7 | 124 |
2669 | 125 #undef off_t /* ruby defines off_t as _int64, Mingw uses long */ |
7 | 126 #undef EXTERN |
127 #undef _ | |
128 | |
129 /* T_DATA defined both by Ruby and Mac header files, hack around it... */ | |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12553
diff
changeset
|
130 #if defined(MACOS_X) |
7 | 131 # define __OPENTRANSPORT__ |
132 # define __OPENTRANSPORTPROTOCOL__ | |
133 # define __OPENTRANSPORTPROVIDERS__ | |
134 #endif | |
135 | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
136 /* |
7364
fe2f6b92d806
commit https://github.com/vim/vim/commit/0d27f64f7188efef99062a3c5694027c12401670
Christian Brabandt <cb@256bit.org>
parents:
7360
diff
changeset
|
137 * The TypedData_XXX macro family can be used since Ruby 1.9.2 but |
fe2f6b92d806
commit https://github.com/vim/vim/commit/0d27f64f7188efef99062a3c5694027c12401670
Christian Brabandt <cb@256bit.org>
parents:
7360
diff
changeset
|
138 * rb_data_type_t changed in 1.9.3, therefore require at least 2.0. |
fe2f6b92d806
commit https://github.com/vim/vim/commit/0d27f64f7188efef99062a3c5694027c12401670
Christian Brabandt <cb@256bit.org>
parents:
7360
diff
changeset
|
139 * The old Data_XXX macro family was deprecated on Ruby 2.2. |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
140 * Use TypedData_XXX if available. |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
141 */ |
7364
fe2f6b92d806
commit https://github.com/vim/vim/commit/0d27f64f7188efef99062a3c5694027c12401670
Christian Brabandt <cb@256bit.org>
parents:
7360
diff
changeset
|
142 #if defined(TypedData_Wrap_Struct) && defined(RUBY20_OR_LATER) |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
143 # define USE_TYPEDDATA 1 |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
144 #endif |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
145 |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
146 /* |
4352 | 147 * Backward compatibility for Ruby 1.8 and earlier. |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
148 * Ruby 1.9 does not provide STR2CSTR, instead StringValuePtr is provided. |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
149 * Ruby 1.9 does not provide RXXX(s)->len and RXXX(s)->ptr, instead |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
150 * RXXX_LEN(s) and RXXX_PTR(s) are provided. |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
151 */ |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
152 #ifndef StringValuePtr |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
153 # define StringValuePtr(s) STR2CSTR(s) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
154 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
155 #ifndef RARRAY_LEN |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
156 # define RARRAY_LEN(s) RARRAY(s)->len |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
157 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
158 #ifndef RARRAY_PTR |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
159 # define RARRAY_PTR(s) RARRAY(s)->ptr |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
160 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
161 #ifndef RSTRING_LEN |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
162 # define RSTRING_LEN(s) RSTRING(s)->len |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
163 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
164 #ifndef RSTRING_PTR |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
165 # define RSTRING_PTR(s) RSTRING(s)->ptr |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
166 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
167 |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
168 #ifdef HAVE_DUP |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
169 # undef HAVE_DUP |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
170 #endif |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
171 |
7 | 172 #include "vim.h" |
173 #include "version.h" | |
174 | |
175 #if defined(PROTO) && !defined(FEAT_RUBY) | |
176 /* Define these to be able to generate the function prototypes. */ | |
177 # define VALUE int | |
178 # define RUBY_DATA_FUNC int | |
179 #endif | |
180 | |
181 static int ruby_initialized = 0; | |
4369 | 182 static void *ruby_stack_start; |
7 | 183 static VALUE objtbl; |
184 | |
185 static VALUE mVIM; | |
186 static VALUE cBuffer; | |
187 static VALUE cVimWindow; | |
188 static VALUE eDeletedBufferError; | |
189 static VALUE eDeletedWindowError; | |
190 | |
191 static int ensure_ruby_initialized(void); | |
192 static void error_print(int); | |
193 static void ruby_io_init(void); | |
194 static void ruby_vim_init(void); | |
195 | |
4452 | 196 #if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK) |
197 # if defined(__ia64) && !defined(ruby_init_stack) | |
198 # define ruby_init_stack(addr) ruby_init_stack((addr), rb_ia64_bsp()) | |
199 # endif | |
4375 | 200 #endif |
201 | |
7 | 202 #if defined(DYNAMIC_RUBY) || defined(PROTO) |
7668
21b0a39d13ed
commit https://github.com/vim/vim/commit/ef26954a35207c3f17d6ed35d9a40c918d974892
Christian Brabandt <cb@256bit.org>
parents:
7528
diff
changeset
|
203 # if defined(PROTO) && !defined(HINSTANCE) |
4375 | 204 # define HINSTANCE int /* for generating prototypes */ |
205 # endif | |
7 | 206 |
207 /* | |
208 * Wrapper defines | |
209 */ | |
4375 | 210 # define rb_assoc_new dll_rb_assoc_new |
211 # define rb_cObject (*dll_rb_cObject) | |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
212 # define rb_check_type dll_rb_check_type |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
213 # ifdef USE_TYPEDDATA |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
214 # define rb_check_typeddata dll_rb_check_typeddata |
6485 | 215 # endif |
4375 | 216 # define rb_class_path dll_rb_class_path |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
217 # ifdef USE_TYPEDDATA |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
218 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 23 |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
219 # define rb_data_typed_object_wrap dll_rb_data_typed_object_wrap |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
220 # else |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
221 # define rb_data_typed_object_alloc dll_rb_data_typed_object_alloc |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
222 # endif |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
223 # else |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
224 # define rb_data_object_alloc dll_rb_data_object_alloc |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
225 # endif |
4375 | 226 # define rb_define_class_under dll_rb_define_class_under |
227 # define rb_define_const dll_rb_define_const | |
228 # define rb_define_global_function dll_rb_define_global_function | |
229 # define rb_define_method dll_rb_define_method | |
230 # define rb_define_module dll_rb_define_module | |
231 # define rb_define_module_function dll_rb_define_module_function | |
232 # define rb_define_singleton_method dll_rb_define_singleton_method | |
233 # define rb_define_virtual_variable dll_rb_define_virtual_variable | |
234 # define rb_stdout (*dll_rb_stdout) | |
14389
424ccd85d5c6
patch 8.1.0209: stderr output from Ruby messes up display
Christian Brabandt <cb@256bit.org>
parents:
13958
diff
changeset
|
235 # define rb_stderr (*dll_rb_stderr) |
4375 | 236 # define rb_eArgError (*dll_rb_eArgError) |
237 # define rb_eIndexError (*dll_rb_eIndexError) | |
238 # define rb_eRuntimeError (*dll_rb_eRuntimeError) | |
239 # define rb_eStandardError (*dll_rb_eStandardError) | |
240 # define rb_eval_string_protect dll_rb_eval_string_protect | |
241 # define rb_global_variable dll_rb_global_variable | |
242 # define rb_hash_aset dll_rb_hash_aset | |
243 # define rb_hash_new dll_rb_hash_new | |
244 # define rb_inspect dll_rb_inspect | |
245 # define rb_int2inum dll_rb_int2inum | |
5684 | 246 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ |
5766 | 247 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER <= 18 |
248 # define rb_fix2int dll_rb_fix2int | |
249 # define rb_num2int dll_rb_num2int | |
250 # endif | |
4375 | 251 # define rb_num2uint dll_rb_num2uint |
252 # endif | |
253 # define rb_lastline_get dll_rb_lastline_get | |
254 # define rb_lastline_set dll_rb_lastline_set | |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12553
diff
changeset
|
255 # define rb_protect dll_rb_protect |
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12553
diff
changeset
|
256 # define rb_load dll_rb_load |
4375 | 257 # ifndef RUBY19_OR_LATER |
258 # define rb_num2long dll_rb_num2long | |
259 # endif | |
260 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER <= 19 | |
261 # define rb_num2ulong dll_rb_num2ulong | |
262 # endif | |
263 # define rb_obj_alloc dll_rb_obj_alloc | |
264 # define rb_obj_as_string dll_rb_obj_as_string | |
265 # define rb_obj_id dll_rb_obj_id | |
266 # define rb_raise dll_rb_raise | |
267 # define rb_str_cat dll_rb_str_cat | |
268 # define rb_str_concat dll_rb_str_concat | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
269 # undef rb_str_new |
4375 | 270 # define rb_str_new dll_rb_str_new |
271 # ifdef rb_str_new2 | |
2212
7d3cf4693a8f
Some versions of Ruby redefine rb_str_new2 to rb_str_new_cstr.
Bram Moolenaar <bram@vim.org>
parents:
2200
diff
changeset
|
272 /* Ruby may #define rb_str_new2 to use rb_str_new_cstr. */ |
4375 | 273 # define need_rb_str_new_cstr 1 |
2621 | 274 /* Ruby's headers #define rb_str_new_cstr to make use of GCC's |
275 * __builtin_constant_p extension. */ | |
4375 | 276 # undef rb_str_new_cstr |
277 # define rb_str_new_cstr dll_rb_str_new_cstr | |
4373 | 278 # else |
4375 | 279 # define rb_str_new2 dll_rb_str_new2 |
280 # endif | |
281 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 | |
282 # define rb_string_value dll_rb_string_value | |
283 # define rb_string_value_ptr dll_rb_string_value_ptr | |
284 # define rb_float_new dll_rb_float_new | |
285 # define rb_ary_new dll_rb_ary_new | |
286 # define rb_ary_push dll_rb_ary_push | |
4452 | 287 # if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK) |
288 # ifdef __ia64 | |
289 # define rb_ia64_bsp dll_rb_ia64_bsp | |
290 # undef ruby_init_stack | |
291 # define ruby_init_stack(addr) dll_ruby_init_stack((addr), rb_ia64_bsp()) | |
292 # else | |
293 # define ruby_init_stack dll_ruby_init_stack | |
294 # endif | |
4375 | 295 # endif |
296 # else | |
297 # define rb_str2cstr dll_rb_str2cstr | |
4373 | 298 # endif |
4375 | 299 # ifdef RUBY19_OR_LATER |
300 # define rb_errinfo dll_rb_errinfo | |
301 # else | |
302 # define ruby_errinfo (*dll_ruby_errinfo) | |
2621 | 303 # endif |
4375 | 304 # define ruby_init dll_ruby_init |
305 # define ruby_init_loadpath dll_ruby_init_loadpath | |
306 # ifdef WIN3264 | |
307 # define NtInitialize dll_NtInitialize | |
10603
df1abc85b169
patch 8.0.0191: can't build with Ruby on some systems
Christian Brabandt <cb@256bit.org>
parents:
10595
diff
changeset
|
308 # define ruby_sysinit dll_ruby_sysinit |
4375 | 309 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
310 # define rb_w32_snprintf dll_rb_w32_snprintf | |
311 # endif | |
312 # endif | |
7 | 313 |
4375 | 314 # ifdef RUBY19_OR_LATER |
315 # define ruby_script dll_ruby_script | |
316 # define rb_enc_find_index dll_rb_enc_find_index | |
317 # define rb_enc_find dll_rb_enc_find | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
318 # undef rb_enc_str_new |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
319 # define rb_enc_str_new dll_rb_enc_str_new |
4375 | 320 # define rb_sprintf dll_rb_sprintf |
321 # define rb_require dll_rb_require | |
7237
2a95fa0a07b5
commit https://github.com/vim/vim/commit/9b1067e038d371bd6c51e5da025383761f4921b4
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
322 # define ruby_options dll_ruby_options |
4375 | 323 # endif |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
324 |
7 | 325 /* |
326 * Pointers for dynamic link | |
327 */ | |
328 static VALUE (*dll_rb_assoc_new) (VALUE, VALUE); | |
2274
7c31d761ffa9
Fix build problem with Ruby on Windows. (Cesar Romani)
Bram Moolenaar <bram@vim.org>
parents:
2212
diff
changeset
|
329 VALUE *dll_rb_cFalseClass; |
7c31d761ffa9
Fix build problem with Ruby on Windows. (Cesar Romani)
Bram Moolenaar <bram@vim.org>
parents:
2212
diff
changeset
|
330 VALUE *dll_rb_cFixnum; |
9293
946b62bbd871
commit https://github.com/vim/vim/commit/2016ae586b12513d973aabc30ed758b543114cbe
Christian Brabandt <cb@256bit.org>
parents:
9278
diff
changeset
|
331 # if defined(USE_RUBY_INTEGER) |
9278
97b0b568f820
commit https://github.com/vim/vim/commit/06469e979fe524ac6cb8f705ed4221aa267de11d
Christian Brabandt <cb@256bit.org>
parents:
9159
diff
changeset
|
332 VALUE *dll_rb_cInteger; |
97b0b568f820
commit https://github.com/vim/vim/commit/06469e979fe524ac6cb8f705ed4221aa267de11d
Christian Brabandt <cb@256bit.org>
parents:
9159
diff
changeset
|
333 # endif |
4375 | 334 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20 |
4193 | 335 VALUE *dll_rb_cFloat; |
4375 | 336 # endif |
2274
7c31d761ffa9
Fix build problem with Ruby on Windows. (Cesar Romani)
Bram Moolenaar <bram@vim.org>
parents:
2212
diff
changeset
|
337 VALUE *dll_rb_cNilClass; |
7 | 338 static VALUE *dll_rb_cObject; |
2274
7c31d761ffa9
Fix build problem with Ruby on Windows. (Cesar Romani)
Bram Moolenaar <bram@vim.org>
parents:
2212
diff
changeset
|
339 VALUE *dll_rb_cSymbol; |
7c31d761ffa9
Fix build problem with Ruby on Windows. (Cesar Romani)
Bram Moolenaar <bram@vim.org>
parents:
2212
diff
changeset
|
340 VALUE *dll_rb_cTrueClass; |
7 | 341 static void (*dll_rb_check_type) (VALUE,int); |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
342 # ifdef USE_TYPEDDATA |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
343 static void *(*dll_rb_check_typeddata) (VALUE,const rb_data_type_t *); |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
344 # endif |
7 | 345 static VALUE (*dll_rb_class_path) (VALUE); |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
346 # ifdef USE_TYPEDDATA |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
347 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 23 |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
348 static VALUE (*dll_rb_data_typed_object_wrap) (VALUE, void*, const rb_data_type_t *); |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
349 # else |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
350 static VALUE (*dll_rb_data_typed_object_alloc) (VALUE, void*, const rb_data_type_t *); |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
351 # endif |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
352 # else |
7 | 353 static VALUE (*dll_rb_data_object_alloc) (VALUE, void*, RUBY_DATA_FUNC, RUBY_DATA_FUNC); |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
354 # endif |
7 | 355 static VALUE (*dll_rb_define_class_under) (VALUE, const char*, VALUE); |
356 static void (*dll_rb_define_const) (VALUE,const char*,VALUE); | |
357 static void (*dll_rb_define_global_function) (const char*,VALUE(*)(),int); | |
358 static void (*dll_rb_define_method) (VALUE,const char*,VALUE(*)(),int); | |
359 static VALUE (*dll_rb_define_module) (const char*); | |
360 static void (*dll_rb_define_module_function) (VALUE,const char*,VALUE(*)(),int); | |
361 static void (*dll_rb_define_singleton_method) (VALUE,const char*,VALUE(*)(),int); | |
362 static void (*dll_rb_define_virtual_variable) (const char*,VALUE(*)(),void(*)()); | |
363 static VALUE *dll_rb_stdout; | |
14389
424ccd85d5c6
patch 8.1.0209: stderr output from Ruby messes up display
Christian Brabandt <cb@256bit.org>
parents:
13958
diff
changeset
|
364 static VALUE *dll_rb_stderr; |
7 | 365 static VALUE *dll_rb_eArgError; |
366 static VALUE *dll_rb_eIndexError; | |
367 static VALUE *dll_rb_eRuntimeError; | |
368 static VALUE *dll_rb_eStandardError; | |
369 static VALUE (*dll_rb_eval_string_protect) (const char*, int*); | |
370 static void (*dll_rb_global_variable) (VALUE*); | |
371 static VALUE (*dll_rb_hash_aset) (VALUE, VALUE, VALUE); | |
372 static VALUE (*dll_rb_hash_new) (void); | |
373 static VALUE (*dll_rb_inspect) (VALUE); | |
374 static VALUE (*dll_rb_int2inum) (long); | |
5684 | 375 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ |
3808 | 376 static long (*dll_rb_fix2int) (VALUE); |
377 static long (*dll_rb_num2int) (VALUE); | |
378 static unsigned long (*dll_rb_num2uint) (VALUE); | |
4375 | 379 # endif |
7 | 380 static VALUE (*dll_rb_lastline_get) (void); |
381 static void (*dll_rb_lastline_set) (VALUE); | |
13148
f06a0a75d5b1
patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
382 static VALUE (*dll_rb_protect) (VALUE (*)(VALUE), VALUE, int*); |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12553
diff
changeset
|
383 static void (*dll_rb_load) (VALUE, int); |
7 | 384 static long (*dll_rb_num2long) (VALUE); |
385 static unsigned long (*dll_rb_num2ulong) (VALUE); | |
386 static VALUE (*dll_rb_obj_alloc) (VALUE); | |
387 static VALUE (*dll_rb_obj_as_string) (VALUE); | |
388 static VALUE (*dll_rb_obj_id) (VALUE); | |
389 static void (*dll_rb_raise) (VALUE, const char*, ...); | |
4375 | 390 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
2589 | 391 static VALUE (*dll_rb_string_value) (volatile VALUE*); |
4375 | 392 # else |
7 | 393 static char *(*dll_rb_str2cstr) (VALUE,int*); |
4375 | 394 # endif |
7 | 395 static VALUE (*dll_rb_str_cat) (VALUE, const char*, long); |
396 static VALUE (*dll_rb_str_concat) (VALUE, VALUE); | |
397 static VALUE (*dll_rb_str_new) (const char*, long); | |
4375 | 398 # ifdef need_rb_str_new_cstr |
2212
7d3cf4693a8f
Some versions of Ruby redefine rb_str_new2 to rb_str_new_cstr.
Bram Moolenaar <bram@vim.org>
parents:
2200
diff
changeset
|
399 /* Ruby may #define rb_str_new2 to use rb_str_new_cstr. */ |
7d3cf4693a8f
Some versions of Ruby redefine rb_str_new2 to rb_str_new_cstr.
Bram Moolenaar <bram@vim.org>
parents:
2200
diff
changeset
|
400 static VALUE (*dll_rb_str_new_cstr) (const char*); |
4375 | 401 # else |
7 | 402 static VALUE (*dll_rb_str_new2) (const char*); |
4375 | 403 # endif |
404 # ifdef RUBY19_OR_LATER | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
405 static VALUE (*dll_rb_errinfo) (void); |
4375 | 406 # else |
7 | 407 static VALUE *dll_ruby_errinfo; |
4375 | 408 # endif |
7 | 409 static void (*dll_ruby_init) (void); |
410 static void (*dll_ruby_init_loadpath) (void); | |
4375 | 411 # ifdef WIN3264 |
2076
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
412 static void (*dll_NtInitialize) (int*, char***); |
10603
df1abc85b169
patch 8.0.0191: can't build with Ruby on some systems
Christian Brabandt <cb@256bit.org>
parents:
10595
diff
changeset
|
413 static void (*dll_ruby_sysinit) (int*, char***); |
4375 | 414 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
2621 | 415 static int (*dll_rb_w32_snprintf)(char*, size_t, const char*, ...); |
4375 | 416 # endif |
2621 | 417 # endif |
4375 | 418 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
419 static char * (*dll_rb_string_value_ptr) (volatile VALUE*); |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
420 static VALUE (*dll_rb_float_new) (double); |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
421 static VALUE (*dll_rb_ary_new) (void); |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
422 static VALUE (*dll_rb_ary_push) (VALUE, VALUE); |
4452 | 423 # if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK) |
424 # ifdef __ia64 | |
4373 | 425 static void * (*dll_rb_ia64_bsp) (void); |
426 static void (*dll_ruby_init_stack)(VALUE*, void*); | |
4452 | 427 # else |
4373 | 428 static void (*dll_ruby_init_stack)(VALUE*); |
4452 | 429 # endif |
4375 | 430 # endif |
4373 | 431 # endif |
4375 | 432 # ifdef RUBY19_OR_LATER |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
433 static VALUE (*dll_rb_int2big)(SIGNED_VALUE); |
4375 | 434 # endif |
7 | 435 |
4375 | 436 # ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
437 static void (*dll_ruby_script) (const char*); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
438 static int (*dll_rb_enc_find_index) (const char*); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
439 static rb_encoding* (*dll_rb_enc_find) (const char*); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
440 static VALUE (*dll_rb_enc_str_new) (const char*, long, rb_encoding*); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
441 static VALUE (*dll_rb_sprintf) (const char*, ...); |
2669 | 442 static VALUE (*dll_rb_require) (const char*); |
7237
2a95fa0a07b5
commit https://github.com/vim/vim/commit/9b1067e038d371bd6c51e5da025383761f4921b4
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
443 static void* (*ruby_options)(int, char**); |
4375 | 444 # endif |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
445 |
5643 | 446 # if defined(USE_RGENGC) && USE_RGENGC |
6485 | 447 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER == 21 |
5643 | 448 static void (*dll_rb_gc_writebarrier_unprotect_promoted)(VALUE); |
6485 | 449 # else |
450 static void (*dll_rb_gc_writebarrier_unprotect)(VALUE obj); | |
451 # endif | |
5643 | 452 # endif |
453 | |
4375 | 454 # if defined(RUBY19_OR_LATER) && !defined(PROTO) |
6767 | 455 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 22 |
456 long rb_num2long_stub(VALUE x) | |
457 # else | |
3947 | 458 SIGNED_VALUE rb_num2long_stub(VALUE x) |
6767 | 459 # endif |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
460 { |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
461 return dll_rb_num2long(x); |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
462 } |
3947 | 463 VALUE rb_int2big_stub(SIGNED_VALUE x) |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
464 { |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
465 return dll_rb_int2big(x); |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
466 } |
5766 | 467 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19 \ |
468 && VIM_SIZEOF_INT < VIM_SIZEOF_LONG | |
4279 | 469 long rb_fix2int_stub(VALUE x) |
470 { | |
471 return dll_rb_fix2int(x); | |
472 } | |
473 long rb_num2int_stub(VALUE x) | |
474 { | |
475 return dll_rb_num2int(x); | |
476 } | |
4375 | 477 # endif |
478 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20 | |
4164 | 479 VALUE |
480 rb_float_new_in_heap(double d) | |
481 { | |
482 return dll_rb_float_new(d); | |
483 } | |
6767 | 484 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 22 |
485 unsigned long rb_num2ulong(VALUE x) | |
486 # else | |
4193 | 487 VALUE rb_num2ulong(VALUE x) |
6767 | 488 # endif |
4164 | 489 { |
490 return (long)RSHIFT((SIGNED_VALUE)(x),1); | |
491 } | |
4375 | 492 # endif |
493 # endif | |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
494 |
6357 | 495 /* Do not generate a prototype here, VALUE isn't always defined. */ |
496 # if defined(USE_RGENGC) && USE_RGENGC && !defined(PROTO) | |
6485 | 497 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER == 21 |
5643 | 498 void rb_gc_writebarrier_unprotect_promoted_stub(VALUE obj) |
499 { | |
6406 | 500 dll_rb_gc_writebarrier_unprotect_promoted(obj); |
5643 | 501 } |
6485 | 502 # else |
503 void rb_gc_writebarrier_unprotect_stub(VALUE obj) | |
504 { | |
505 dll_rb_gc_writebarrier_unprotect(obj); | |
506 } | |
507 # endif | |
508 # endif | |
509 | |
2621 | 510 static HINSTANCE hinstRuby = NULL; /* Instance of ruby.dll */ |
7 | 511 |
512 /* | |
501 | 513 * Table of name to function pointer of ruby. |
7 | 514 */ |
515 static struct | |
516 { | |
517 char *name; | |
518 RUBY_PROC *ptr; | |
519 } ruby_funcname_table[] = | |
520 { | |
521 {"rb_assoc_new", (RUBY_PROC*)&dll_rb_assoc_new}, | |
522 {"rb_cFalseClass", (RUBY_PROC*)&dll_rb_cFalseClass}, | |
9293
946b62bbd871
commit https://github.com/vim/vim/commit/2016ae586b12513d973aabc30ed758b543114cbe
Christian Brabandt <cb@256bit.org>
parents:
9278
diff
changeset
|
523 # if defined(USE_RUBY_INTEGER) |
9278
97b0b568f820
commit https://github.com/vim/vim/commit/06469e979fe524ac6cb8f705ed4221aa267de11d
Christian Brabandt <cb@256bit.org>
parents:
9159
diff
changeset
|
524 {"rb_cInteger", (RUBY_PROC*)&dll_rb_cInteger}, |
10546
7babc70a7b98
patch 8.0.0163: cannot build with Ruby 2.4
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
525 # else |
7babc70a7b98
patch 8.0.0163: cannot build with Ruby 2.4
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
526 {"rb_cFixnum", (RUBY_PROC*)&dll_rb_cFixnum}, |
9278
97b0b568f820
commit https://github.com/vim/vim/commit/06469e979fe524ac6cb8f705ed4221aa267de11d
Christian Brabandt <cb@256bit.org>
parents:
9159
diff
changeset
|
527 # endif |
4375 | 528 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20 |
4193 | 529 {"rb_cFloat", (RUBY_PROC*)&dll_rb_cFloat}, |
4375 | 530 # endif |
7 | 531 {"rb_cNilClass", (RUBY_PROC*)&dll_rb_cNilClass}, |
532 {"rb_cObject", (RUBY_PROC*)&dll_rb_cObject}, | |
533 {"rb_cSymbol", (RUBY_PROC*)&dll_rb_cSymbol}, | |
534 {"rb_cTrueClass", (RUBY_PROC*)&dll_rb_cTrueClass}, | |
535 {"rb_check_type", (RUBY_PROC*)&dll_rb_check_type}, | |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
536 # ifdef USE_TYPEDDATA |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
537 {"rb_check_typeddata", (RUBY_PROC*)&dll_rb_check_typeddata}, |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
538 # endif |
7 | 539 {"rb_class_path", (RUBY_PROC*)&dll_rb_class_path}, |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
540 # ifdef USE_TYPEDDATA |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
541 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 23 |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
542 {"rb_data_typed_object_wrap", (RUBY_PROC*)&dll_rb_data_typed_object_wrap}, |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
543 # else |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
544 {"rb_data_typed_object_alloc", (RUBY_PROC*)&dll_rb_data_typed_object_alloc}, |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
545 # endif |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
546 # else |
7 | 547 {"rb_data_object_alloc", (RUBY_PROC*)&dll_rb_data_object_alloc}, |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
548 # endif |
7 | 549 {"rb_define_class_under", (RUBY_PROC*)&dll_rb_define_class_under}, |
550 {"rb_define_const", (RUBY_PROC*)&dll_rb_define_const}, | |
551 {"rb_define_global_function", (RUBY_PROC*)&dll_rb_define_global_function}, | |
552 {"rb_define_method", (RUBY_PROC*)&dll_rb_define_method}, | |
553 {"rb_define_module", (RUBY_PROC*)&dll_rb_define_module}, | |
554 {"rb_define_module_function", (RUBY_PROC*)&dll_rb_define_module_function}, | |
555 {"rb_define_singleton_method", (RUBY_PROC*)&dll_rb_define_singleton_method}, | |
556 {"rb_define_virtual_variable", (RUBY_PROC*)&dll_rb_define_virtual_variable}, | |
557 {"rb_stdout", (RUBY_PROC*)&dll_rb_stdout}, | |
14389
424ccd85d5c6
patch 8.1.0209: stderr output from Ruby messes up display
Christian Brabandt <cb@256bit.org>
parents:
13958
diff
changeset
|
558 {"rb_stderr", (RUBY_PROC*)&dll_rb_stderr}, |
7 | 559 {"rb_eArgError", (RUBY_PROC*)&dll_rb_eArgError}, |
560 {"rb_eIndexError", (RUBY_PROC*)&dll_rb_eIndexError}, | |
561 {"rb_eRuntimeError", (RUBY_PROC*)&dll_rb_eRuntimeError}, | |
562 {"rb_eStandardError", (RUBY_PROC*)&dll_rb_eStandardError}, | |
563 {"rb_eval_string_protect", (RUBY_PROC*)&dll_rb_eval_string_protect}, | |
564 {"rb_global_variable", (RUBY_PROC*)&dll_rb_global_variable}, | |
565 {"rb_hash_aset", (RUBY_PROC*)&dll_rb_hash_aset}, | |
566 {"rb_hash_new", (RUBY_PROC*)&dll_rb_hash_new}, | |
567 {"rb_inspect", (RUBY_PROC*)&dll_rb_inspect}, | |
568 {"rb_int2inum", (RUBY_PROC*)&dll_rb_int2inum}, | |
5684 | 569 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ |
3808 | 570 {"rb_fix2int", (RUBY_PROC*)&dll_rb_fix2int}, |
571 {"rb_num2int", (RUBY_PROC*)&dll_rb_num2int}, | |
572 {"rb_num2uint", (RUBY_PROC*)&dll_rb_num2uint}, | |
4375 | 573 # endif |
7 | 574 {"rb_lastline_get", (RUBY_PROC*)&dll_rb_lastline_get}, |
575 {"rb_lastline_set", (RUBY_PROC*)&dll_rb_lastline_set}, | |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12553
diff
changeset
|
576 {"rb_protect", (RUBY_PROC*)&dll_rb_protect}, |
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12553
diff
changeset
|
577 {"rb_load", (RUBY_PROC*)&dll_rb_load}, |
7 | 578 {"rb_num2long", (RUBY_PROC*)&dll_rb_num2long}, |
579 {"rb_num2ulong", (RUBY_PROC*)&dll_rb_num2ulong}, | |
580 {"rb_obj_alloc", (RUBY_PROC*)&dll_rb_obj_alloc}, | |
581 {"rb_obj_as_string", (RUBY_PROC*)&dll_rb_obj_as_string}, | |
582 {"rb_obj_id", (RUBY_PROC*)&dll_rb_obj_id}, | |
583 {"rb_raise", (RUBY_PROC*)&dll_rb_raise}, | |
4375 | 584 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
2589 | 585 {"rb_string_value", (RUBY_PROC*)&dll_rb_string_value}, |
4375 | 586 # else |
7 | 587 {"rb_str2cstr", (RUBY_PROC*)&dll_rb_str2cstr}, |
4375 | 588 # endif |
7 | 589 {"rb_str_cat", (RUBY_PROC*)&dll_rb_str_cat}, |
590 {"rb_str_concat", (RUBY_PROC*)&dll_rb_str_concat}, | |
591 {"rb_str_new", (RUBY_PROC*)&dll_rb_str_new}, | |
4375 | 592 # ifdef need_rb_str_new_cstr |
2212
7d3cf4693a8f
Some versions of Ruby redefine rb_str_new2 to rb_str_new_cstr.
Bram Moolenaar <bram@vim.org>
parents:
2200
diff
changeset
|
593 {"rb_str_new_cstr", (RUBY_PROC*)&dll_rb_str_new_cstr}, |
4375 | 594 # else |
7 | 595 {"rb_str_new2", (RUBY_PROC*)&dll_rb_str_new2}, |
4375 | 596 # endif |
597 # ifdef RUBY19_OR_LATER | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
598 {"rb_errinfo", (RUBY_PROC*)&dll_rb_errinfo}, |
4375 | 599 # else |
7 | 600 {"ruby_errinfo", (RUBY_PROC*)&dll_ruby_errinfo}, |
4375 | 601 # endif |
7 | 602 {"ruby_init", (RUBY_PROC*)&dll_ruby_init}, |
603 {"ruby_init_loadpath", (RUBY_PROC*)&dll_ruby_init_loadpath}, | |
4375 | 604 # ifdef WIN3264 |
605 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER < 19 | |
10603
df1abc85b169
patch 8.0.0191: can't build with Ruby on some systems
Christian Brabandt <cb@256bit.org>
parents:
10595
diff
changeset
|
606 {"NtInitialize", (RUBY_PROC*)&dll_NtInitialize}, |
4375 | 607 # else |
10603
df1abc85b169
patch 8.0.0191: can't build with Ruby on some systems
Christian Brabandt <cb@256bit.org>
parents:
10595
diff
changeset
|
608 {"ruby_sysinit", (RUBY_PROC*)&dll_ruby_sysinit}, |
4375 | 609 # endif |
610 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 | |
7 | 611 {"rb_w32_snprintf", (RUBY_PROC*)&dll_rb_w32_snprintf}, |
4375 | 612 # endif |
2621 | 613 # endif |
4375 | 614 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
615 {"rb_string_value_ptr", (RUBY_PROC*)&dll_rb_string_value_ptr}, |
4375 | 616 # if DYNAMIC_RUBY_VER <= 19 |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
617 {"rb_float_new", (RUBY_PROC*)&dll_rb_float_new}, |
4375 | 618 # else |
4164 | 619 {"rb_float_new_in_heap", (RUBY_PROC*)&dll_rb_float_new}, |
4375 | 620 # endif |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
621 {"rb_ary_new", (RUBY_PROC*)&dll_rb_ary_new}, |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
622 {"rb_ary_push", (RUBY_PROC*)&dll_rb_ary_push}, |
4375 | 623 # endif |
624 # ifdef RUBY19_OR_LATER | |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
625 {"rb_int2big", (RUBY_PROC*)&dll_rb_int2big}, |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
626 {"ruby_script", (RUBY_PROC*)&dll_ruby_script}, |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
627 {"rb_enc_find_index", (RUBY_PROC*)&dll_rb_enc_find_index}, |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
628 {"rb_enc_find", (RUBY_PROC*)&dll_rb_enc_find}, |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
629 {"rb_enc_str_new", (RUBY_PROC*)&dll_rb_enc_str_new}, |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
630 {"rb_sprintf", (RUBY_PROC*)&dll_rb_sprintf}, |
2669 | 631 {"rb_require", (RUBY_PROC*)&dll_rb_require}, |
7237
2a95fa0a07b5
commit https://github.com/vim/vim/commit/9b1067e038d371bd6c51e5da025383761f4921b4
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
632 {"ruby_options", (RUBY_PROC*)&dll_ruby_options}, |
4375 | 633 # endif |
4452 | 634 # if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK) |
635 # ifdef __ia64 | |
636 {"rb_ia64_bsp", (RUBY_PROC*)&dll_rb_ia64_bsp}, | |
637 # endif | |
638 {"ruby_init_stack", (RUBY_PROC*)&dll_ruby_init_stack}, | |
639 # endif | |
5643 | 640 # if defined(USE_RGENGC) && USE_RGENGC |
6485 | 641 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER == 21 |
5643 | 642 {"rb_gc_writebarrier_unprotect_promoted", (RUBY_PROC*)&dll_rb_gc_writebarrier_unprotect_promoted}, |
6485 | 643 # else |
644 {"rb_gc_writebarrier_unprotect", (RUBY_PROC*)&dll_rb_gc_writebarrier_unprotect}, | |
645 # endif | |
5643 | 646 # endif |
7 | 647 {"", NULL}, |
648 }; | |
649 | |
650 /* | |
651 * Free ruby.dll | |
652 */ | |
653 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
654 end_dynamic_ruby(void) |
7 | 655 { |
656 if (hinstRuby) | |
657 { | |
2589 | 658 close_dll(hinstRuby); |
2621 | 659 hinstRuby = NULL; |
7 | 660 } |
661 } | |
662 | |
663 /* | |
664 * Load library and get all pointers. | |
665 * Parameter 'libname' provides name of DLL. | |
666 * Return OK or FAIL. | |
667 */ | |
668 static int | |
669 ruby_runtime_link_init(char *libname, int verbose) | |
670 { | |
671 int i; | |
672 | |
673 if (hinstRuby) | |
674 return OK; | |
2589 | 675 hinstRuby = load_dll(libname); |
7 | 676 if (!hinstRuby) |
677 { | |
678 if (verbose) | |
679 EMSG2(_(e_loadlib), libname); | |
680 return FAIL; | |
681 } | |
682 | |
683 for (i = 0; ruby_funcname_table[i].ptr; ++i) | |
684 { | |
2589 | 685 if (!(*ruby_funcname_table[i].ptr = symbol_from_dll(hinstRuby, |
7 | 686 ruby_funcname_table[i].name))) |
687 { | |
2589 | 688 close_dll(hinstRuby); |
2621 | 689 hinstRuby = NULL; |
7 | 690 if (verbose) |
691 EMSG2(_(e_loadfunc), ruby_funcname_table[i].name); | |
692 return FAIL; | |
693 } | |
694 } | |
695 return OK; | |
696 } | |
697 | |
698 /* | |
699 * If ruby is enabled (there is installed ruby on Windows system) return TRUE, | |
700 * else FALSE. | |
701 */ | |
702 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
703 ruby_enabled(int verbose) |
7 | 704 { |
7528
53163e4d9e4f
commit https://github.com/vim/vim/commit/25e4fcde767084d1a79e0926bc301c92987c0cce
Christian Brabandt <cb@256bit.org>
parents:
7364
diff
changeset
|
705 return ruby_runtime_link_init((char *)p_rubydll, verbose) == OK; |
7 | 706 } |
707 #endif /* defined(DYNAMIC_RUBY) || defined(PROTO) */ | |
708 | |
709 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
710 ruby_end(void) |
7 | 711 { |
712 #ifdef DYNAMIC_RUBY | |
713 end_dynamic_ruby(); | |
714 #endif | |
715 } | |
716 | |
717 void ex_ruby(exarg_T *eap) | |
718 { | |
719 int state; | |
720 char *script = NULL; | |
721 | |
750 | 722 script = (char *)script_get(eap, eap->arg); |
7 | 723 if (!eap->skip && ensure_ruby_initialized()) |
724 { | |
725 if (script == NULL) | |
726 rb_eval_string_protect((char *)eap->arg, &state); | |
727 else | |
728 rb_eval_string_protect(script, &state); | |
729 if (state) | |
730 error_print(state); | |
731 } | |
732 vim_free(script); | |
733 } | |
734 | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
735 /* |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
736 * In Ruby 1.9 or later, ruby String object has encoding. |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
737 * conversion buffer string of vim to ruby String object using |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
738 * VIM encoding option. |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
739 */ |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
740 static VALUE |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
741 vim_str2rb_enc_str(const char *s) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
742 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
743 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
744 int isnum; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
745 long lval; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
746 char_u *sval; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
747 rb_encoding *enc; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
748 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
749 isnum = get_option_value((char_u *)"enc", &lval, &sval, 0); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
750 if (isnum == 0) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
751 { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
752 enc = rb_enc_find((char *)sval); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
753 vim_free(sval); |
8802
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
754 if (enc) |
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
755 { |
9159
6b003ff07234
commit https://github.com/vim/vim/commit/9b0ac229bcfc91acabd35fc576055a94c1687c32
Christian Brabandt <cb@256bit.org>
parents:
8802
diff
changeset
|
756 return rb_enc_str_new(s, (long)strlen(s), enc); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
757 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
758 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
759 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
760 return rb_str_new2(s); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
761 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
762 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
763 static VALUE |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
764 eval_enc_string_protect(const char *str, int *state) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
765 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
766 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
767 int isnum; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
768 long lval; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
769 char_u *sval; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
770 rb_encoding *enc; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
771 VALUE v; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
772 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
773 isnum = get_option_value((char_u *)"enc", &lval, &sval, 0); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
774 if (isnum == 0) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
775 { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
776 enc = rb_enc_find((char *)sval); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
777 vim_free(sval); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
778 if (enc) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
779 { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
780 v = rb_sprintf("#-*- coding:%s -*-\n%s", rb_enc_name(enc), str); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
781 return rb_eval_string_protect(StringValuePtr(v), state); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
782 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
783 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
784 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
785 return rb_eval_string_protect(str, state); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
786 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
787 |
7 | 788 void ex_rubydo(exarg_T *eap) |
789 { | |
790 int state; | |
791 linenr_T i; | |
10761
721af7a9b4b4
patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
10603
diff
changeset
|
792 buf_T *was_curbuf = curbuf; |
7 | 793 |
794 if (ensure_ruby_initialized()) | |
795 { | |
796 if (u_save(eap->line1 - 1, eap->line2 + 1) != OK) | |
797 return; | |
8802
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
798 for (i = eap->line1; i <= eap->line2; i++) |
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
799 { |
2656 | 800 VALUE line; |
7 | 801 |
10761
721af7a9b4b4
patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
10603
diff
changeset
|
802 if (i > curbuf->b_ml.ml_line_count) |
721af7a9b4b4
patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
10603
diff
changeset
|
803 break; |
2656 | 804 line = vim_str2rb_enc_str((char *)ml_get(i)); |
7 | 805 rb_lastline_set(line); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
806 eval_enc_string_protect((char *) eap->arg, &state); |
8802
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
807 if (state) |
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
808 { |
7 | 809 error_print(state); |
810 break; | |
811 } | |
10761
721af7a9b4b4
patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
10603
diff
changeset
|
812 if (was_curbuf != curbuf) |
721af7a9b4b4
patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
10603
diff
changeset
|
813 break; |
7 | 814 line = rb_lastline_get(); |
8802
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
815 if (!NIL_P(line)) |
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
816 { |
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
817 if (TYPE(line) != T_STRING) |
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
818 { |
835 | 819 EMSG(_("E265: $_ must be an instance of String")); |
7 | 820 return; |
821 } | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
822 ml_replace(i, (char_u *) StringValuePtr(line), 1); |
7 | 823 changed(); |
824 #ifdef SYNTAX_HL | |
825 syn_changed(i); /* recompute syntax hl. for this line */ | |
826 #endif | |
827 } | |
828 } | |
829 check_cursor(); | |
830 update_curbuf(NOT_VALID); | |
831 } | |
832 } | |
833 | |
13958
fbd4f9645b57
patch 8.0.1849: compiler warning for unused arguments, missing prototype
Christian Brabandt <cb@256bit.org>
parents:
13148
diff
changeset
|
834 static VALUE rb_load_wrap(VALUE file_to_load) |
13148
f06a0a75d5b1
patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
835 { |
f06a0a75d5b1
patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
836 rb_load(file_to_load, 0); |
f06a0a75d5b1
patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
837 return Qnil; |
f06a0a75d5b1
patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
838 } |
f06a0a75d5b1
patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
839 |
7 | 840 void ex_rubyfile(exarg_T *eap) |
841 { | |
842 int state; | |
843 | |
844 if (ensure_ruby_initialized()) | |
845 { | |
13148
f06a0a75d5b1
patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
846 VALUE file_to_load = rb_str_new2((const char *)eap->arg); |
f06a0a75d5b1
patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
847 rb_protect(rb_load_wrap, file_to_load, &state); |
f06a0a75d5b1
patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
848 if (state) |
f06a0a75d5b1
patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
849 error_print(state); |
7 | 850 } |
851 } | |
852 | |
853 void ruby_buffer_free(buf_T *buf) | |
854 { | |
502 | 855 if (buf->b_ruby_ref) |
856 { | |
857 rb_hash_aset(objtbl, rb_obj_id((VALUE) buf->b_ruby_ref), Qnil); | |
858 RDATA(buf->b_ruby_ref)->data = NULL; | |
7 | 859 } |
860 } | |
861 | |
862 void ruby_window_free(win_T *win) | |
863 { | |
502 | 864 if (win->w_ruby_ref) |
865 { | |
866 rb_hash_aset(objtbl, rb_obj_id((VALUE) win->w_ruby_ref), Qnil); | |
867 RDATA(win->w_ruby_ref)->data = NULL; | |
7 | 868 } |
869 } | |
870 | |
871 static int ensure_ruby_initialized(void) | |
872 { | |
873 if (!ruby_initialized) | |
874 { | |
875 #ifdef DYNAMIC_RUBY | |
876 if (ruby_enabled(TRUE)) | |
877 { | |
878 #endif | |
2076
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
879 #ifdef _WIN32 |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
880 /* suggested by Ariya Mizutani */ |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
881 int argc = 1; |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
882 char *argv[] = {"gvim.exe"}; |
6406 | 883 char **argvp = argv; |
10595
dbaad101b1e1
patch 8.0.0187: cant build with new Ruby version
Christian Brabandt <cb@256bit.org>
parents:
10546
diff
changeset
|
884 # ifdef RUBY19_OR_LATER |
dbaad101b1e1
patch 8.0.0187: cant build with new Ruby version
Christian Brabandt <cb@256bit.org>
parents:
10546
diff
changeset
|
885 ruby_sysinit(&argc, &argvp); |
dbaad101b1e1
patch 8.0.0187: cant build with new Ruby version
Christian Brabandt <cb@256bit.org>
parents:
10546
diff
changeset
|
886 # else |
6406 | 887 NtInitialize(&argc, &argvp); |
10595
dbaad101b1e1
patch 8.0.0187: cant build with new Ruby version
Christian Brabandt <cb@256bit.org>
parents:
10546
diff
changeset
|
888 # endif |
2076
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
889 #endif |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2274
diff
changeset
|
890 { |
4452 | 891 #if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK) |
4369 | 892 ruby_init_stack(ruby_stack_start); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
893 #endif |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2274
diff
changeset
|
894 ruby_init(); |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2274
diff
changeset
|
895 } |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
896 #ifdef RUBY19_OR_LATER |
2669 | 897 { |
898 int dummy_argc = 2; | |
12553
270aec277c81
patch 8.0.1155: Ruby command triggers a warning
Christian Brabandt <cb@256bit.org>
parents:
12517
diff
changeset
|
899 char *dummy_argv[] = {"vim-ruby", "-e_=0"}; |
7237
2a95fa0a07b5
commit https://github.com/vim/vim/commit/9b1067e038d371bd6c51e5da025383761f4921b4
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
900 ruby_options(dummy_argc, dummy_argv); |
2669 | 901 } |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
902 ruby_script("vim-ruby"); |
2669 | 903 #else |
904 ruby_init_loadpath(); | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
905 #endif |
7 | 906 ruby_io_init(); |
907 ruby_vim_init(); | |
908 ruby_initialized = 1; | |
909 #ifdef DYNAMIC_RUBY | |
910 } | |
911 else | |
912 { | |
913 EMSG(_("E266: Sorry, this command is disabled, the Ruby library could not be loaded.")); | |
914 return 0; | |
915 } | |
916 #endif | |
917 } | |
918 return ruby_initialized; | |
919 } | |
920 | |
921 static void error_print(int state) | |
922 { | |
923 #ifndef DYNAMIC_RUBY | |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
924 #if !(defined(RUBY_VERSION) && RUBY_VERSION >= 19) \ |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
925 && !(defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19) |
7 | 926 RUBYEXTERN VALUE ruby_errinfo; |
927 #endif | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
928 #endif |
7 | 929 VALUE eclass; |
930 VALUE einfo; | |
931 char buff[BUFSIZ]; | |
932 | |
933 #define TAG_RETURN 0x1 | |
934 #define TAG_BREAK 0x2 | |
935 #define TAG_NEXT 0x3 | |
936 #define TAG_RETRY 0x4 | |
937 #define TAG_REDO 0x5 | |
938 #define TAG_RAISE 0x6 | |
939 #define TAG_THROW 0x7 | |
940 #define TAG_FATAL 0x8 | |
941 #define TAG_MASK 0xf | |
942 | |
8802
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
943 switch (state) |
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
944 { |
7 | 945 case TAG_RETURN: |
835 | 946 EMSG(_("E267: unexpected return")); |
7 | 947 break; |
948 case TAG_NEXT: | |
835 | 949 EMSG(_("E268: unexpected next")); |
7 | 950 break; |
951 case TAG_BREAK: | |
835 | 952 EMSG(_("E269: unexpected break")); |
7 | 953 break; |
954 case TAG_REDO: | |
835 | 955 EMSG(_("E270: unexpected redo")); |
7 | 956 break; |
957 case TAG_RETRY: | |
835 | 958 EMSG(_("E271: retry outside of rescue clause")); |
7 | 959 break; |
960 case TAG_RAISE: | |
961 case TAG_FATAL: | |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
962 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
963 eclass = CLASS_OF(rb_errinfo()); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
964 einfo = rb_obj_as_string(rb_errinfo()); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
965 #else |
7 | 966 eclass = CLASS_OF(ruby_errinfo); |
967 einfo = rb_obj_as_string(ruby_errinfo); | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
968 #endif |
8802
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
969 if (eclass == rb_eRuntimeError && RSTRING_LEN(einfo) == 0) |
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
970 { |
835 | 971 EMSG(_("E272: unhandled exception")); |
7 | 972 } |
8802
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
973 else |
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
974 { |
7 | 975 VALUE epath; |
976 char *p; | |
977 | |
978 epath = rb_class_path(eclass); | |
272 | 979 vim_snprintf(buff, BUFSIZ, "%s: %s", |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
980 RSTRING_PTR(epath), RSTRING_PTR(einfo)); |
7 | 981 p = strchr(buff, '\n'); |
982 if (p) *p = '\0'; | |
983 EMSG(buff); | |
984 } | |
985 break; | |
986 default: | |
272 | 987 vim_snprintf(buff, BUFSIZ, _("E273: unknown longjmp status %d"), state); |
7 | 988 EMSG(buff); |
989 break; | |
990 } | |
991 } | |
992 | |
1888 | 993 static VALUE vim_message(VALUE self UNUSED, VALUE str) |
7 | 994 { |
995 char *buff, *p; | |
996 | |
997 str = rb_obj_as_string(str); | |
2990 | 998 if (RSTRING_LEN(str) > 0) |
999 { | |
1000 /* Only do this when the string isn't empty, alloc(0) causes trouble. */ | |
12335
df498e3e34fc
patch 8.0.1047: buffer overflow in Ruby
Christian Brabandt <cb@256bit.org>
parents:
10761
diff
changeset
|
1001 buff = ALLOCA_N(char, RSTRING_LEN(str) + 1); |
2990 | 1002 strcpy(buff, RSTRING_PTR(str)); |
1003 p = strchr(buff, '\n'); | |
1004 if (p) *p = '\0'; | |
1005 MSG(buff); | |
1006 } | |
1007 else | |
1008 { | |
1009 MSG(""); | |
1010 } | |
7 | 1011 return Qnil; |
1012 } | |
1013 | |
1888 | 1014 static VALUE vim_set_option(VALUE self UNUSED, VALUE str) |
7 | 1015 { |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1016 do_set((char_u *)StringValuePtr(str), 0); |
7 | 1017 update_screen(NOT_VALID); |
1018 return Qnil; | |
1019 } | |
1020 | |
1888 | 1021 static VALUE vim_command(VALUE self UNUSED, VALUE str) |
7 | 1022 { |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1023 do_cmdline_cmd((char_u *)StringValuePtr(str)); |
7 | 1024 return Qnil; |
1025 } | |
1026 | |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1027 #ifdef FEAT_EVAL |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1028 static VALUE vim_to_ruby(typval_T *tv) |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1029 { |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1030 VALUE result = Qnil; |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1031 |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1032 if (tv->v_type == VAR_STRING) |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1033 { |
2121
20d9fc2f13a4
updated for version 7.2.403
Bram Moolenaar <bram@zimbu.org>
parents:
2117
diff
changeset
|
1034 result = rb_str_new2(tv->vval.v_string == NULL |
20d9fc2f13a4
updated for version 7.2.403
Bram Moolenaar <bram@zimbu.org>
parents:
2117
diff
changeset
|
1035 ? "" : (char *)(tv->vval.v_string)); |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1036 } |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1037 else if (tv->v_type == VAR_NUMBER) |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1038 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1039 result = INT2NUM(tv->vval.v_number); |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1040 } |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1041 # ifdef FEAT_FLOAT |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1042 else if (tv->v_type == VAR_FLOAT) |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1043 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1044 result = rb_float_new(tv->vval.v_float); |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1045 } |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1046 # endif |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1047 else if (tv->v_type == VAR_LIST) |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1048 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1049 list_T *list = tv->vval.v_list; |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1050 listitem_T *curr; |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1051 |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1052 result = rb_ary_new(); |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1053 |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1054 if (list != NULL) |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1055 { |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1056 for (curr = list->lv_first; curr != NULL; curr = curr->li_next) |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1057 { |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1058 rb_ary_push(result, vim_to_ruby(&curr->li_tv)); |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1059 } |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1060 } |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1061 } |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1062 else if (tv->v_type == VAR_DICT) |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1063 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1064 result = rb_hash_new(); |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1065 |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1066 if (tv->vval.v_dict != NULL) |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1067 { |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1068 hashtab_T *ht = &tv->vval.v_dict->dv_hashtab; |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1069 long_u todo = ht->ht_used; |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1070 hashitem_T *hi; |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1071 dictitem_T *di; |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1072 |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1073 for (hi = ht->ht_array; todo > 0; ++hi) |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1074 { |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1075 if (!HASHITEM_EMPTY(hi)) |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1076 { |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1077 --todo; |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1078 |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1079 di = dict_lookup(hi); |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1080 rb_hash_aset(result, rb_str_new2((char *)hi->hi_key), |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1081 vim_to_ruby(&di->di_tv)); |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1082 } |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1083 } |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1084 } |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
1085 } |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
1086 else if (tv->v_type == VAR_SPECIAL) |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
1087 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
1088 if (tv->vval.v_number <= VVAL_TRUE) |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
1089 result = INT2NUM(tv->vval.v_number); |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1090 } /* else return Qnil; */ |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1091 |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1092 return result; |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1093 } |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1094 #endif |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1095 |
1888 | 1096 static VALUE vim_evaluate(VALUE self UNUSED, VALUE str) |
7 | 1097 { |
1098 #ifdef FEAT_EVAL | |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1099 typval_T *tv; |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1100 VALUE result; |
7 | 1101 |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1102 tv = eval_expr((char_u *)StringValuePtr(str), NULL); |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1103 if (tv == NULL) |
7 | 1104 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
1105 return Qnil; |
7 | 1106 } |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1107 result = vim_to_ruby(tv); |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1108 |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1109 free_tv(tv); |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1110 |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1111 return result; |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1112 #else |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
1113 return Qnil; |
7 | 1114 #endif |
1115 } | |
1116 | |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1117 #ifdef USE_TYPEDDATA |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1118 static size_t buffer_dsize(const void *buf); |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1119 |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1120 static const rb_data_type_t buffer_type = { |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1121 "vim_buffer", |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1122 {0, 0, buffer_dsize, {0, 0}}, |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1123 0, 0, |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1124 # ifdef RUBY_TYPED_FREE_IMMEDIATELY |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1125 0, |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1126 # endif |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1127 }; |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1128 |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1129 static size_t buffer_dsize(const void *buf UNUSED) |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1130 { |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1131 return sizeof(buf_T); |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1132 } |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1133 #endif |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1134 |
7 | 1135 static VALUE buffer_new(buf_T *buf) |
1136 { | |
502 | 1137 if (buf->b_ruby_ref) |
1138 { | |
1139 return (VALUE) buf->b_ruby_ref; | |
7 | 1140 } |
502 | 1141 else |
1142 { | |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1143 #ifdef USE_TYPEDDATA |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1144 VALUE obj = TypedData_Wrap_Struct(cBuffer, &buffer_type, buf); |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1145 #else |
7 | 1146 VALUE obj = Data_Wrap_Struct(cBuffer, 0, 0, buf); |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1147 #endif |
502 | 1148 buf->b_ruby_ref = (void *) obj; |
7 | 1149 rb_hash_aset(objtbl, rb_obj_id(obj), obj); |
1150 return obj; | |
1151 } | |
1152 } | |
1153 | |
1154 static buf_T *get_buf(VALUE obj) | |
1155 { | |
1156 buf_T *buf; | |
1157 | |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1158 #ifdef USE_TYPEDDATA |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1159 TypedData_Get_Struct(obj, buf_T, &buffer_type, buf); |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1160 #else |
7 | 1161 Data_Get_Struct(obj, buf_T, buf); |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1162 #endif |
7 | 1163 if (buf == NULL) |
1164 rb_raise(eDeletedBufferError, "attempt to refer to deleted buffer"); | |
1165 return buf; | |
1166 } | |
1167 | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
1168 static VALUE buffer_s_current(void) |
7 | 1169 { |
1170 return buffer_new(curbuf); | |
1171 } | |
1172 | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
1173 static VALUE buffer_s_count(void) |
7 | 1174 { |
1175 buf_T *b; | |
1176 int n = 0; | |
1177 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9293
diff
changeset
|
1178 FOR_ALL_BUFFERS(b) |
779 | 1179 { |
856 | 1180 /* Deleted buffers should not be counted |
1181 * SegPhault - 01/07/05 */ | |
1182 if (b->b_p_bl) | |
779 | 1183 n++; |
1184 } | |
1185 | |
7 | 1186 return INT2NUM(n); |
1187 } | |
1188 | |
1888 | 1189 static VALUE buffer_s_aref(VALUE self UNUSED, VALUE num) |
7 | 1190 { |
1191 buf_T *b; | |
1192 int n = NUM2INT(num); | |
1193 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9293
diff
changeset
|
1194 FOR_ALL_BUFFERS(b) |
779 | 1195 { |
856 | 1196 /* Deleted buffers should not be counted |
1197 * SegPhault - 01/07/05 */ | |
1198 if (!b->b_p_bl) | |
779 | 1199 continue; |
1200 | |
856 | 1201 if (n == 0) |
7 | 1202 return buffer_new(b); |
779 | 1203 |
856 | 1204 n--; |
7 | 1205 } |
1206 return Qnil; | |
1207 } | |
1208 | |
1209 static VALUE buffer_name(VALUE self) | |
1210 { | |
1211 buf_T *buf = get_buf(self); | |
1212 | |
750 | 1213 return buf->b_ffname ? rb_str_new2((char *)buf->b_ffname) : Qnil; |
7 | 1214 } |
1215 | |
1216 static VALUE buffer_number(VALUE self) | |
1217 { | |
1218 buf_T *buf = get_buf(self); | |
1219 | |
1220 return INT2NUM(buf->b_fnum); | |
1221 } | |
1222 | |
1223 static VALUE buffer_count(VALUE self) | |
1224 { | |
1225 buf_T *buf = get_buf(self); | |
1226 | |
1227 return INT2NUM(buf->b_ml.ml_line_count); | |
1228 } | |
1229 | |
779 | 1230 static VALUE get_buffer_line(buf_T *buf, linenr_T n) |
7 | 1231 { |
2637 | 1232 if (n <= 0 || n > buf->b_ml.ml_line_count) |
1233 rb_raise(rb_eIndexError, "line number %ld out of range", (long)n); | |
1234 return vim_str2rb_enc_str((char *)ml_get_buf(buf, n, FALSE)); | |
7 | 1235 } |
1236 | |
779 | 1237 static VALUE buffer_aref(VALUE self, VALUE num) |
7 | 1238 { |
1239 buf_T *buf = get_buf(self); | |
779 | 1240 |
1241 if (buf != NULL) | |
1242 return get_buffer_line(buf, (linenr_T)NUM2LONG(num)); | |
1243 return Qnil; /* For stop warning */ | |
1244 } | |
1245 | |
1246 static VALUE set_buffer_line(buf_T *buf, linenr_T n, VALUE str) | |
1247 { | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1248 char *line = StringValuePtr(str); |
896 | 1249 aco_save_T aco; |
7 | 1250 |
896 | 1251 if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL) |
1252 { | |
1253 /* set curwin/curbuf for "buf" and save some things */ | |
1254 aucmd_prepbuf(&aco, buf); | |
1255 | |
8802
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1256 if (u_savesub(n) == OK) |
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1257 { |
779 | 1258 ml_replace(n, (char_u *)line, TRUE); |
7 | 1259 changed(); |
1260 #ifdef SYNTAX_HL | |
1261 syn_changed(n); /* recompute syntax hl. for this line */ | |
1262 #endif | |
1263 } | |
896 | 1264 |
1265 /* restore curwin/curbuf and a few other things */ | |
1266 aucmd_restbuf(&aco); | |
1267 /* Careful: autocommands may have made "buf" invalid! */ | |
934 | 1268 |
7 | 1269 update_curbuf(NOT_VALID); |
1270 } | |
896 | 1271 else |
1272 { | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1273 rb_raise(rb_eIndexError, "line number %ld out of range", (long)n); |
7 | 1274 } |
1275 return str; | |
1276 } | |
1277 | |
779 | 1278 static VALUE buffer_aset(VALUE self, VALUE num, VALUE str) |
1279 { | |
1280 buf_T *buf = get_buf(self); | |
1281 | |
1282 if (buf != NULL) | |
1283 return set_buffer_line(buf, (linenr_T)NUM2LONG(num), str); | |
1284 return str; | |
1285 } | |
1286 | |
7 | 1287 static VALUE buffer_delete(VALUE self, VALUE num) |
1288 { | |
896 | 1289 buf_T *buf = get_buf(self); |
1290 long n = NUM2LONG(num); | |
1291 aco_save_T aco; | |
7 | 1292 |
896 | 1293 if (n > 0 && n <= buf->b_ml.ml_line_count) |
1294 { | |
1295 /* set curwin/curbuf for "buf" and save some things */ | |
1296 aucmd_prepbuf(&aco, buf); | |
1297 | |
8802
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1298 if (u_savedel(n, 1) == OK) |
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1299 { |
7 | 1300 ml_delete(n, 0); |
779 | 1301 |
856 | 1302 /* Changes to non-active buffers should properly refresh |
1303 * SegPhault - 01/09/05 */ | |
1304 deleted_lines_mark(n, 1L); | |
779 | 1305 |
7 | 1306 changed(); |
1307 } | |
896 | 1308 |
1309 /* restore curwin/curbuf and a few other things */ | |
1310 aucmd_restbuf(&aco); | |
1311 /* Careful: autocommands may have made "buf" invalid! */ | |
934 | 1312 |
7 | 1313 update_curbuf(NOT_VALID); |
1314 } | |
896 | 1315 else |
1316 { | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1317 rb_raise(rb_eIndexError, "line number %ld out of range", n); |
7 | 1318 } |
1319 return Qnil; | |
1320 } | |
1321 | |
1322 static VALUE buffer_append(VALUE self, VALUE num, VALUE str) | |
1323 { | |
896 | 1324 buf_T *buf = get_buf(self); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1325 char *line = StringValuePtr(str); |
896 | 1326 long n = NUM2LONG(num); |
1327 aco_save_T aco; | |
7 | 1328 |
2637 | 1329 if (line == NULL) |
1330 { | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1331 rb_raise(rb_eIndexError, "NULL line"); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1332 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1333 else if (n >= 0 && n <= buf->b_ml.ml_line_count) |
896 | 1334 { |
1335 /* set curwin/curbuf for "buf" and save some things */ | |
1336 aucmd_prepbuf(&aco, buf); | |
1337 | |
8802
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1338 if (u_inssub(n + 1) == OK) |
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1339 { |
7 | 1340 ml_append(n, (char_u *) line, (colnr_T) 0, FALSE); |
779 | 1341 |
856 | 1342 /* Changes to non-active buffers should properly refresh screen |
1343 * SegPhault - 12/20/04 */ | |
1344 appended_lines_mark(n, 1L); | |
779 | 1345 |
856 | 1346 changed(); |
7 | 1347 } |
896 | 1348 |
1349 /* restore curwin/curbuf and a few other things */ | |
1350 aucmd_restbuf(&aco); | |
1351 /* Careful: autocommands may have made "buf" invalid! */ | |
934 | 1352 |
7 | 1353 update_curbuf(NOT_VALID); |
1354 } | |
2637 | 1355 else |
1356 { | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1357 rb_raise(rb_eIndexError, "line number %ld out of range", n); |
7 | 1358 } |
1359 return str; | |
1360 } | |
1361 | |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1362 #ifdef USE_TYPEDDATA |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1363 static size_t window_dsize(const void *buf); |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1364 |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1365 static const rb_data_type_t window_type = { |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1366 "vim_window", |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1367 {0, 0, window_dsize, {0, 0}}, |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1368 0, 0, |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1369 # ifdef RUBY_TYPED_FREE_IMMEDIATELY |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1370 0, |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1371 # endif |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1372 }; |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1373 |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1374 static size_t window_dsize(const void *win UNUSED) |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1375 { |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1376 return sizeof(win_T); |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1377 } |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1378 #endif |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1379 |
7 | 1380 static VALUE window_new(win_T *win) |
1381 { | |
502 | 1382 if (win->w_ruby_ref) |
1383 { | |
1384 return (VALUE) win->w_ruby_ref; | |
7 | 1385 } |
502 | 1386 else |
1387 { | |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1388 #ifdef USE_TYPEDDATA |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1389 VALUE obj = TypedData_Wrap_Struct(cVimWindow, &window_type, win); |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1390 #else |
7 | 1391 VALUE obj = Data_Wrap_Struct(cVimWindow, 0, 0, win); |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1392 #endif |
502 | 1393 win->w_ruby_ref = (void *) obj; |
7 | 1394 rb_hash_aset(objtbl, rb_obj_id(obj), obj); |
1395 return obj; | |
1396 } | |
1397 } | |
1398 | |
1399 static win_T *get_win(VALUE obj) | |
1400 { | |
1401 win_T *win; | |
1402 | |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1403 #ifdef USE_TYPEDDATA |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1404 TypedData_Get_Struct(obj, win_T, &window_type, win); |
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1405 #else |
7 | 1406 Data_Get_Struct(obj, win_T, win); |
7360
b20095ba6fc2
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Christian Brabandt <cb@256bit.org>
parents:
7237
diff
changeset
|
1407 #endif |
7 | 1408 if (win == NULL) |
1409 rb_raise(eDeletedWindowError, "attempt to refer to deleted window"); | |
1410 return win; | |
1411 } | |
1412 | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
1413 static VALUE window_s_current(void) |
7 | 1414 { |
1415 return window_new(curwin); | |
1416 } | |
1417 | |
779 | 1418 /* |
1419 * Added line manipulation functions | |
1420 * SegPhault - 03/07/05 | |
1421 */ | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
1422 static VALUE line_s_current(void) |
779 | 1423 { |
1424 return get_buffer_line(curbuf, curwin->w_cursor.lnum); | |
1425 } | |
1426 | |
1888 | 1427 static VALUE set_current_line(VALUE self UNUSED, VALUE str) |
779 | 1428 { |
1429 return set_buffer_line(curbuf, curwin->w_cursor.lnum, str); | |
1430 } | |
1431 | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
1432 static VALUE current_line_number(void) |
779 | 1433 { |
1434 return INT2FIX((int)curwin->w_cursor.lnum); | |
1435 } | |
1436 | |
1437 | |
1438 | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
1439 static VALUE window_s_count(void) |
7 | 1440 { |
1441 win_T *w; | |
1442 int n = 0; | |
1443 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9293
diff
changeset
|
1444 FOR_ALL_WINDOWS(w) |
7 | 1445 n++; |
1446 return INT2NUM(n); | |
1447 } | |
1448 | |
1888 | 1449 static VALUE window_s_aref(VALUE self UNUSED, VALUE num) |
7 | 1450 { |
1451 win_T *w; | |
1452 int n = NUM2INT(num); | |
1453 | |
1454 for (w = firstwin; w != NULL; w = w->w_next, --n) | |
1455 if (n == 0) | |
1456 return window_new(w); | |
1457 return Qnil; | |
1458 } | |
1459 | |
1460 static VALUE window_buffer(VALUE self) | |
1461 { | |
1462 win_T *win = get_win(self); | |
1463 | |
1464 return buffer_new(win->w_buffer); | |
1465 } | |
1466 | |
1467 static VALUE window_height(VALUE self) | |
1468 { | |
1469 win_T *win = get_win(self); | |
1470 | |
1471 return INT2NUM(win->w_height); | |
1472 } | |
1473 | |
1474 static VALUE window_set_height(VALUE self, VALUE height) | |
1475 { | |
1476 win_T *win = get_win(self); | |
1477 win_T *savewin = curwin; | |
1478 | |
1479 curwin = win; | |
1480 win_setheight(NUM2INT(height)); | |
1481 curwin = savewin; | |
1482 return height; | |
1483 } | |
1484 | |
4135 | 1485 static VALUE window_width(VALUE self UNUSED) |
501 | 1486 { |
12517
1b65cbe1578d
patch 8.0.1137: cannot build with Ruby
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1487 return INT2NUM(get_win(self)->w_width); |
501 | 1488 } |
1489 | |
4135 | 1490 static VALUE window_set_width(VALUE self UNUSED, VALUE width) |
501 | 1491 { |
1492 win_T *win = get_win(self); | |
1493 win_T *savewin = curwin; | |
1494 | |
1495 curwin = win; | |
1496 win_setwidth(NUM2INT(width)); | |
1497 curwin = savewin; | |
1498 return width; | |
1499 } | |
1500 | |
7 | 1501 static VALUE window_cursor(VALUE self) |
1502 { | |
1503 win_T *win = get_win(self); | |
1504 | |
1505 return rb_assoc_new(INT2NUM(win->w_cursor.lnum), INT2NUM(win->w_cursor.col)); | |
1506 } | |
1507 | |
1508 static VALUE window_set_cursor(VALUE self, VALUE pos) | |
1509 { | |
1510 VALUE lnum, col; | |
1511 win_T *win = get_win(self); | |
1512 | |
1513 Check_Type(pos, T_ARRAY); | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1514 if (RARRAY_LEN(pos) != 2) |
7 | 1515 rb_raise(rb_eArgError, "array length must be 2"); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1516 lnum = RARRAY_PTR(pos)[0]; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1517 col = RARRAY_PTR(pos)[1]; |
7 | 1518 win->w_cursor.lnum = NUM2LONG(lnum); |
1519 win->w_cursor.col = NUM2UINT(col); | |
1520 check_cursor(); /* put cursor on an existing line */ | |
1521 update_screen(NOT_VALID); | |
1522 return Qnil; | |
1523 } | |
1524 | |
3478 | 1525 static VALUE f_nop(VALUE self UNUSED) |
3474 | 1526 { |
1527 return Qnil; | |
1528 } | |
1529 | |
1888 | 1530 static VALUE f_p(int argc, VALUE *argv, VALUE self UNUSED) |
7 | 1531 { |
1532 int i; | |
1533 VALUE str = rb_str_new("", 0); | |
1534 | |
8802
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1535 for (i = 0; i < argc; i++) |
eaf11fa2fec8
commit https://github.com/vim/vim/commit/758535a1df4c5e86b45dddf12db2a54dea28ca40
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1536 { |
7 | 1537 if (i > 0) rb_str_cat(str, ", ", 2); |
1538 rb_str_concat(str, rb_inspect(argv[i])); | |
1539 } | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1540 MSG(RSTRING_PTR(str)); |
7 | 1541 return Qnil; |
1542 } | |
1543 | |
1544 static void ruby_io_init(void) | |
1545 { | |
1546 #ifndef DYNAMIC_RUBY | |
1547 RUBYEXTERN VALUE rb_stdout; | |
14389
424ccd85d5c6
patch 8.1.0209: stderr output from Ruby messes up display
Christian Brabandt <cb@256bit.org>
parents:
13958
diff
changeset
|
1548 RUBYEXTERN VALUE rb_stderr; |
7 | 1549 #endif |
1550 | |
1551 rb_stdout = rb_obj_alloc(rb_cObject); | |
14389
424ccd85d5c6
patch 8.1.0209: stderr output from Ruby messes up display
Christian Brabandt <cb@256bit.org>
parents:
13958
diff
changeset
|
1552 rb_stderr = rb_obj_alloc(rb_cObject); |
7 | 1553 rb_define_singleton_method(rb_stdout, "write", vim_message, 1); |
3474 | 1554 rb_define_singleton_method(rb_stdout, "flush", f_nop, 0); |
14389
424ccd85d5c6
patch 8.1.0209: stderr output from Ruby messes up display
Christian Brabandt <cb@256bit.org>
parents:
13958
diff
changeset
|
1555 rb_define_singleton_method(rb_stderr, "write", vim_message, 1); |
424ccd85d5c6
patch 8.1.0209: stderr output from Ruby messes up display
Christian Brabandt <cb@256bit.org>
parents:
13958
diff
changeset
|
1556 rb_define_singleton_method(rb_stderr, "flush", f_nop, 0); |
7 | 1557 rb_define_global_function("p", f_p, -1); |
1558 } | |
1559 | |
1560 static void ruby_vim_init(void) | |
1561 { | |
1562 objtbl = rb_hash_new(); | |
1563 rb_global_variable(&objtbl); | |
1564 | |
1188 | 1565 /* The Vim module used to be called "VIM", but "Vim" is better. Make an |
4352 | 1566 * alias "VIM" for backwards compatibility. */ |
1188 | 1567 mVIM = rb_define_module("Vim"); |
1568 rb_define_const(rb_cObject, "VIM", mVIM); | |
7 | 1569 rb_define_const(mVIM, "VERSION_MAJOR", INT2NUM(VIM_VERSION_MAJOR)); |
1570 rb_define_const(mVIM, "VERSION_MINOR", INT2NUM(VIM_VERSION_MINOR)); | |
1571 rb_define_const(mVIM, "VERSION_BUILD", INT2NUM(VIM_VERSION_BUILD)); | |
1572 rb_define_const(mVIM, "VERSION_PATCHLEVEL", INT2NUM(VIM_VERSION_PATCHLEVEL)); | |
1573 rb_define_const(mVIM, "VERSION_SHORT", rb_str_new2(VIM_VERSION_SHORT)); | |
1574 rb_define_const(mVIM, "VERSION_MEDIUM", rb_str_new2(VIM_VERSION_MEDIUM)); | |
1575 rb_define_const(mVIM, "VERSION_LONG", rb_str_new2(VIM_VERSION_LONG)); | |
1576 rb_define_const(mVIM, "VERSION_LONG_DATE", rb_str_new2(VIM_VERSION_LONG_DATE)); | |
1577 rb_define_module_function(mVIM, "message", vim_message, 1); | |
1578 rb_define_module_function(mVIM, "set_option", vim_set_option, 1); | |
1579 rb_define_module_function(mVIM, "command", vim_command, 1); | |
1580 rb_define_module_function(mVIM, "evaluate", vim_evaluate, 1); | |
1581 | |
1582 eDeletedBufferError = rb_define_class_under(mVIM, "DeletedBufferError", | |
1583 rb_eStandardError); | |
1584 eDeletedWindowError = rb_define_class_under(mVIM, "DeletedWindowError", | |
1585 rb_eStandardError); | |
1586 | |
1587 cBuffer = rb_define_class_under(mVIM, "Buffer", rb_cObject); | |
1588 rb_define_singleton_method(cBuffer, "current", buffer_s_current, 0); | |
1589 rb_define_singleton_method(cBuffer, "count", buffer_s_count, 0); | |
1590 rb_define_singleton_method(cBuffer, "[]", buffer_s_aref, 1); | |
1591 rb_define_method(cBuffer, "name", buffer_name, 0); | |
1592 rb_define_method(cBuffer, "number", buffer_number, 0); | |
1593 rb_define_method(cBuffer, "count", buffer_count, 0); | |
1594 rb_define_method(cBuffer, "length", buffer_count, 0); | |
1595 rb_define_method(cBuffer, "[]", buffer_aref, 1); | |
1596 rb_define_method(cBuffer, "[]=", buffer_aset, 2); | |
1597 rb_define_method(cBuffer, "delete", buffer_delete, 1); | |
1598 rb_define_method(cBuffer, "append", buffer_append, 2); | |
1599 | |
779 | 1600 /* Added line manipulation functions |
1601 * SegPhault - 03/07/05 */ | |
1602 rb_define_method(cBuffer, "line_number", current_line_number, 0); | |
1603 rb_define_method(cBuffer, "line", line_s_current, 0); | |
1604 rb_define_method(cBuffer, "line=", set_current_line, 1); | |
1605 | |
1606 | |
7 | 1607 cVimWindow = rb_define_class_under(mVIM, "Window", rb_cObject); |
1608 rb_define_singleton_method(cVimWindow, "current", window_s_current, 0); | |
1609 rb_define_singleton_method(cVimWindow, "count", window_s_count, 0); | |
1610 rb_define_singleton_method(cVimWindow, "[]", window_s_aref, 1); | |
1611 rb_define_method(cVimWindow, "buffer", window_buffer, 0); | |
1612 rb_define_method(cVimWindow, "height", window_height, 0); | |
1613 rb_define_method(cVimWindow, "height=", window_set_height, 1); | |
501 | 1614 rb_define_method(cVimWindow, "width", window_width, 0); |
1615 rb_define_method(cVimWindow, "width=", window_set_width, 1); | |
7 | 1616 rb_define_method(cVimWindow, "cursor", window_cursor, 0); |
1617 rb_define_method(cVimWindow, "cursor=", window_set_cursor, 1); | |
1618 | |
1619 rb_define_virtual_variable("$curbuf", buffer_s_current, 0); | |
1620 rb_define_virtual_variable("$curwin", window_s_current, 0); | |
1621 } | |
4369 | 1622 |
1623 void vim_ruby_init(void *stack_start) | |
1624 { | |
1625 /* should get machine stack start address early in main function */ | |
1626 ruby_stack_start = stack_start; | |
1627 } |