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