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