From 46c53a9e8aa032218deb6c6d62d44600575a1663 Mon Sep 17 00:00:00 2001 From: Livio Ribeiro Date: Fri, 25 Sep 2015 16:57:26 -0300 Subject: [PATCH 1/2] Add lua (luajit) to rust example --- luajit-to-rust/Cargo.toml | 8 ++++++++ luajit-to-rust/Makefile | 14 ++++++++++++++ luajit-to-rust/src/lib.rs | 4 ++++ luajit-to-rust/src/main.lua | 21 +++++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 luajit-to-rust/Cargo.toml create mode 100644 luajit-to-rust/Makefile create mode 100644 luajit-to-rust/src/lib.rs create mode 100644 luajit-to-rust/src/main.lua diff --git a/luajit-to-rust/Cargo.toml b/luajit-to-rust/Cargo.toml new file mode 100644 index 0000000..391bc50 --- /dev/null +++ b/luajit-to-rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "luajit-to-rust" +version = "0.1.0" +authors = ["Alex Crichton "] + +[lib] +name = "double_input" +crate-type = ["dylib"] diff --git a/luajit-to-rust/Makefile b/luajit-to-rust/Makefile new file mode 100644 index 0000000..bd944d3 --- /dev/null +++ b/luajit-to-rust/Makefile @@ -0,0 +1,14 @@ +ifeq ($(shell uname),Darwin) + EXT := dylib +else + EXT := so +endif + +all: target/debug/libdouble_input.$(EXT) + luajit src/main.lua + +target/debug/libdouble_input.$(EXT): src/lib.rs Cargo.toml + cargo build + +clean: + rm -rf target diff --git a/luajit-to-rust/src/lib.rs b/luajit-to-rust/src/lib.rs new file mode 100644 index 0000000..bf573d1 --- /dev/null +++ b/luajit-to-rust/src/lib.rs @@ -0,0 +1,4 @@ +#[no_mangle] +pub extern fn double_input(input: i32) -> i32 { + input * 2 +} diff --git a/luajit-to-rust/src/main.lua b/luajit-to-rust/src/main.lua new file mode 100644 index 0000000..2f512ec --- /dev/null +++ b/luajit-to-rust/src/main.lua @@ -0,0 +1,21 @@ +local ffi = require('ffi') + +local ext + +if ffi.os == 'Linux' then + ext = 'so' +else + ext = 'dylib' +end + +ffi.cdef[[ +int32_t double_input(int32_t input); +]] + +local lib = ffi.load('target/debug/libdouble_input.' .. ext) +local double_input = lib.double_input + +local input = 4 +local output = double_input(input) + +print(input .. " * 2 = " .. output) From c07ae5e9f50a79eaeba72b89ddbed07246b2a9a4 Mon Sep 17 00:00:00 2001 From: Livio Ribeiro Date: Fri, 25 Sep 2015 17:11:11 -0300 Subject: [PATCH 2/2] Fix author name in luajit example --- luajit-to-rust/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/luajit-to-rust/Cargo.toml b/luajit-to-rust/Cargo.toml index 391bc50..679f285 100644 --- a/luajit-to-rust/Cargo.toml +++ b/luajit-to-rust/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "luajit-to-rust" version = "0.1.0" -authors = ["Alex Crichton "] +# Modified based on python version +authors = ["Livio Ribeiro "] [lib] name = "double_input"