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