Embedding Lua into Rust
Many of the programs we've discussed in this book use a report thread to notify the user of the running behavior of the program. Each of these report functions have been coded in Rust, an unchanging part of the executable. What if, however, we wanted end-users to be able to supply their own reporting routine? Or, consider the cernan project (https://crates.io/crates/cernan), discussed previously in this book, which supports a programmable filter, an online data-stream filter that can be programmed by end-users without changing the cernan binary. How do you pull such a trick off?
A common answer, not just in Rust but in many compiled languages, is to embed a Lua interpreter (https://www.lua.org/) and read user programs in at startup. It's such a common answer, in fact, that there are many Lua embeddings to choose from in the crates ecosystem. We'll use rlua (https://crates.io/crates/rlua) here as it's a safe choice and the project documentation is very good. Other Lua...