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