perl-to-rust
This commit is contained in:
9
perl-to-rust/Cargo.toml
Normal file
9
perl-to-rust/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "perl-to-rust"
|
||||
version = "0.1.0"
|
||||
#modified based on python version
|
||||
authors = ["Hao Wu <echowuhao@gmail.com>"]
|
||||
|
||||
[lib]
|
||||
name = "double_input"
|
||||
crate-type = ["dylib"]
|
||||
15
perl-to-rust/Makefile
Normal file
15
perl-to-rust/Makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
ifeq ($(shell uname),Darwin)
|
||||
EXT := dylib
|
||||
else
|
||||
EXT := so
|
||||
endif
|
||||
|
||||
all: target/libdouble_input.so
|
||||
perl src/main.pl
|
||||
|
||||
target/libdouble_input.so: src/lib.rs Cargo.toml
|
||||
cargo build
|
||||
(cd target && ln -nsf debug/libdouble_input-*$(EXT) libdouble_input.so)
|
||||
|
||||
clean:
|
||||
rm -rf target
|
||||
4
perl-to-rust/src/lib.rs
Normal file
4
perl-to-rust/src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
#[no_mangle]
|
||||
pub extern fn double_input(input: i32) -> i32 {
|
||||
input * 2
|
||||
}
|
||||
14
perl-to-rust/src/main.pl
Normal file
14
perl-to-rust/src/main.pl
Normal file
@@ -0,0 +1,14 @@
|
||||
use v5.10;
|
||||
use FFI::Raw;
|
||||
|
||||
my $double_input = FFI::Raw->new(
|
||||
"target/libdouble_input.so",
|
||||
'double_input',
|
||||
FFI::Raw::int, # return value
|
||||
FFI::Raw::int # arg #1
|
||||
);
|
||||
|
||||
my $input = 4;
|
||||
my $output = $double_input->call($input);
|
||||
say $input . " * 2 = " . $output;
|
||||
|
||||
Reference in New Issue
Block a user