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