Add lua (luajit) to rust example

This commit is contained in:
Livio Ribeiro
2015-09-25 16:57:26 -03:00
parent 640bfb9da8
commit 46c53a9e8a
4 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
#[no_mangle]
pub extern fn double_input(input: i32) -> i32 {
input * 2
}

View File

@@ -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)