Mercurial > vim
annotate src/if_ruby.c @ 2200:99ba9a30755a vim73
Various smaller changes. Updated proto files. Updated dependencies.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 20 May 2010 21:46:00 +0200 |
parents | 20d9fc2f13a4 |
children | 7d3cf4693a8f |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
779 | 4 * |
5 * Ruby interface by Shugo Maeda | |
6 * with improvements by SegPhault (Ryan Paul) | |
7 | 7 * |
8 * Do ":help uganda" in Vim to read copying and usage conditions. | |
9 * Do ":help credits" in Vim to see a list of people who contributed. | |
10 * See README.txt for an overview of the Vim source code. | |
11 */ | |
12 | |
13 #include <stdio.h> | |
14 #include <string.h> | |
15 | |
16 #ifdef _WIN32 | |
17 # if !defined(DYNAMIC_RUBY_VER) || (DYNAMIC_RUBY_VER < 18) | |
18 # define NT | |
19 # endif | |
20 # ifndef DYNAMIC_RUBY | |
21 # define IMPORT /* For static dll usage __declspec(dllimport) */ | |
22 # define RUBYEXTERN __declspec(dllimport) | |
23 # endif | |
24 #endif | |
25 #ifndef RUBYEXTERN | |
26 # define RUBYEXTERN extern | |
27 #endif | |
28 | |
29 /* | |
30 * This is tricky. In ruby.h there is (inline) function rb_class_of() | |
31 * definition. This function use these variables. But we want function to | |
32 * use dll_* variables. | |
33 */ | |
34 #ifdef DYNAMIC_RUBY | |
35 # define rb_cFalseClass (*dll_rb_cFalseClass) | |
36 # define rb_cFixnum (*dll_rb_cFixnum) | |
37 # define rb_cNilClass (*dll_rb_cNilClass) | |
38 # define rb_cSymbol (*dll_rb_cSymbol) | |
39 # define rb_cTrueClass (*dll_rb_cTrueClass) | |
40 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 | |
41 /* | |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
42 * 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
|
43 * in ruby.h. But it causes trouble for these variables, because it is |
7 | 44 * defined in this file. When defined this RUBY_EXPORT it modified to |
45 * "extern" and be able to avoid this problem. | |
46 */ | |
47 # define RUBY_EXPORT | |
48 # endif | |
49 #endif | |
50 | |
2076
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
51 /* suggested by Ariya Mizutani */ |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
52 #if (_MSC_VER == 1200) |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
53 # undef _WIN32_WINNT |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
54 #endif |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
55 |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
56 #if (defined(RUBY_VERSION) && RUBY_VERSION >= 19) \ |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
57 || (defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19) |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
58 # define RUBY19_OR_LATER 1 |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
59 #endif |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
60 |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
61 #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
|
62 /* 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
|
63 * rb_int2big */ |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
64 # define rb_num2long rb_num2long_stub |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
65 # define rb_int2big rb_int2big_stub |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
66 #endif |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
67 |
7 | 68 #include <ruby.h> |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
69 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
70 # include <ruby/encoding.h> |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
71 #endif |
7 | 72 |
73 #undef EXTERN | |
74 #undef _ | |
75 | |
76 /* T_DATA defined both by Ruby and Mac header files, hack around it... */ | |
1233 | 77 #if defined(MACOS_X_UNIX) || defined(macintosh) |
7 | 78 # define __OPENTRANSPORT__ |
79 # define __OPENTRANSPORTPROTOCOL__ | |
80 # define __OPENTRANSPORTPROVIDERS__ | |
81 #endif | |
82 | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
83 /* |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
84 * Backward compatiblity for Ruby 1.8 and earlier. |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
85 * 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
|
86 * 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
|
87 * 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
|
88 */ |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
89 #ifndef StringValuePtr |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
90 # define StringValuePtr(s) STR2CSTR(s) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
91 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
92 #ifndef RARRAY_LEN |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
93 # define RARRAY_LEN(s) RARRAY(s)->len |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
94 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
95 #ifndef RARRAY_PTR |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
96 # define RARRAY_PTR(s) RARRAY(s)->ptr |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
97 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
98 #ifndef RSTRING_LEN |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
99 # define RSTRING_LEN(s) RSTRING(s)->len |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
100 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
101 #ifndef RSTRING_PTR |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
102 # define RSTRING_PTR(s) RSTRING(s)->ptr |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
103 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
104 |
7 | 105 #include "vim.h" |
106 #include "version.h" | |
107 | |
108 #if defined(PROTO) && !defined(FEAT_RUBY) | |
109 /* Define these to be able to generate the function prototypes. */ | |
110 # define VALUE int | |
111 # define RUBY_DATA_FUNC int | |
112 #endif | |
113 | |
114 static int ruby_initialized = 0; | |
115 static VALUE objtbl; | |
116 | |
117 static VALUE mVIM; | |
118 static VALUE cBuffer; | |
119 static VALUE cVimWindow; | |
120 static VALUE eDeletedBufferError; | |
121 static VALUE eDeletedWindowError; | |
122 | |
123 static int ensure_ruby_initialized(void); | |
124 static void error_print(int); | |
125 static void ruby_io_init(void); | |
126 static void ruby_vim_init(void); | |
127 | |
128 #if defined(DYNAMIC_RUBY) || defined(PROTO) | |
129 #ifdef PROTO | |
130 # define HINSTANCE int /* for generating prototypes */ | |
131 #endif | |
132 | |
133 /* | |
134 * Wrapper defines | |
135 */ | |
136 #define rb_assoc_new dll_rb_assoc_new | |
137 #define rb_cObject (*dll_rb_cObject) | |
138 #define rb_check_type dll_rb_check_type | |
139 #define rb_class_path dll_rb_class_path | |
140 #define rb_data_object_alloc dll_rb_data_object_alloc | |
141 #define rb_define_class_under dll_rb_define_class_under | |
142 #define rb_define_const dll_rb_define_const | |
143 #define rb_define_global_function dll_rb_define_global_function | |
144 #define rb_define_method dll_rb_define_method | |
145 #define rb_define_module dll_rb_define_module | |
146 #define rb_define_module_function dll_rb_define_module_function | |
147 #define rb_define_singleton_method dll_rb_define_singleton_method | |
148 #define rb_define_virtual_variable dll_rb_define_virtual_variable | |
149 #define rb_stdout (*dll_rb_stdout) | |
150 #define rb_eArgError (*dll_rb_eArgError) | |
151 #define rb_eIndexError (*dll_rb_eIndexError) | |
152 #define rb_eRuntimeError (*dll_rb_eRuntimeError) | |
153 #define rb_eStandardError (*dll_rb_eStandardError) | |
154 #define rb_eval_string_protect dll_rb_eval_string_protect | |
155 #define rb_global_variable dll_rb_global_variable | |
156 #define rb_hash_aset dll_rb_hash_aset | |
157 #define rb_hash_new dll_rb_hash_new | |
158 #define rb_inspect dll_rb_inspect | |
159 #define rb_int2inum dll_rb_int2inum | |
160 #define rb_lastline_get dll_rb_lastline_get | |
161 #define rb_lastline_set dll_rb_lastline_set | |
162 #define rb_load_protect dll_rb_load_protect | |
163 #define rb_num2long dll_rb_num2long | |
164 #define rb_num2ulong dll_rb_num2ulong | |
165 #define rb_obj_alloc dll_rb_obj_alloc | |
166 #define rb_obj_as_string dll_rb_obj_as_string | |
167 #define rb_obj_id dll_rb_obj_id | |
168 #define rb_raise dll_rb_raise | |
169 #define rb_str2cstr dll_rb_str2cstr | |
170 #define rb_str_cat dll_rb_str_cat | |
171 #define rb_str_concat dll_rb_str_concat | |
172 #define rb_str_new dll_rb_str_new | |
2200
99ba9a30755a
Various smaller changes. Updated proto files. Updated dependencies.
Bram Moolenaar <bram@vim.org>
parents:
2121
diff
changeset
|
173 /* Ruby may also define rb_str_new2. */ |
99ba9a30755a
Various smaller changes. Updated proto files. Updated dependencies.
Bram Moolenaar <bram@vim.org>
parents:
2121
diff
changeset
|
174 #ifndef rb_str_new2 |
99ba9a30755a
Various smaller changes. Updated proto files. Updated dependencies.
Bram Moolenaar <bram@vim.org>
parents:
2121
diff
changeset
|
175 # define rb_str_new2 dll_rb_str_new2 |
99ba9a30755a
Various smaller changes. Updated proto files. Updated dependencies.
Bram Moolenaar <bram@vim.org>
parents:
2121
diff
changeset
|
176 #endif |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
177 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
178 # define rb_string_value_ptr dll_rb_string_value_ptr |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
179 # define rb_float_new dll_rb_float_new |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
180 # define rb_ary_new dll_rb_ary_new |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
181 # define rb_ary_push dll_rb_ary_push |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
182 #endif |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
183 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
184 # define rb_errinfo dll_rb_errinfo |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
185 #else |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
186 # define ruby_errinfo (*dll_ruby_errinfo) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
187 #endif |
7 | 188 #define ruby_init dll_ruby_init |
189 #define ruby_init_loadpath dll_ruby_init_loadpath | |
2076
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
190 #define NtInitialize dll_NtInitialize |
7 | 191 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
192 # define rb_w32_snprintf dll_rb_w32_snprintf | |
193 #endif | |
194 | |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
195 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
196 # define ruby_script dll_ruby_script |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
197 # define rb_enc_find_index dll_rb_enc_find_index |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
198 # define rb_enc_find dll_rb_enc_find |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
199 # define rb_enc_str_new dll_rb_enc_str_new |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
200 # define rb_sprintf dll_rb_sprintf |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
201 # define ruby_init_stack dll_ruby_init_stack |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
202 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
203 |
7 | 204 /* |
205 * Pointers for dynamic link | |
206 */ | |
207 static VALUE (*dll_rb_assoc_new) (VALUE, VALUE); | |
208 static VALUE *dll_rb_cFalseClass; | |
209 static VALUE *dll_rb_cFixnum; | |
210 static VALUE *dll_rb_cNilClass; | |
211 static VALUE *dll_rb_cObject; | |
212 static VALUE *dll_rb_cSymbol; | |
213 static VALUE *dll_rb_cTrueClass; | |
214 static void (*dll_rb_check_type) (VALUE,int); | |
215 static VALUE (*dll_rb_class_path) (VALUE); | |
216 static VALUE (*dll_rb_data_object_alloc) (VALUE, void*, RUBY_DATA_FUNC, RUBY_DATA_FUNC); | |
217 static VALUE (*dll_rb_define_class_under) (VALUE, const char*, VALUE); | |
218 static void (*dll_rb_define_const) (VALUE,const char*,VALUE); | |
219 static void (*dll_rb_define_global_function) (const char*,VALUE(*)(),int); | |
220 static void (*dll_rb_define_method) (VALUE,const char*,VALUE(*)(),int); | |
221 static VALUE (*dll_rb_define_module) (const char*); | |
222 static void (*dll_rb_define_module_function) (VALUE,const char*,VALUE(*)(),int); | |
223 static void (*dll_rb_define_singleton_method) (VALUE,const char*,VALUE(*)(),int); | |
224 static void (*dll_rb_define_virtual_variable) (const char*,VALUE(*)(),void(*)()); | |
225 static VALUE *dll_rb_stdout; | |
226 static VALUE *dll_rb_eArgError; | |
227 static VALUE *dll_rb_eIndexError; | |
228 static VALUE *dll_rb_eRuntimeError; | |
229 static VALUE *dll_rb_eStandardError; | |
230 static VALUE (*dll_rb_eval_string_protect) (const char*, int*); | |
231 static void (*dll_rb_global_variable) (VALUE*); | |
232 static VALUE (*dll_rb_hash_aset) (VALUE, VALUE, VALUE); | |
233 static VALUE (*dll_rb_hash_new) (void); | |
234 static VALUE (*dll_rb_inspect) (VALUE); | |
235 static VALUE (*dll_rb_int2inum) (long); | |
236 static VALUE (*dll_rb_int2inum) (long); | |
237 static VALUE (*dll_rb_lastline_get) (void); | |
238 static void (*dll_rb_lastline_set) (VALUE); | |
239 static void (*dll_rb_load_protect) (VALUE, int, int*); | |
240 static long (*dll_rb_num2long) (VALUE); | |
241 static unsigned long (*dll_rb_num2ulong) (VALUE); | |
242 static VALUE (*dll_rb_obj_alloc) (VALUE); | |
243 static VALUE (*dll_rb_obj_as_string) (VALUE); | |
244 static VALUE (*dll_rb_obj_id) (VALUE); | |
245 static void (*dll_rb_raise) (VALUE, const char*, ...); | |
246 static char *(*dll_rb_str2cstr) (VALUE,int*); | |
247 static VALUE (*dll_rb_str_cat) (VALUE, const char*, long); | |
248 static VALUE (*dll_rb_str_concat) (VALUE, VALUE); | |
249 static VALUE (*dll_rb_str_new) (const char*, long); | |
250 static VALUE (*dll_rb_str_new2) (const char*); | |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
251 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
252 static VALUE (*dll_rb_errinfo) (void); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
253 #else |
7 | 254 static VALUE *dll_ruby_errinfo; |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
255 #endif |
7 | 256 static void (*dll_ruby_init) (void); |
257 static void (*dll_ruby_init_loadpath) (void); | |
2076
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
258 static void (*dll_NtInitialize) (int*, char***); |
7 | 259 #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
|
260 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
|
261 static VALUE (*dll_rb_float_new) (double); |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
262 static VALUE (*dll_rb_ary_new) (void); |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
263 static VALUE (*dll_rb_ary_push) (VALUE, VALUE); |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
264 #endif |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
265 #ifdef RUBY19_OR_LATER |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
266 static VALUE (*dll_rb_int2big)(SIGNED_VALUE); |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
267 #endif |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
268 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
7 | 269 static int (*dll_rb_w32_snprintf)(char*, size_t, const char*, ...); |
270 #endif | |
271 | |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
272 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
273 static void (*dll_ruby_script) (const char*); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 static VALUE (*dll_rb_sprintf) (const char*, ...); |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
278 static void (*ruby_init_stack)(VALUE*); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
279 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
280 |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
281 #ifdef RUBY19_OR_LATER |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
282 static SIGNED_VALUE rb_num2long_stub(VALUE x) |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
283 { |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
284 return dll_rb_num2long(x); |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
285 } |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
286 static VALUE rb_int2big_stub(SIGNED_VALUE x) |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
287 { |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
288 return dll_rb_int2big(x); |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
289 } |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
290 #endif |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
291 |
7 | 292 static HINSTANCE hinstRuby = 0; /* Instance of ruby.dll */ |
293 | |
294 /* | |
501 | 295 * Table of name to function pointer of ruby. |
7 | 296 */ |
297 #define RUBY_PROC FARPROC | |
298 static struct | |
299 { | |
300 char *name; | |
301 RUBY_PROC *ptr; | |
302 } ruby_funcname_table[] = | |
303 { | |
304 {"rb_assoc_new", (RUBY_PROC*)&dll_rb_assoc_new}, | |
305 {"rb_cFalseClass", (RUBY_PROC*)&dll_rb_cFalseClass}, | |
306 {"rb_cFixnum", (RUBY_PROC*)&dll_rb_cFixnum}, | |
307 {"rb_cNilClass", (RUBY_PROC*)&dll_rb_cNilClass}, | |
308 {"rb_cObject", (RUBY_PROC*)&dll_rb_cObject}, | |
309 {"rb_cSymbol", (RUBY_PROC*)&dll_rb_cSymbol}, | |
310 {"rb_cTrueClass", (RUBY_PROC*)&dll_rb_cTrueClass}, | |
311 {"rb_check_type", (RUBY_PROC*)&dll_rb_check_type}, | |
312 {"rb_class_path", (RUBY_PROC*)&dll_rb_class_path}, | |
313 {"rb_data_object_alloc", (RUBY_PROC*)&dll_rb_data_object_alloc}, | |
314 {"rb_define_class_under", (RUBY_PROC*)&dll_rb_define_class_under}, | |
315 {"rb_define_const", (RUBY_PROC*)&dll_rb_define_const}, | |
316 {"rb_define_global_function", (RUBY_PROC*)&dll_rb_define_global_function}, | |
317 {"rb_define_method", (RUBY_PROC*)&dll_rb_define_method}, | |
318 {"rb_define_module", (RUBY_PROC*)&dll_rb_define_module}, | |
319 {"rb_define_module_function", (RUBY_PROC*)&dll_rb_define_module_function}, | |
320 {"rb_define_singleton_method", (RUBY_PROC*)&dll_rb_define_singleton_method}, | |
321 {"rb_define_virtual_variable", (RUBY_PROC*)&dll_rb_define_virtual_variable}, | |
322 {"rb_stdout", (RUBY_PROC*)&dll_rb_stdout}, | |
323 {"rb_eArgError", (RUBY_PROC*)&dll_rb_eArgError}, | |
324 {"rb_eIndexError", (RUBY_PROC*)&dll_rb_eIndexError}, | |
325 {"rb_eRuntimeError", (RUBY_PROC*)&dll_rb_eRuntimeError}, | |
326 {"rb_eStandardError", (RUBY_PROC*)&dll_rb_eStandardError}, | |
327 {"rb_eval_string_protect", (RUBY_PROC*)&dll_rb_eval_string_protect}, | |
328 {"rb_global_variable", (RUBY_PROC*)&dll_rb_global_variable}, | |
329 {"rb_hash_aset", (RUBY_PROC*)&dll_rb_hash_aset}, | |
330 {"rb_hash_new", (RUBY_PROC*)&dll_rb_hash_new}, | |
331 {"rb_inspect", (RUBY_PROC*)&dll_rb_inspect}, | |
332 {"rb_int2inum", (RUBY_PROC*)&dll_rb_int2inum}, | |
333 {"rb_lastline_get", (RUBY_PROC*)&dll_rb_lastline_get}, | |
334 {"rb_lastline_set", (RUBY_PROC*)&dll_rb_lastline_set}, | |
335 {"rb_load_protect", (RUBY_PROC*)&dll_rb_load_protect}, | |
336 {"rb_num2long", (RUBY_PROC*)&dll_rb_num2long}, | |
337 {"rb_num2ulong", (RUBY_PROC*)&dll_rb_num2ulong}, | |
338 {"rb_obj_alloc", (RUBY_PROC*)&dll_rb_obj_alloc}, | |
339 {"rb_obj_as_string", (RUBY_PROC*)&dll_rb_obj_as_string}, | |
340 {"rb_obj_id", (RUBY_PROC*)&dll_rb_obj_id}, | |
341 {"rb_raise", (RUBY_PROC*)&dll_rb_raise}, | |
342 {"rb_str2cstr", (RUBY_PROC*)&dll_rb_str2cstr}, | |
343 {"rb_str_cat", (RUBY_PROC*)&dll_rb_str_cat}, | |
344 {"rb_str_concat", (RUBY_PROC*)&dll_rb_str_concat}, | |
345 {"rb_str_new", (RUBY_PROC*)&dll_rb_str_new}, | |
346 {"rb_str_new2", (RUBY_PROC*)&dll_rb_str_new2}, | |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
347 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
348 {"rb_errinfo", (RUBY_PROC*)&dll_rb_errinfo}, |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
349 #else |
7 | 350 {"ruby_errinfo", (RUBY_PROC*)&dll_ruby_errinfo}, |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
351 #endif |
7 | 352 {"ruby_init", (RUBY_PROC*)&dll_ruby_init}, |
353 {"ruby_init_loadpath", (RUBY_PROC*)&dll_ruby_init_loadpath}, | |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
354 { |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
355 #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
|
356 "NtInitialize", |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
357 #else |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
358 "ruby_sysinit", |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
359 #endif |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
360 (RUBY_PROC*)&dll_NtInitialize}, |
7 | 361 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
362 {"rb_w32_snprintf", (RUBY_PROC*)&dll_rb_w32_snprintf}, | |
363 #endif | |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
364 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
365 {"rb_string_value_ptr", (RUBY_PROC*)&dll_rb_string_value_ptr}, |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
366 {"rb_float_new", (RUBY_PROC*)&dll_rb_float_new}, |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
367 {"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
|
368 {"rb_ary_push", (RUBY_PROC*)&dll_rb_ary_push}, |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
369 #endif |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
370 #ifdef RUBY19_OR_LATER |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
371 {"rb_int2big", (RUBY_PROC*)&dll_rb_int2big}, |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
372 {"ruby_script", (RUBY_PROC*)&dll_ruby_script}, |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
373 {"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
|
374 {"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
|
375 {"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
|
376 {"rb_sprintf", (RUBY_PROC*)&dll_rb_sprintf}, |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
377 {"ruby_init_stack", (RUBY_PROC*)&dll_ruby_init_stack}, |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
378 #endif |
7 | 379 {"", NULL}, |
380 }; | |
381 | |
382 /* | |
383 * Free ruby.dll | |
384 */ | |
385 static void | |
386 end_dynamic_ruby() | |
387 { | |
388 if (hinstRuby) | |
389 { | |
390 FreeLibrary(hinstRuby); | |
391 hinstRuby = 0; | |
392 } | |
393 } | |
394 | |
395 /* | |
396 * Load library and get all pointers. | |
397 * Parameter 'libname' provides name of DLL. | |
398 * Return OK or FAIL. | |
399 */ | |
400 static int | |
401 ruby_runtime_link_init(char *libname, int verbose) | |
402 { | |
403 int i; | |
404 | |
405 if (hinstRuby) | |
406 return OK; | |
407 hinstRuby = LoadLibrary(libname); | |
408 if (!hinstRuby) | |
409 { | |
410 if (verbose) | |
411 EMSG2(_(e_loadlib), libname); | |
412 return FAIL; | |
413 } | |
414 | |
415 for (i = 0; ruby_funcname_table[i].ptr; ++i) | |
416 { | |
417 if (!(*ruby_funcname_table[i].ptr = GetProcAddress(hinstRuby, | |
418 ruby_funcname_table[i].name))) | |
419 { | |
420 FreeLibrary(hinstRuby); | |
421 hinstRuby = 0; | |
422 if (verbose) | |
423 EMSG2(_(e_loadfunc), ruby_funcname_table[i].name); | |
424 return FAIL; | |
425 } | |
426 } | |
427 return OK; | |
428 } | |
429 | |
430 /* | |
431 * If ruby is enabled (there is installed ruby on Windows system) return TRUE, | |
432 * else FALSE. | |
433 */ | |
434 int | |
435 ruby_enabled(verbose) | |
436 int verbose; | |
437 { | |
438 return ruby_runtime_link_init(DYNAMIC_RUBY_DLL, verbose) == OK; | |
439 } | |
440 #endif /* defined(DYNAMIC_RUBY) || defined(PROTO) */ | |
441 | |
442 void | |
443 ruby_end() | |
444 { | |
445 #ifdef DYNAMIC_RUBY | |
446 end_dynamic_ruby(); | |
447 #endif | |
448 } | |
449 | |
450 void ex_ruby(exarg_T *eap) | |
451 { | |
452 int state; | |
453 char *script = NULL; | |
454 | |
750 | 455 script = (char *)script_get(eap, eap->arg); |
7 | 456 if (!eap->skip && ensure_ruby_initialized()) |
457 { | |
458 if (script == NULL) | |
459 rb_eval_string_protect((char *)eap->arg, &state); | |
460 else | |
461 rb_eval_string_protect(script, &state); | |
462 if (state) | |
463 error_print(state); | |
464 } | |
465 vim_free(script); | |
466 } | |
467 | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
468 /* |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
469 * 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
|
470 * 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
|
471 * VIM encoding option. |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
472 */ |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
473 static VALUE |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
474 vim_str2rb_enc_str(const char *s) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
475 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
476 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
477 int isnum; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
478 long lval; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
479 char_u *sval; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
480 rb_encoding *enc; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
481 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
482 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
|
483 if (isnum == 0) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
484 { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
485 enc = rb_enc_find((char *)sval); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
486 vim_free(sval); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
487 if (enc) { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
488 return rb_enc_str_new(s, strlen(s), enc); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
489 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
490 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
491 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
492 return rb_str_new2(s); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
493 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
494 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
495 static VALUE |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
496 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
|
497 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
498 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
499 int isnum; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
500 long lval; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
501 char_u *sval; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
502 rb_encoding *enc; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
503 VALUE v; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
504 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
505 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
|
506 if (isnum == 0) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
507 { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
508 enc = rb_enc_find((char *)sval); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
509 vim_free(sval); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
510 if (enc) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
511 { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
512 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
|
513 return rb_eval_string_protect(StringValuePtr(v), state); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
514 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
515 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
516 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
517 return rb_eval_string_protect(str, state); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
518 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
519 |
7 | 520 void ex_rubydo(exarg_T *eap) |
521 { | |
522 int state; | |
523 linenr_T i; | |
524 | |
525 if (ensure_ruby_initialized()) | |
526 { | |
527 if (u_save(eap->line1 - 1, eap->line2 + 1) != OK) | |
528 return; | |
529 for (i = eap->line1; i <= eap->line2; i++) { | |
530 VALUE line, oldline; | |
531 | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
532 line = oldline = vim_str2rb_enc_str((char *)ml_get(i)); |
7 | 533 rb_lastline_set(line); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
534 eval_enc_string_protect((char *) eap->arg, &state); |
7 | 535 if (state) { |
536 error_print(state); | |
537 break; | |
538 } | |
539 line = rb_lastline_get(); | |
540 if (!NIL_P(line)) { | |
541 if (TYPE(line) != T_STRING) { | |
835 | 542 EMSG(_("E265: $_ must be an instance of String")); |
7 | 543 return; |
544 } | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
545 ml_replace(i, (char_u *) StringValuePtr(line), 1); |
7 | 546 changed(); |
547 #ifdef SYNTAX_HL | |
548 syn_changed(i); /* recompute syntax hl. for this line */ | |
549 #endif | |
550 } | |
551 } | |
552 check_cursor(); | |
553 update_curbuf(NOT_VALID); | |
554 } | |
555 } | |
556 | |
557 void ex_rubyfile(exarg_T *eap) | |
558 { | |
559 int state; | |
560 | |
561 if (ensure_ruby_initialized()) | |
562 { | |
563 rb_load_protect(rb_str_new2((char *) eap->arg), 0, &state); | |
564 if (state) error_print(state); | |
565 } | |
566 } | |
567 | |
568 void ruby_buffer_free(buf_T *buf) | |
569 { | |
502 | 570 if (buf->b_ruby_ref) |
571 { | |
572 rb_hash_aset(objtbl, rb_obj_id((VALUE) buf->b_ruby_ref), Qnil); | |
573 RDATA(buf->b_ruby_ref)->data = NULL; | |
7 | 574 } |
575 } | |
576 | |
577 void ruby_window_free(win_T *win) | |
578 { | |
502 | 579 if (win->w_ruby_ref) |
580 { | |
581 rb_hash_aset(objtbl, rb_obj_id((VALUE) win->w_ruby_ref), Qnil); | |
582 RDATA(win->w_ruby_ref)->data = NULL; | |
7 | 583 } |
584 } | |
585 | |
586 static int ensure_ruby_initialized(void) | |
587 { | |
588 if (!ruby_initialized) | |
589 { | |
590 #ifdef DYNAMIC_RUBY | |
591 if (ruby_enabled(TRUE)) | |
592 { | |
593 #endif | |
2076
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
594 #ifdef _WIN32 |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
595 /* suggested by Ariya Mizutani */ |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
596 int argc = 1; |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
597 char *argv[] = {"gvim.exe"}; |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
598 NtInitialize(&argc, &argv); |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
599 #endif |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
600 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
601 RUBY_INIT_STACK; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
602 #endif |
7 | 603 ruby_init(); |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
604 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
605 ruby_script("vim-ruby"); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
606 #endif |
7 | 607 ruby_init_loadpath(); |
608 ruby_io_init(); | |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
609 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
610 rb_enc_find_index("encdb"); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
611 #endif |
7 | 612 ruby_vim_init(); |
613 ruby_initialized = 1; | |
614 #ifdef DYNAMIC_RUBY | |
615 } | |
616 else | |
617 { | |
618 EMSG(_("E266: Sorry, this command is disabled, the Ruby library could not be loaded.")); | |
619 return 0; | |
620 } | |
621 #endif | |
622 } | |
623 return ruby_initialized; | |
624 } | |
625 | |
626 static void error_print(int state) | |
627 { | |
628 #ifndef DYNAMIC_RUBY | |
2104
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
629 #if !(defined(RUBY_VERSION) && RUBY_VERSION >= 19) \ |
09cc86b66653
updated for version 7.2.387
Bram Moolenaar <bram@zimbu.org>
parents:
2090
diff
changeset
|
630 && !(defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19) |
7 | 631 RUBYEXTERN VALUE ruby_errinfo; |
632 #endif | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
633 #endif |
7 | 634 VALUE eclass; |
635 VALUE einfo; | |
636 char buff[BUFSIZ]; | |
637 | |
638 #define TAG_RETURN 0x1 | |
639 #define TAG_BREAK 0x2 | |
640 #define TAG_NEXT 0x3 | |
641 #define TAG_RETRY 0x4 | |
642 #define TAG_REDO 0x5 | |
643 #define TAG_RAISE 0x6 | |
644 #define TAG_THROW 0x7 | |
645 #define TAG_FATAL 0x8 | |
646 #define TAG_MASK 0xf | |
647 | |
648 switch (state) { | |
649 case TAG_RETURN: | |
835 | 650 EMSG(_("E267: unexpected return")); |
7 | 651 break; |
652 case TAG_NEXT: | |
835 | 653 EMSG(_("E268: unexpected next")); |
7 | 654 break; |
655 case TAG_BREAK: | |
835 | 656 EMSG(_("E269: unexpected break")); |
7 | 657 break; |
658 case TAG_REDO: | |
835 | 659 EMSG(_("E270: unexpected redo")); |
7 | 660 break; |
661 case TAG_RETRY: | |
835 | 662 EMSG(_("E271: retry outside of rescue clause")); |
7 | 663 break; |
664 case TAG_RAISE: | |
665 case TAG_FATAL: | |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
666 #ifdef RUBY19_OR_LATER |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
667 eclass = CLASS_OF(rb_errinfo()); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
668 einfo = rb_obj_as_string(rb_errinfo()); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
669 #else |
7 | 670 eclass = CLASS_OF(ruby_errinfo); |
671 einfo = rb_obj_as_string(ruby_errinfo); | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
672 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
673 if (eclass == rb_eRuntimeError && RSTRING_LEN(einfo) == 0) { |
835 | 674 EMSG(_("E272: unhandled exception")); |
7 | 675 } |
676 else { | |
677 VALUE epath; | |
678 char *p; | |
679 | |
680 epath = rb_class_path(eclass); | |
272 | 681 vim_snprintf(buff, BUFSIZ, "%s: %s", |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
682 RSTRING_PTR(epath), RSTRING_PTR(einfo)); |
7 | 683 p = strchr(buff, '\n'); |
684 if (p) *p = '\0'; | |
685 EMSG(buff); | |
686 } | |
687 break; | |
688 default: | |
272 | 689 vim_snprintf(buff, BUFSIZ, _("E273: unknown longjmp status %d"), state); |
7 | 690 EMSG(buff); |
691 break; | |
692 } | |
693 } | |
694 | |
1888 | 695 static VALUE vim_message(VALUE self UNUSED, VALUE str) |
7 | 696 { |
697 char *buff, *p; | |
698 | |
699 str = rb_obj_as_string(str); | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
700 buff = ALLOCA_N(char, RSTRING_LEN(str)); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
701 strcpy(buff, RSTRING_PTR(str)); |
7 | 702 p = strchr(buff, '\n'); |
703 if (p) *p = '\0'; | |
704 MSG(buff); | |
705 return Qnil; | |
706 } | |
707 | |
1888 | 708 static VALUE vim_set_option(VALUE self UNUSED, VALUE str) |
7 | 709 { |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
710 do_set((char_u *)StringValuePtr(str), 0); |
7 | 711 update_screen(NOT_VALID); |
712 return Qnil; | |
713 } | |
714 | |
1888 | 715 static VALUE vim_command(VALUE self UNUSED, VALUE str) |
7 | 716 { |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
717 do_cmdline_cmd((char_u *)StringValuePtr(str)); |
7 | 718 return Qnil; |
719 } | |
720 | |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
721 #ifdef FEAT_EVAL |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
722 static VALUE vim_to_ruby(typval_T *tv) |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
723 { |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
724 VALUE result = Qnil; |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
725 |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
726 if (tv->v_type == VAR_STRING) |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
727 { |
2121
20d9fc2f13a4
updated for version 7.2.403
Bram Moolenaar <bram@zimbu.org>
parents:
2117
diff
changeset
|
728 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
|
729 ? "" : (char *)(tv->vval.v_string)); |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
730 } |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
731 else if (tv->v_type == VAR_NUMBER) |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
732 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
733 result = INT2NUM(tv->vval.v_number); |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
734 } |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
735 # ifdef FEAT_FLOAT |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
736 else if (tv->v_type == VAR_FLOAT) |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
737 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
738 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
|
739 } |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
740 # endif |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
741 else if (tv->v_type == VAR_LIST) |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
742 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
743 list_T *list = tv->vval.v_list; |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
744 listitem_T *curr; |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
745 |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
746 result = rb_ary_new(); |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
747 |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
748 if (list != NULL) |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
749 { |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
750 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
|
751 { |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
752 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
|
753 } |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
754 } |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
755 } |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
756 else if (tv->v_type == VAR_DICT) |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
757 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
758 result = rb_hash_new(); |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
759 |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
760 if (tv->vval.v_dict != NULL) |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
761 { |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
762 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
|
763 long_u todo = ht->ht_used; |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
764 hashitem_T *hi; |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
765 dictitem_T *di; |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
766 |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
767 for (hi = ht->ht_array; todo > 0; ++hi) |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
768 { |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
769 if (!HASHITEM_EMPTY(hi)) |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
770 { |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
771 --todo; |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
772 |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
773 di = dict_lookup(hi); |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
774 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
|
775 vim_to_ruby(&di->di_tv)); |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
776 } |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
777 } |
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
778 } |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
779 } /* else return Qnil; */ |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
780 |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
781 return result; |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
782 } |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
783 #endif |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
784 |
1888 | 785 static VALUE vim_evaluate(VALUE self UNUSED, VALUE str) |
7 | 786 { |
787 #ifdef FEAT_EVAL | |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
788 typval_T *tv; |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
789 VALUE result; |
7 | 790 |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
791 tv = eval_expr((char_u *)StringValuePtr(str), NULL); |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
792 if (tv == NULL) |
7 | 793 { |
2117
4be6da0fa3d9
updated for version 7.2.400
Bram Moolenaar <bram@zimbu.org>
parents:
2104
diff
changeset
|
794 return Qnil; |
7 | 795 } |
2090
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
796 result = vim_to_ruby(tv); |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
797 |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
798 free_tv(tv); |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
799 |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
800 return result; |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
801 #else |
53d475dff0e3
updated for version 7.2.374
Bram Moolenaar <bram@zimbu.org>
parents:
2084
diff
changeset
|
802 return Qnil; |
7 | 803 #endif |
804 } | |
805 | |
806 static VALUE buffer_new(buf_T *buf) | |
807 { | |
502 | 808 if (buf->b_ruby_ref) |
809 { | |
810 return (VALUE) buf->b_ruby_ref; | |
7 | 811 } |
502 | 812 else |
813 { | |
7 | 814 VALUE obj = Data_Wrap_Struct(cBuffer, 0, 0, buf); |
502 | 815 buf->b_ruby_ref = (void *) obj; |
7 | 816 rb_hash_aset(objtbl, rb_obj_id(obj), obj); |
817 return obj; | |
818 } | |
819 } | |
820 | |
821 static buf_T *get_buf(VALUE obj) | |
822 { | |
823 buf_T *buf; | |
824 | |
825 Data_Get_Struct(obj, buf_T, buf); | |
826 if (buf == NULL) | |
827 rb_raise(eDeletedBufferError, "attempt to refer to deleted buffer"); | |
828 return buf; | |
829 } | |
830 | |
831 static VALUE buffer_s_current() | |
832 { | |
833 return buffer_new(curbuf); | |
834 } | |
835 | |
836 static VALUE buffer_s_count() | |
837 { | |
838 buf_T *b; | |
839 int n = 0; | |
840 | |
779 | 841 for (b = firstbuf; b != NULL; b = b->b_next) |
842 { | |
856 | 843 /* Deleted buffers should not be counted |
844 * SegPhault - 01/07/05 */ | |
845 if (b->b_p_bl) | |
779 | 846 n++; |
847 } | |
848 | |
7 | 849 return INT2NUM(n); |
850 } | |
851 | |
1888 | 852 static VALUE buffer_s_aref(VALUE self UNUSED, VALUE num) |
7 | 853 { |
854 buf_T *b; | |
855 int n = NUM2INT(num); | |
856 | |
779 | 857 for (b = firstbuf; b != NULL; b = b->b_next) |
858 { | |
856 | 859 /* Deleted buffers should not be counted |
860 * SegPhault - 01/07/05 */ | |
861 if (!b->b_p_bl) | |
779 | 862 continue; |
863 | |
856 | 864 if (n == 0) |
7 | 865 return buffer_new(b); |
779 | 866 |
856 | 867 n--; |
7 | 868 } |
869 return Qnil; | |
870 } | |
871 | |
872 static VALUE buffer_name(VALUE self) | |
873 { | |
874 buf_T *buf = get_buf(self); | |
875 | |
750 | 876 return buf->b_ffname ? rb_str_new2((char *)buf->b_ffname) : Qnil; |
7 | 877 } |
878 | |
879 static VALUE buffer_number(VALUE self) | |
880 { | |
881 buf_T *buf = get_buf(self); | |
882 | |
883 return INT2NUM(buf->b_fnum); | |
884 } | |
885 | |
886 static VALUE buffer_count(VALUE self) | |
887 { | |
888 buf_T *buf = get_buf(self); | |
889 | |
890 return INT2NUM(buf->b_ml.ml_line_count); | |
891 } | |
892 | |
779 | 893 static VALUE get_buffer_line(buf_T *buf, linenr_T n) |
7 | 894 { |
779 | 895 if (n > 0 && n <= buf->b_ml.ml_line_count) |
896 { | |
750 | 897 char *line = (char *)ml_get_buf(buf, n, FALSE); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
898 return line ? vim_str2rb_enc_str(line) : Qnil; |
7 | 899 } |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
900 rb_raise(rb_eIndexError, "line number %ld out of range", (long)n); |
1888 | 901 #ifndef __GNUC__ |
779 | 902 return Qnil; /* For stop warning */ |
1888 | 903 #endif |
7 | 904 } |
905 | |
779 | 906 static VALUE buffer_aref(VALUE self, VALUE num) |
7 | 907 { |
908 buf_T *buf = get_buf(self); | |
779 | 909 |
910 if (buf != NULL) | |
911 return get_buffer_line(buf, (linenr_T)NUM2LONG(num)); | |
912 return Qnil; /* For stop warning */ | |
913 } | |
914 | |
915 static VALUE set_buffer_line(buf_T *buf, linenr_T n, VALUE str) | |
916 { | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
917 char *line = StringValuePtr(str); |
896 | 918 aco_save_T aco; |
7 | 919 |
896 | 920 if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL) |
921 { | |
922 /* set curwin/curbuf for "buf" and save some things */ | |
923 aucmd_prepbuf(&aco, buf); | |
924 | |
7 | 925 if (u_savesub(n) == OK) { |
779 | 926 ml_replace(n, (char_u *)line, TRUE); |
7 | 927 changed(); |
928 #ifdef SYNTAX_HL | |
929 syn_changed(n); /* recompute syntax hl. for this line */ | |
930 #endif | |
931 } | |
896 | 932 |
933 /* restore curwin/curbuf and a few other things */ | |
934 aucmd_restbuf(&aco); | |
935 /* Careful: autocommands may have made "buf" invalid! */ | |
934 | 936 |
7 | 937 update_curbuf(NOT_VALID); |
938 } | |
896 | 939 else |
940 { | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
941 rb_raise(rb_eIndexError, "line number %ld out of range", (long)n); |
1888 | 942 #ifndef __GNUC__ |
7 | 943 return Qnil; /* For stop warning */ |
1888 | 944 #endif |
7 | 945 } |
946 return str; | |
947 } | |
948 | |
779 | 949 static VALUE buffer_aset(VALUE self, VALUE num, VALUE str) |
950 { | |
951 buf_T *buf = get_buf(self); | |
952 | |
953 if (buf != NULL) | |
954 return set_buffer_line(buf, (linenr_T)NUM2LONG(num), str); | |
955 return str; | |
956 } | |
957 | |
7 | 958 static VALUE buffer_delete(VALUE self, VALUE num) |
959 { | |
896 | 960 buf_T *buf = get_buf(self); |
961 long n = NUM2LONG(num); | |
962 aco_save_T aco; | |
7 | 963 |
896 | 964 if (n > 0 && n <= buf->b_ml.ml_line_count) |
965 { | |
966 /* set curwin/curbuf for "buf" and save some things */ | |
967 aucmd_prepbuf(&aco, buf); | |
968 | |
7 | 969 if (u_savedel(n, 1) == OK) { |
970 ml_delete(n, 0); | |
779 | 971 |
856 | 972 /* Changes to non-active buffers should properly refresh |
973 * SegPhault - 01/09/05 */ | |
974 deleted_lines_mark(n, 1L); | |
779 | 975 |
7 | 976 changed(); |
977 } | |
896 | 978 |
979 /* restore curwin/curbuf and a few other things */ | |
980 aucmd_restbuf(&aco); | |
981 /* Careful: autocommands may have made "buf" invalid! */ | |
934 | 982 |
7 | 983 update_curbuf(NOT_VALID); |
984 } | |
896 | 985 else |
986 { | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
987 rb_raise(rb_eIndexError, "line number %ld out of range", n); |
7 | 988 } |
989 return Qnil; | |
990 } | |
991 | |
992 static VALUE buffer_append(VALUE self, VALUE num, VALUE str) | |
993 { | |
896 | 994 buf_T *buf = get_buf(self); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
995 char *line = StringValuePtr(str); |
896 | 996 long n = NUM2LONG(num); |
997 aco_save_T aco; | |
7 | 998 |
2084
4bac7ed34007
updated for version 7.2.368
Bram Moolenaar <bram@zimbu.org>
parents:
2077
diff
changeset
|
999 if (line == NULL) { |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1000 rb_raise(rb_eIndexError, "NULL line"); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1001 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1002 else if (n >= 0 && n <= buf->b_ml.ml_line_count) |
896 | 1003 { |
1004 /* set curwin/curbuf for "buf" and save some things */ | |
1005 aucmd_prepbuf(&aco, buf); | |
1006 | |
7 | 1007 if (u_inssub(n + 1) == OK) { |
1008 ml_append(n, (char_u *) line, (colnr_T) 0, FALSE); | |
779 | 1009 |
856 | 1010 /* Changes to non-active buffers should properly refresh screen |
1011 * SegPhault - 12/20/04 */ | |
1012 appended_lines_mark(n, 1L); | |
779 | 1013 |
856 | 1014 changed(); |
7 | 1015 } |
896 | 1016 |
1017 /* restore curwin/curbuf and a few other things */ | |
1018 aucmd_restbuf(&aco); | |
1019 /* Careful: autocommands may have made "buf" invalid! */ | |
934 | 1020 |
7 | 1021 update_curbuf(NOT_VALID); |
1022 } | |
1023 else { | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1024 rb_raise(rb_eIndexError, "line number %ld out of range", n); |
7 | 1025 } |
1026 return str; | |
1027 } | |
1028 | |
1029 static VALUE window_new(win_T *win) | |
1030 { | |
502 | 1031 if (win->w_ruby_ref) |
1032 { | |
1033 return (VALUE) win->w_ruby_ref; | |
7 | 1034 } |
502 | 1035 else |
1036 { | |
7 | 1037 VALUE obj = Data_Wrap_Struct(cVimWindow, 0, 0, win); |
502 | 1038 win->w_ruby_ref = (void *) obj; |
7 | 1039 rb_hash_aset(objtbl, rb_obj_id(obj), obj); |
1040 return obj; | |
1041 } | |
1042 } | |
1043 | |
1044 static win_T *get_win(VALUE obj) | |
1045 { | |
1046 win_T *win; | |
1047 | |
1048 Data_Get_Struct(obj, win_T, win); | |
1049 if (win == NULL) | |
1050 rb_raise(eDeletedWindowError, "attempt to refer to deleted window"); | |
1051 return win; | |
1052 } | |
1053 | |
1054 static VALUE window_s_current() | |
1055 { | |
1056 return window_new(curwin); | |
1057 } | |
1058 | |
779 | 1059 /* |
1060 * Added line manipulation functions | |
1061 * SegPhault - 03/07/05 | |
1062 */ | |
1063 static VALUE line_s_current() | |
1064 { | |
1065 return get_buffer_line(curbuf, curwin->w_cursor.lnum); | |
1066 } | |
1067 | |
1888 | 1068 static VALUE set_current_line(VALUE self UNUSED, VALUE str) |
779 | 1069 { |
1070 return set_buffer_line(curbuf, curwin->w_cursor.lnum, str); | |
1071 } | |
1072 | |
1073 static VALUE current_line_number() | |
1074 { | |
1075 return INT2FIX((int)curwin->w_cursor.lnum); | |
1076 } | |
1077 | |
1078 | |
1079 | |
7 | 1080 static VALUE window_s_count() |
1081 { | |
1082 #ifdef FEAT_WINDOWS | |
1083 win_T *w; | |
1084 int n = 0; | |
1085 | |
671 | 1086 for (w = firstwin; w != NULL; w = w->w_next) |
7 | 1087 n++; |
1088 return INT2NUM(n); | |
1089 #else | |
1090 return INT2NUM(1); | |
1091 #endif | |
1092 } | |
1093 | |
1888 | 1094 static VALUE window_s_aref(VALUE self UNUSED, VALUE num) |
7 | 1095 { |
1096 win_T *w; | |
1097 int n = NUM2INT(num); | |
1098 | |
1099 #ifndef FEAT_WINDOWS | |
1100 w = curwin; | |
1101 #else | |
1102 for (w = firstwin; w != NULL; w = w->w_next, --n) | |
1103 #endif | |
1104 if (n == 0) | |
1105 return window_new(w); | |
1106 return Qnil; | |
1107 } | |
1108 | |
1109 static VALUE window_buffer(VALUE self) | |
1110 { | |
1111 win_T *win = get_win(self); | |
1112 | |
1113 return buffer_new(win->w_buffer); | |
1114 } | |
1115 | |
1116 static VALUE window_height(VALUE self) | |
1117 { | |
1118 win_T *win = get_win(self); | |
1119 | |
1120 return INT2NUM(win->w_height); | |
1121 } | |
1122 | |
1123 static VALUE window_set_height(VALUE self, VALUE height) | |
1124 { | |
1125 win_T *win = get_win(self); | |
1126 win_T *savewin = curwin; | |
1127 | |
1128 curwin = win; | |
1129 win_setheight(NUM2INT(height)); | |
1130 curwin = savewin; | |
1131 return height; | |
1132 } | |
1133 | |
501 | 1134 static VALUE window_width(VALUE self) |
1135 { | |
1136 win_T *win = get_win(self); | |
1137 | |
1138 return INT2NUM(win->w_width); | |
1139 } | |
1140 | |
1141 static VALUE window_set_width(VALUE self, VALUE width) | |
1142 { | |
1143 win_T *win = get_win(self); | |
1144 win_T *savewin = curwin; | |
1145 | |
1146 curwin = win; | |
1147 win_setwidth(NUM2INT(width)); | |
1148 curwin = savewin; | |
1149 return width; | |
1150 } | |
1151 | |
7 | 1152 static VALUE window_cursor(VALUE self) |
1153 { | |
1154 win_T *win = get_win(self); | |
1155 | |
1156 return rb_assoc_new(INT2NUM(win->w_cursor.lnum), INT2NUM(win->w_cursor.col)); | |
1157 } | |
1158 | |
1159 static VALUE window_set_cursor(VALUE self, VALUE pos) | |
1160 { | |
1161 VALUE lnum, col; | |
1162 win_T *win = get_win(self); | |
1163 | |
1164 Check_Type(pos, T_ARRAY); | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1165 if (RARRAY_LEN(pos) != 2) |
7 | 1166 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
|
1167 lnum = RARRAY_PTR(pos)[0]; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1168 col = RARRAY_PTR(pos)[1]; |
7 | 1169 win->w_cursor.lnum = NUM2LONG(lnum); |
1170 win->w_cursor.col = NUM2UINT(col); | |
1171 check_cursor(); /* put cursor on an existing line */ | |
1172 update_screen(NOT_VALID); | |
1173 return Qnil; | |
1174 } | |
1175 | |
1888 | 1176 static VALUE f_p(int argc, VALUE *argv, VALUE self UNUSED) |
7 | 1177 { |
1178 int i; | |
1179 VALUE str = rb_str_new("", 0); | |
1180 | |
1181 for (i = 0; i < argc; i++) { | |
1182 if (i > 0) rb_str_cat(str, ", ", 2); | |
1183 rb_str_concat(str, rb_inspect(argv[i])); | |
1184 } | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1185 MSG(RSTRING_PTR(str)); |
7 | 1186 return Qnil; |
1187 } | |
1188 | |
1189 static void ruby_io_init(void) | |
1190 { | |
1191 #ifndef DYNAMIC_RUBY | |
1192 RUBYEXTERN VALUE rb_stdout; | |
1193 #endif | |
1194 | |
1195 rb_stdout = rb_obj_alloc(rb_cObject); | |
1196 rb_define_singleton_method(rb_stdout, "write", vim_message, 1); | |
1197 rb_define_global_function("p", f_p, -1); | |
1198 } | |
1199 | |
1200 static void ruby_vim_init(void) | |
1201 { | |
1202 objtbl = rb_hash_new(); | |
1203 rb_global_variable(&objtbl); | |
1204 | |
1188 | 1205 /* The Vim module used to be called "VIM", but "Vim" is better. Make an |
1206 * alias "VIM" for backwards compatiblity. */ | |
1207 mVIM = rb_define_module("Vim"); | |
1208 rb_define_const(rb_cObject, "VIM", mVIM); | |
7 | 1209 rb_define_const(mVIM, "VERSION_MAJOR", INT2NUM(VIM_VERSION_MAJOR)); |
1210 rb_define_const(mVIM, "VERSION_MINOR", INT2NUM(VIM_VERSION_MINOR)); | |
1211 rb_define_const(mVIM, "VERSION_BUILD", INT2NUM(VIM_VERSION_BUILD)); | |
1212 rb_define_const(mVIM, "VERSION_PATCHLEVEL", INT2NUM(VIM_VERSION_PATCHLEVEL)); | |
1213 rb_define_const(mVIM, "VERSION_SHORT", rb_str_new2(VIM_VERSION_SHORT)); | |
1214 rb_define_const(mVIM, "VERSION_MEDIUM", rb_str_new2(VIM_VERSION_MEDIUM)); | |
1215 rb_define_const(mVIM, "VERSION_LONG", rb_str_new2(VIM_VERSION_LONG)); | |
1216 rb_define_const(mVIM, "VERSION_LONG_DATE", rb_str_new2(VIM_VERSION_LONG_DATE)); | |
1217 rb_define_module_function(mVIM, "message", vim_message, 1); | |
1218 rb_define_module_function(mVIM, "set_option", vim_set_option, 1); | |
1219 rb_define_module_function(mVIM, "command", vim_command, 1); | |
1220 rb_define_module_function(mVIM, "evaluate", vim_evaluate, 1); | |
1221 | |
1222 eDeletedBufferError = rb_define_class_under(mVIM, "DeletedBufferError", | |
1223 rb_eStandardError); | |
1224 eDeletedWindowError = rb_define_class_under(mVIM, "DeletedWindowError", | |
1225 rb_eStandardError); | |
1226 | |
1227 cBuffer = rb_define_class_under(mVIM, "Buffer", rb_cObject); | |
1228 rb_define_singleton_method(cBuffer, "current", buffer_s_current, 0); | |
1229 rb_define_singleton_method(cBuffer, "count", buffer_s_count, 0); | |
1230 rb_define_singleton_method(cBuffer, "[]", buffer_s_aref, 1); | |
1231 rb_define_method(cBuffer, "name", buffer_name, 0); | |
1232 rb_define_method(cBuffer, "number", buffer_number, 0); | |
1233 rb_define_method(cBuffer, "count", buffer_count, 0); | |
1234 rb_define_method(cBuffer, "length", buffer_count, 0); | |
1235 rb_define_method(cBuffer, "[]", buffer_aref, 1); | |
1236 rb_define_method(cBuffer, "[]=", buffer_aset, 2); | |
1237 rb_define_method(cBuffer, "delete", buffer_delete, 1); | |
1238 rb_define_method(cBuffer, "append", buffer_append, 2); | |
1239 | |
779 | 1240 /* Added line manipulation functions |
1241 * SegPhault - 03/07/05 */ | |
1242 rb_define_method(cBuffer, "line_number", current_line_number, 0); | |
1243 rb_define_method(cBuffer, "line", line_s_current, 0); | |
1244 rb_define_method(cBuffer, "line=", set_current_line, 1); | |
1245 | |
1246 | |
7 | 1247 cVimWindow = rb_define_class_under(mVIM, "Window", rb_cObject); |
1248 rb_define_singleton_method(cVimWindow, "current", window_s_current, 0); | |
1249 rb_define_singleton_method(cVimWindow, "count", window_s_count, 0); | |
1250 rb_define_singleton_method(cVimWindow, "[]", window_s_aref, 1); | |
1251 rb_define_method(cVimWindow, "buffer", window_buffer, 0); | |
1252 rb_define_method(cVimWindow, "height", window_height, 0); | |
1253 rb_define_method(cVimWindow, "height=", window_set_height, 1); | |
501 | 1254 rb_define_method(cVimWindow, "width", window_width, 0); |
1255 rb_define_method(cVimWindow, "width=", window_set_width, 1); | |
7 | 1256 rb_define_method(cVimWindow, "cursor", window_cursor, 0); |
1257 rb_define_method(cVimWindow, "cursor=", window_set_cursor, 1); | |
1258 | |
1259 rb_define_virtual_variable("$curbuf", buffer_s_current, 0); | |
1260 rb_define_virtual_variable("$curwin", window_s_current, 0); | |
1261 } |