Hi, this is my first post here!
I know this is a Rust forum, but I do find that dealing with foreign interfaces is difficult.
I'm trying to get a static reference to a mlua::Lua but all of the normal things seem to break. This is being put in a dll and i want it to just work if possible, I'm pretending i will know better ways to handle this in the future.
static luaScope:mlua::Lua = Lua::new();
results in angry compiler.
calls in statics are limited to constant functions, tuple structs and tuple variants
Oh, constant function maybe I can make one!
static luaScope:mlua::Lua = LuaInit();
const fn LuaInit()->mlua::Lua
{
let m = Lua::new();
m
}
Big fail Turns out const functions can only call const functions also I got a million (hyperbole) errors saying that
*mut c_void` cannot be shared between threads safely
I looked and found lazy_static!
use lazy_static::lazy_static;
use std::sync::Mutex;
lazy_static! {
static ref luaScope: Mutex<mlua::Lua> = {
let mut m = Lua::new();
Mutex::new(m)
};
}
This gives another handling error with
*mut c_void` cannot be shared between threads safely
= help: within `mlua::Lua`, the trait `Send` is not implemented for `*mut c_void`
= note: required because it appears within the type `mlua::Lua`
= note: required because of the requirements on the impl of `Sync` for `Mutex<mlua::Lua>
provided some answers. on why but not how to fix this.
Well how to handle those? Arc<Mutex> perhaps?
No this did not work either
So how should I wrap this up to make it acceptable?