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