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