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