assay/lua/
async_bridge.rs1use mlua::Lua;
2
3pub fn strip_shebang(script: &str) -> &str {
4 if script.starts_with("#!") {
5 script.find('\n').map_or("", |i| &script[i + 1..])
6 } else {
7 script
8 }
9}
10
11pub async fn exec_lua_async(lua: &Lua, script: &str) -> mlua::Result<()> {
12 lua.load(strip_shebang(script)).exec_async().await
13}
14
15pub async fn exec_lua_file_async(lua: &Lua, path: &str) -> mlua::Result<()> {
16 let content = std::fs::read_to_string(path)
17 .map_err(|e| mlua::Error::runtime(format!("failed to read Lua script {path:?}: {e}")))?;
18 exec_lua_async(lua, &content).await
19}