@@ -2329,7 +2329,142 @@ private void RegisterBuiltins()
23292329 }
23302330 } ) , "void" ) ;
23312331
2332+ WorkingCreateGlobal ( "showErrorBox" , new Action < string > ( ( message ) =>
2333+ {
2334+ Console . ForegroundColor = ConsoleColor . Red ;
2335+ Console . WriteLine ( "\n --- ERROR ---" ) ;
2336+ Console . WriteLine ( message ) ;
2337+ Console . ResetColor ( ) ;
2338+ Console . WriteLine ( "Press any key to continue..." ) ;
2339+ Console . ReadKey ( true ) ;
2340+ } ) , "void" ) ;
2341+
2342+ WorkingCreateGlobal ( "showConfirmBox" , new Func < string , string , bool > ( ( message , title ) =>
2343+ {
2344+ Console . WriteLine ( $ "\n --- { title } ---") ;
2345+ Console . WriteLine ( message ) ;
2346+ Console . Write ( "Enter Y for Yes or N for No: " ) ;
2347+
2348+ while ( true )
2349+ {
2350+ var key = Console . ReadKey ( true ) ;
2351+ if ( char . ToUpper ( key . KeyChar ) == 'Y' )
2352+ {
2353+ Console . WriteLine ( "Yes" ) ;
2354+ return true ;
2355+ }
2356+ else if ( char . ToUpper ( key . KeyChar ) == 'N' )
2357+ {
2358+ Console . WriteLine ( "No" ) ;
2359+ return false ;
2360+ }
2361+ }
2362+ } ) , "bool" ) ;
2363+
2364+ WorkingCreateGlobal ( "openFile" , new Func < string , bool > ( ( fileName ) =>
2365+ {
2366+ try
2367+ {
2368+ var process = new System . Diagnostics . Process ( ) ;
2369+ process . StartInfo . FileName = fileName ;
2370+ process . StartInfo . UseShellExecute = true ;
2371+ return process . Start ( ) ;
2372+ }
2373+ catch ( Exception ex )
2374+ {
2375+ Console . WriteLine ( $ "Failed to open file: { ex . Message } ") ;
2376+ return false ;
2377+ }
2378+ } ) , "bool" ) ;
2379+
2380+ WorkingCreateGlobal ( "runProcess" , new Func < string , string , bool > ( ( fileName , args ) =>
2381+ {
2382+ try
2383+ {
2384+ var process = new System . Diagnostics . Process ( ) ;
2385+ process . StartInfo . FileName = fileName ;
2386+ process . StartInfo . Arguments = args ;
2387+ return process . Start ( ) ;
2388+ }
2389+ catch ( Exception ex )
2390+ {
2391+ Console . WriteLine ( $ "Failed to run process: { ex . Message } ") ;
2392+ return false ;
2393+ }
2394+ } ) , "bool" ) ;
2395+
2396+ WorkingCreateGlobal ( "runProcessAndWait" , new Func < string , string , int > ( ( fileName , args ) =>
2397+ {
2398+ try
2399+ {
2400+ var process = new System . Diagnostics . Process ( ) ;
2401+ process . StartInfo . FileName = fileName ;
2402+ process . StartInfo . Arguments = args ;
2403+ process . Start ( ) ;
2404+ process . WaitForExit ( ) ;
2405+ return process . ExitCode ;
2406+ }
2407+ catch ( Exception ex )
2408+ {
2409+ Console . WriteLine ( $ "Failed to run process: { ex . Message } ") ;
2410+ return - 1 ;
2411+ }
2412+ } ) , "i32" ) ;
2413+
2414+ WorkingCreateGlobal ( "openFileDialog" , new Func < string , string , string > ( ( title , filter ) =>
2415+ {
2416+ Console . WriteLine ( $ "\n --- { title } ---") ;
2417+ Console . WriteLine ( $ "File filter: { filter } ") ;
2418+ Console . Write ( "Please enter the full path to the file: " ) ;
2419+ return Console . ReadLine ( ) ?? string . Empty ;
2420+ } ) , "string" ) ;
2421+
2422+ WorkingCreateGlobal ( "saveFileDialog" , new Func < string , string , string > ( ( title , filter ) =>
2423+ {
2424+ Console . WriteLine ( $ "\n --- { title } ---") ;
2425+ Console . WriteLine ( $ "File filter: { filter } ") ;
2426+ Console . Write ( "Please enter the full path where to save the file: " ) ;
2427+ return Console . ReadLine ( ) ?? string . Empty ;
2428+ } ) , "string" ) ;
2429+
23322430 WorkingCreateGlobal ( "breakPoint" , new Action ( ( ) => Console . WriteLine ( $ "breakpoint hit! Line: { checker . getLine ( ) } ") ) , "void" ) ;
2431+ WorkingCreateGlobal ( "now" , new Func < string > ( ( ) => DateTime . Now . ToString ( "o" ) ) , "string" ) ;
2432+ WorkingCreateGlobal ( "timestamp" , new Func < long > ( ( ) => DateTimeOffset . UtcNow . ToUnixTimeSeconds ( ) ) , "i64" ) ;
2433+ WorkingCreateGlobal ( "formatDate" , new Func < string , string , string > ( ( format , culture ) =>
2434+ {
2435+ return DateTime . Now . ToString ( format , new System . Globalization . CultureInfo ( culture ) ) ;
2436+ } ) , "string" ) ;
2437+ WorkingCreateGlobal ( "abs" , new Func < double , double > ( Math . Abs ) , "f64" ) ;
2438+ WorkingCreateGlobal ( "floor" , new Func < double , double > ( Math . Floor ) , "f64" ) ;
2439+ WorkingCreateGlobal ( "ceil" , new Func < double , double > ( Math . Ceiling ) , "f64" ) ;
2440+ WorkingCreateGlobal ( "round" , new Func < double , double > ( Math . Round ) , "f64" ) ;
2441+ WorkingCreateGlobal ( "sqrt" , new Func < double , double > ( Math . Sqrt ) , "f64" ) ;
2442+ WorkingCreateGlobal ( "pow" , new Func < double , double , double > ( Math . Pow ) , "f64" ) ;
2443+ WorkingCreateGlobal ( "max" , new Func < double , double , double > ( Math . Max ) , "f64" ) ;
2444+ WorkingCreateGlobal ( "min" , new Func < double , double , double > ( Math . Min ) , "f64" ) ;
2445+ WorkingCreateGlobal ( "clamp" , new Func < double , double , double , double > ( ( val , min , max ) => Math . Max ( min , Math . Min ( max , val ) ) ) , "f64" ) ;
2446+ WorkingCreateGlobal ( "toUpper" , new Func < string , string > ( s => s . ToUpperInvariant ( ) ) , "string" ) ;
2447+ WorkingCreateGlobal ( "toLower" , new Func < string , string > ( s => s . ToLowerInvariant ( ) ) , "string" ) ;
2448+ WorkingCreateGlobal ( "trim" , new Func < string , string > ( s => s . Trim ( ) ) , "string" ) ;
2449+ WorkingCreateGlobal ( "startsWith" , new Func < string , string , bool > ( ( s , prefix ) => s . StartsWith ( prefix ) ) , "bool" ) ;
2450+ WorkingCreateGlobal ( "endsWith" , new Func < string , string , bool > ( ( s , suffix ) => s . EndsWith ( suffix ) ) , "bool" ) ;
2451+ WorkingCreateGlobal ( "contains" , new Func < string , string , bool > ( ( s , substr ) => s . Contains ( substr ) ) , "bool" ) ;
2452+ WorkingCreateGlobal ( "split" , new Func < string , string , List < string > > ( ( s , sep ) => s . Split ( new [ ] { sep } , StringSplitOptions . None ) . ToList ( ) ) , "List<string>" ) ;
2453+ WorkingCreateGlobal ( "join" , new Func < List < string > , string , string > ( ( list , sep ) => string . Join ( sep , list ) ) , "string" ) ;
2454+ WorkingCreateGlobal ( "isNull" , new Func < object , bool > ( o => o == null ) , "bool" ) ;
2455+ WorkingCreateGlobal ( "isNumber" , new Func < object , bool > ( o => double . TryParse ( o ? . ToString ( ) , out _ ) ) , "bool" ) ;
2456+ WorkingCreateGlobal ( "isString" , new Func < object , bool > ( o => o is string ) , "bool" ) ;
2457+ WorkingCreateGlobal ( "toInt" , new Func < object , int > ( o => Convert . ToInt32 ( o ) ) , "i32" ) ;
2458+ WorkingCreateGlobal ( "toFloat" , new Func < object , double > ( o => Convert . ToDouble ( o ) ) , "f64" ) ;
2459+ WorkingCreateGlobal ( "uuid" , new Func < string > ( ( ) => Guid . NewGuid ( ) . ToString ( ) ) , "string" ) ;
2460+ WorkingCreateGlobal ( "env" , new Func < string , string > ( key => System . Environment . GetEnvironmentVariable ( key ) ?? string . Empty ) , "string" ) ;
2461+ WorkingCreateGlobal ( "log" , new Action < object > ( o => Console . WriteLine ( $ "[LOG] { o } ") ) , "void" ) ;
2462+ WorkingCreateGlobal ( "error" , new Action < object > ( o =>
2463+ {
2464+ Console . ForegroundColor = ConsoleColor . Red ;
2465+ Console . WriteLine ( $ "[ERROR] { o } ") ;
2466+ Console . ResetColor ( ) ;
2467+ } ) , "void" ) ;
23332468 }
23342469
23352470 public void WorkingCreateGlobal ( string name , object value , object typeReturn )
0 commit comments