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