@@ -5,6 +5,7 @@ use tracing::error;
55/// Runs a Lua script.
66pub async fn run_command (
77 file_path : Option < String > ,
8+ code : Option < String > ,
89 stdlib_path : Option < String > ,
910 check_teal_code : bool ,
1011 extra_args : Option < Vec < String > > ,
@@ -32,13 +33,19 @@ pub async fn run_command(
3233
3334 // Load and execute the Lua script.
3435 #[ allow( clippy:: expect_used) ]
35- let user_file = if let Some ( file_path) = file_path {
36- check_for_default_file ( file_path)
36+ let ( user_file, actual_path_str) = if let Some ( code) = code {
37+ actual_path = "<commandline>" . to_string ( ) ;
38+ ( code, actual_path. clone ( ) )
3739 } else {
38- check_for_default_file ( "." . to_string ( ) )
40+ let file = if let Some ( file_path) = file_path {
41+ check_for_default_file ( file_path)
42+ } else {
43+ check_for_default_file ( "." . to_string ( ) )
44+ } ;
45+ ( file, actual_path. clone ( ) )
3946 } ;
4047
41- run_command_prerequisite ( & actual_path , stdlib_path, check_teal_code, extra_args) . await ;
48+ run_command_prerequisite ( & actual_path_str , stdlib_path, check_teal_code, extra_args) . await ;
4249 spawn_termination_task ( ) ;
4350
4451 // Remove the Shebang lines
@@ -48,17 +55,21 @@ pub async fn run_command(
4855 . collect :: < Vec < _ > > ( )
4956 . join ( "\n " ) ;
5057
51- if let Some ( is_teal) = PathBuf :: from ( & actual_path) . extension ( )
58+ if actual_path_str == "<commandline>" {
59+ if let Err ( e) = lua. load ( user_file) . set_name ( "<commandline>" ) . exec_async ( ) . await {
60+ error ! ( "{}" , e) ;
61+ }
62+ } else if let Some ( is_teal) = PathBuf :: from ( & actual_path_str) . extension ( )
5263 && is_teal == "tl"
5364 {
5465 if let Err ( e) = crate :: components:: load_teal ( lua) . await {
5566 error ! ( "{}" , e) ;
5667 }
5768
58- if let Err ( e) = crate :: components:: execute_teal_code ( lua, & actual_path , & user_file) . await {
69+ if let Err ( e) = crate :: components:: execute_teal_code ( lua, & actual_path_str , & user_file) . await {
5970 error ! ( "{}" , e) ;
6071 }
61- } else if let Err ( e) = lua. load ( user_file) . set_name ( actual_path ) . exec_async ( ) . await {
72+ } else if let Err ( e) = lua. load ( user_file) . set_name ( actual_path_str ) . exec_async ( ) . await {
6273 error ! ( "{}" , e) ;
6374 }
6475
0 commit comments