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