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