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