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