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