#lua-jit #lua #calling #interfacing #wrapper #running #api

no-std tinylj

Rust crate for calling LuaJIT from Rust

3 releases

Uses old Rust 2015

0.1.3 Jun 21, 2023
0.1.2 Jun 21, 2023
0.1.1 Jun 21, 2023

#877 in Programming languages

MIT license

48KB
957 lines

TinyLJ

Github

Fork of luajit-rs

Crate for interfacing with LuaJIT from Rust, for running high-performance Lua code that can integrate with native-code written in rust.

Getting Started

use tinylj::{c_int, State, lua_fn};

fn return_42(state: &mut State) -> c_int {
    state.push(42);

    1
}

pub fn main() {
    let mut state = State::new();
    state.open_libs();
    state.do_string(r#"print("Hello world!")"#);

    state.push(lua_fn!(return_42));
    state.set_global("return_42");
    state.do_string(r#"print(return_42())"#);
}

lib.rs:

TinyLJ

tinylj is a simple wrapper around the LuaJIT project, allowing it to be called from Rust easily and with minimal overhead. Most functions in this crate correspond directly to underlying Lua C API calls

Examples

#[macro_use]
extern crate tinylj;

use tinylj::{c_int, State};

fn return_42(state: &mut State) -> c_int {
    state.push(42);

    1
}

pub fn main() {
    let mut state = State::new();
    state.open_libs();
    state.do_string(r#"print("Hello world!")"#);

    state.push(lua_fn!(return_42));
    state.set_global("return_42");
    state.do_string(r#"print(return_42())"#);
}

Dependencies

~0–1.6MB
~25K SLoC