[Questions] Calling a Lua function from Rust: `*mut rlua::ffi::lua_State` cannot be shared between threads safely

Hello, I am developing a CLI program for rendering template files using the new MiniJinja library by mitsuhiko.

The program is here: https://github.com/benwilber/temple.

I would like to be able to extend the program by allowing the user to load custom Lua scripts for things like custom filters, functions, and tests. However, I am running into Rust lifetime errors that I've not been able to solve.

Basically, I would like to be able to register a Lua function as a custom filter function. But it's showing an error when compiling. Here is the code:


How can I call a Lua function from the MiniJinja add_filter function? I would prefer to try to do this in the regular/safe way. But I'm open to unsafe alternatives if required.


Edit: Posted the same on StackOverflow and Reddit

Can you put the env behind a Rc<RefCell<...>> and call .borrow_mut().add_filter(...) ?

Disclaimer: assuming there is no multi threading involved here.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.