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