Add lua (luajit) to rust example
This commit is contained in:
4
luajit-to-rust/src/lib.rs
Normal file
4
luajit-to-rust/src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
#[no_mangle]
|
||||
pub extern fn double_input(input: i32) -> i32 {
|
||||
input * 2
|
||||
}
|
||||
21
luajit-to-rust/src/main.lua
Normal file
21
luajit-to-rust/src/main.lua
Normal 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)
|
||||
Reference in New Issue
Block a user