#lua #lua-jit

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

#562 in Programming languages

Download history 1/week @ 2024-02-14 4/week @ 2024-02-21 12/week @ 2024-02-28 4/week @ 2024-03-06 3/week @ 2024-03-13 13/week @ 2024-03-27 30/week @ 2024-04-03 104/week @ 2024-04-10

147 downloads per month

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.4MB
~22K SLoC