Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 73e0534

Browse files
authored
Merge pull request #148 from konstin/split_out_init
Allow calling init seperately
2 parents 239f1de + 538a1c9 commit 73e0534

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,10 @@ hello
8282
hello world
8383
=> nil
8484
```
85+
86+
To run all tests in the repository, run
87+
88+
```shell
89+
rake install
90+
rake
91+
```

ruby/lib/helix_runtime/project.rb

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ def cargo_build
100100
if ENV['VERBOSE']
101101
cargo_args << " --verbose"
102102
end
103+
if ENV['CARGO_EXTRA_ARGS']
104+
cargo_args << ENV['CARGO_EXTRA_ARGS']
105+
end
103106
if link_args
104107
rustc_args << "-C link-args=#{link_args}"
105108
end

src/coercions/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ pub type ToRubyResult = Result<VALUE, Error>;
4949
pub trait ToRuby {
5050
fn to_ruby(self) -> ToRubyResult;
5151
}
52+
53+
pub trait InitRuby {
54+
fn init_ruby();
55+
}

src/macros/codegen.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,44 @@ macro_rules! codegen_method {
222222
};
223223
}
224224

225+
#[macro_export]
226+
macro_rules! codegen_ruby_init {
227+
({
228+
type: class,
229+
rust_name: $rust_name:tt,
230+
ruby_name: $ruby_name:tt,
231+
meta: { pub: $pub:tt, reopen: $reopen:tt },
232+
struct: $struct:tt,
233+
methods: $methods:tt
234+
}) => (
235+
impl $crate::InitRuby for $rust_name {
236+
fn init_ruby() {
237+
codegen_class_binding!({
238+
type: class,
239+
rust_name: $rust_name,
240+
ruby_name: $ruby_name,
241+
meta: { pub: $pub, reopen: $reopen },
242+
struct: $struct,
243+
methods: $methods
244+
}, {
245+
type: class,
246+
rust_name: $rust_name,
247+
ruby_name: $ruby_name,
248+
meta: { pub: $pub, reopen: $reopen },
249+
struct: $struct,
250+
methods: $methods
251+
});
252+
}
253+
}
254+
);
255+
}
256+
257+
225258
#[macro_export]
226259
macro_rules! codegen_extra_impls {
227260
($class:tt) => (
228261
codegen_allocator!($class);
229262
codegen_coercions!($class);
263+
codegen_ruby_init!($class);
230264
)
231-
}
265+
}

src/macros/init.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
#[macro_export]
22
macro_rules! codegen_init {
3-
{ [ $($class:tt)* ] } => {
3+
// Extracts the list of rust class names and calls the actual codegen_init with that
4+
{ [ $({
5+
type: class,
6+
rust_name: $rust_name:tt,
7+
ruby_name: { $($ruby_name:tt) * },
8+
meta: { pub: $pub:tt, reopen: $reopen:tt },
9+
struct: $struct:tt,
10+
methods: [ $($method:tt) * ]
11+
})* ] } => (
12+
codegen_init!{ [ $($rust_name)* ] }
13+
);
14+
15+
{ [ $($rust_name:tt)* ] } => {
416
#[allow(non_snake_case)]
517
#[no_mangle]
618
pub extern "C" fn Init_native() {
19+
use $crate::InitRuby;
720
$crate::sys::check_version();
821

922
$(
10-
codegen_class_binding!($class, $class);
23+
$rust_name::init_ruby();
1124
)*
1225
}
13-
}
26+
};
1427
}
1528

29+
1630
#[macro_export]
1731
macro_rules! codegen_class_binding {
1832
{ $class:tt, {

0 commit comments

Comments
 (0)