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