luajit2-sys

Crates.ioluajit2-sys
lib.rsluajit2-sys
version0.0.2
sourcesrc
created_at2020-01-19 06:48:42.566747
updated_at2020-01-19 21:26:36.127932
descriptionLuaJIT-2.1 FFI Bindings
homepage
repositoryhttps://github.com/aloucks/luajit2-sys
max_upload_size
id199979
size4,245,575
(aloucks)

documentation

https://docs.rs/luajit2-sys

README

Rust LuaJIT Bindings

crates.io docs.rs build

[dependencies]
luajit2-sys = "0.0.1"

Exported Cargo Environment Variables

DEP_LUAJIT_INCLUDE Path to the LuaJIT source and headers
DEP_LUAJIT_LIB_NAME Platform specfic lib name (lua51 on Windows and luajit everywhere else)

Example

use luajit2_sys as sys;
use std::ffi::CStr;

fn main() {
    unsafe {
        let lua = sys::luaL_newstate();
        sys::luaL_openlibs(lua);
        let script_data = b"return 1 + 2";
        let script_name = b"run_script\0";
        sys::luaL_loadbuffer(
            lua,
            script_data.as_ptr() as _,
            script_data.len() as _,
            script_name.as_ptr() as _,
        );
        sys::lua_pcall(lua, 0, 1, 0);
        let idx = sys::lua_gettop(lua);
        let s = sys::lua_tostring(lua, idx);
        let result = CStr::from_ptr(s).to_string_lossy().to_string();
        sys::lua_close(lua);

        println!("result: {}", result);
    }
}
Commit count: 23

cargo fmt