add example crates

This commit is contained in:
2024-09-29 18:23:50 +02:00
parent da63980914
commit f116e435ec
15 changed files with 782 additions and 3 deletions

View File

@@ -0,0 +1,18 @@
use std::ffi::{c_char, CStr};
use mlua::Lua;
#[no_mangle]
pub extern "C" fn lua_new() -> *mut Lua {
let lua = Lua::new();
Box::into_raw(Box::new(lua))
}
#[no_mangle]
pub unsafe extern "C" fn lua_execute(lua: *mut Lua, to_execute: *const c_char) {
let lua: &mut Lua = &mut *lua;
let to_execute = CStr::from_ptr(to_execute);
if let Err(err) = lua.load(&to_execute.to_string_lossy().to_string()).exec() {
eprintln!("{}", err)
}
}