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