pub fn make_session_tbl(lua: &Lua) -> LuaResult<LuaTable> {
    let tbl = lua.create_table()?;

    // get_all() -> Vec<Session>
    tbl.set("get_all", lua.create_function(|_, ()| Session::all())?)?;

    // get_by_id(id: usize) -> Option<Session>
    tbl.set(
        "get_by_id",
        lua.create_function(|_, id: usize| {
            let exists = has_session(id)?;
            if exists {
                Ok(Some(Session::new(id)))
            } else {
                Ok(None)
            }
        })?,
    )?;

    // launch(opts: LaunchOpts) -> Session
    tbl.set(
        "launch",
        lua.create_function(|lua, opts: LuaValue| {
            let opts = LaunchOpts::from_lua(opts, lua)?;
            runtime::block_on(Session::launch(opts))
        })?,
    )?;

    // connect_async(opts: ConnectOpts) -> Future<Session>
    tbl.set(
        "connect_async",
        lua.create_async_function(|lua, opts: LuaValue| async move {
            let opts = ConnectOpts::from_lua(opts, lua)?;
            runtime::spawn(Session::connect(opts)).await
        })?,
    )?;

    // connect(opts: ConnectOpts) -> Session
    tbl.set(
        "connect",
        lua.create_function(|lua, opts: LuaValue| {
            let opts = ConnectOpts::from_lua(opts, lua)?;
            runtime::block_on(Session::connect(opts))
        })?,
    )?;

    Ok(tbl)
}
/// Makes a Lua table containing the session functions
Makes a Lua table containing the session functions
Makes a Lua table containing the session functions
pub fn make_session_tbl(lua: &Lua) -> LuaResult<LuaTable> {
    let tbl = lua.create_table()?;
    // get_all() -> Vec<Session>
    tbl.set("get_all", lua.create_function(|_, ()| Session::all())?)?;
    // get_by_id(id: usize) -> Option<Session>
    tbl.set(
        "get_by_id",
        lua.create_function(|_, id: usize| {
            let exists = has_session(id)?;
            if exists {
                Ok(Some(Session::new(id)))
            } else {
                Ok(None)
            }
        })?,
    )?;
    // launch(opts: LaunchOpts) -> Session
    tbl.set(
        "launch",
        lua.create_function(|lua, opts: LuaValue| {
            let opts = LaunchOpts::from_lua(opts, lua)?;
            runtime::block_on(Session::launch(opts))
        })?,
    )?;
    // connect_async(opts: ConnectOpts) -> Future<Session>
    tbl.set(
        "connect_async",
        lua.create_async_function(|lua, opts: LuaValue| async move {
            let opts = ConnectOpts::from_lua(opts, lua)?;
            runtime::spawn(Session::connect(opts)).await
        })?,
    )?;
    // connect(opts: ConnectOpts) -> Session
    tbl.set(
        "connect",
        lua.create_function(|lua, opts: LuaValue| {
            let opts = ConnectOpts::from_lua(opts, lua)?;
            runtime::block_on(Session::connect(opts))
        })?,
    )?;
    Ok(tbl)
}
pub fn make_session_tbl ( lua : & Lua ) -> LuaResult < LuaTable > { let tbl = lua . create_table ( ) ? ; // get_all() -> Vec<Session> tbl . set ( " " , lua . create_function ( | _ , ( ) | Session :: all ( ) ) ? ) ? ; // get_by_id(id: usize) -> Option<Session> tbl . set ( " " , lua . create_function ( | _ , id : usize | { let exists = has_session ( id ) ? ; if exists { Ok ( Some ( Session :: new ( id ) ) ) } else { Ok ( None ) } } ) ? , ) ? ; // launch(opts: LaunchOpts) -> Session tbl . set ( " " , lua . create_function ( | lua , opts : LuaValue | { let opts = LaunchOpts :: from_lua ( opts , lua ) ? ; runtime :: block_on ( Session :: launch ( opts ) ) } ) ? , ) ? ; // connect_async(opts: ConnectOpts) -> Future<Session> tbl . set ( " " , lua . create_async_function ( | lua , opts : LuaValue | async move { let opts = ConnectOpts :: from_lua ( opts , lua ) ? ; runtime :: spawn ( Session :: connect ( opts ) ) . await } ) ? , ) ? ; // connect(opts: ConnectOpts) -> Session tbl . set ( " " , lua . create_function ( | lua , opts : LuaValue | { let opts = ConnectOpts :: from_lua ( opts , lua ) ? ; runtime :: block_on ( Session :: connect ( opts ) ) } ) ? , ) ? ; Ok ( tbl ) }
Makes a Lua table containing the session functions
Makes a Lua table containing the session functions
lua
&Lua