mirror of
https://github.com/chipsenkbeil/distant.git
synced 2024-11-05 12:00:36 +00:00
16bed4690b
* Update distant-ssh2 with new changes to wezterm-ssh * Implement lua module (distant-lua) * Implement tests for lua module (distant-lua-tests) * Add untested windows daemon support * distant binary now compiles on windows * Split up Github actions for Windows, MacOS, and Linux into individual yaml files
42 lines
1.1 KiB
Rust
42 lines
1.1 KiB
Rust
use super::fixtures::DistantServerCtx;
|
|
use mlua::{chunk, prelude::*};
|
|
|
|
/// Creates a function that produces a session within the provided Lua environment
|
|
/// using the given distant server context, returning the session's id
|
|
pub fn make_function<'a>(lua: &'a Lua, ctx: &'_ DistantServerCtx) -> LuaResult<LuaFunction<'a>> {
|
|
let addr = ctx.addr;
|
|
let host = addr.ip().to_string();
|
|
let port = addr.port();
|
|
let key = ctx.key.clone();
|
|
|
|
lua.load(chunk! {
|
|
local distant = require("distant_lua")
|
|
local thread = coroutine.create(distant.session.connect_async)
|
|
|
|
local status, res = coroutine.resume(thread, {
|
|
host = $host,
|
|
port = $port,
|
|
key = $key,
|
|
timeout = 15000,
|
|
})
|
|
|
|
// Block until the connection finishes
|
|
local session = nil
|
|
while status do
|
|
if status and res ~= distant.PENDING then
|
|
session = res
|
|
break
|
|
end
|
|
|
|
status, res = coroutine.resume(thread)
|
|
end
|
|
|
|
if session then
|
|
return session
|
|
else
|
|
error(res)
|
|
end
|
|
})
|
|
.into_function()
|
|
}
|