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