@ -14,6 +14,7 @@ use crossterm::event;
use crossterm ::execute ;
use crossterm ::execute ;
use crossterm ::terminal as term ;
use crossterm ::terminal as term ;
use mlua ::LuaSerdeExt ;
use mlua ::LuaSerdeExt ;
use mlua ::Value ;
use std ::fs ;
use std ::fs ;
use std ::io ::Write ;
use std ::io ::Write ;
use std ::path ::PathBuf ;
use std ::path ::PathBuf ;
@ -555,18 +556,55 @@ impl Runner {
term ::disable_raw_mode ( ) ? ;
term ::disable_raw_mode ( ) ? ;
terminal . show_cursor ( ) ? ;
terminal . show_cursor ( ) ? ;
let res : Result < Option < Vec < ExternalMsg > > > = lua
let res : Result < Value > =
. load ( & code )
lua . load ( & code ) . eval ( ) . map_err ( Error ::from ) ;
. eval ( )
match res {
Ok ( Value ::Function ( f ) ) = > {
let arg = app . to_lua_ctx_heavy ( ) ;
let res : Result <
Option < Vec < ExternalMsg > > ,
> = lua
. to_value ( & arg )
. and_then ( | a | f . call ( a ) )
. and_then ( | v | lua . from_value ( v ) )
. and_then ( | v | lua . from_value ( v ) )
. map_err ( Error ::from ) ;
. map_err ( Error ::from ) ;
match res {
match res {
Ok ( Some ( msgs ) ) = > {
Ok ( Some ( msgs ) ) = > {
app = app
app = app
. handle_batch_external_msgs ( msgs ) ? ;
. handle_batch_external_msgs (
msgs ,
) ? ;
}
}
Ok ( None ) = > { }
Ok ( None ) = > { }
Err ( err ) = > {
app = app . log_error (
err . to_string ( ) ,
) ? ;
}
}
}
Ok ( v ) = > {
let res : Result <
Option < Vec < ExternalMsg > > ,
> = lua
. from_value ( v )
. map_err ( Error ::from ) ;
match res {
Ok ( Some ( msgs ) ) = > {
app = app
. handle_batch_external_msgs (
msgs ,
) ? ;
}
Ok ( None ) = > { }
Err ( err ) = > {
app = app . log_error (
err . to_string ( ) ,
) ? ;
}
}
}
Err ( err ) = > {
Err ( err ) = > {
app = app . log_error ( err . to_string ( ) ) ? ;
app = app . log_error ( err . to_string ( ) ) ? ;
}
}
@ -594,18 +632,55 @@ impl Runner {
}
}
LuaEvalSilently ( code ) = > {
LuaEvalSilently ( code ) = > {
let res : Result < Option < Vec < ExternalMsg > > > = lua
let res : Result < Value > =
. load ( & code )
lua . load ( & code ) . eval ( ) . map_err ( Error ::from ) ;
. eval ( )
match res {
Ok ( Value ::Function ( f ) ) = > {
let arg = app . to_lua_ctx_heavy ( ) ;
let res : Result <
Option < Vec < ExternalMsg > > ,
> = lua
. to_value ( & arg )
. and_then ( | a | f . call ( a ) )
. and_then ( | v | lua . from_value ( v ) )
. and_then ( | v | lua . from_value ( v ) )
. map_err ( Error ::from ) ;
. map_err ( Error ::from ) ;
match res {
match res {
Ok ( Some ( msgs ) ) = > {
Ok ( Some ( msgs ) ) = > {
app = app
app = app
. handle_batch_external_msgs ( msgs ) ? ;
. handle_batch_external_msgs (
msgs ,
) ? ;
}
}
Ok ( None ) = > { }
Ok ( None ) = > { }
Err ( err ) = > {
app = app . log_error (
err . to_string ( ) ,
) ? ;
}
}
}
Ok ( v ) = > {
let res : Result <
Option < Vec < ExternalMsg > > ,
> = lua
. from_value ( v )
. map_err ( Error ::from ) ;
match res {
Ok ( Some ( msgs ) ) = > {
app = app
. handle_batch_external_msgs (
msgs ,
) ? ;
}
Ok ( None ) = > { }
Err ( err ) = > {
app = app . log_error (
err . to_string ( ) ,
) ? ;
}
}
}
Err ( err ) = > {
Err ( err ) = > {
app = app . log_error ( err . to_string ( ) ) ? ;
app = app . log_error ( err . to_string ( ) ) ? ;
}
}