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