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