@@ -79,7 +79,7 @@ public int Interperate(LineWithTokens[] LineTokens)
7979 continue ;
8080
8181 var backup_vars = Vars . Select ( x => new Var ( x . Name , x . Value , x . Line , x . StackNumber , x . DataType , x . Required ) ) . ToArray ( ) ;
82- var backup_methods = Methods . Select ( x => new Method ( x . Name , x . Line , x . Settings , x . Lines , x . Params , x . Returns ) ) . ToArray ( ) ;
82+ var backup_methods = Methods . Select ( x => new Method ( x . Name , x . Line , x . Settings , x . Lines , x . Parameters , x . Returns ) ) . ToArray ( ) ;
8383 try
8484 {
8585 temp_stack = new Stack < string > ( StackTrace ) ;
@@ -286,30 +286,56 @@ public int Interperate(LineWithTokens[] LineTokens)
286286 throw new Exception ( "Expected \" :\" identifier to set method perameters" ) ;
287287 }
288288
289- if ( method . Params != null && method . Params . Length > 0 )
289+ if ( method . Parameters != null && method . Parameters . Length > 0 )
290290 {
291- string all ; string [ ] vals ;
292- try
291+ string all ;
292+ object [ ] vals ;
293+
294+ try
293295 {
294- all = string . Join ( " " , line . Tokens . Skip ( next + 1 ) . Select ( x => x . StringValue ) ) ;
295- if ( all . Split ( ',' ) . Length > method . Params . Select ( x => x . Required ) . ToArray ( ) . Length )
296- throw new Exception ( $ "Expects { ( method . Params . Any ( x=> x . Required ) ? "at least" : "" ) } { ( method . Params . Any ( x => x . Required ) ? method . Params . Select ( x=> x . Required ) . ToArray ( ) . Length : method . Params . Length ) } parameter for method \" { method . Name } \" but { all . Split ( ',' ) . Length } were inputted") ;
297- vals = all . Split ( ',' ) . Select ( x => x . Trim ( ) ) . Select ( ( x , y ) => GetValue ( x , method . Params [ y ] . DataType ) . ToString ( ) ) . Where ( x => x != "" ) . ToArray ( ) ;
296+ all = string . Join ( " " , line . Tokens . Select ( ( x , y ) => x . Value is RunMethod r ? "@:|" + y . ToString ( ) + "{}" : x . StringValue ) . Skip ( next + 1 ) ) ;
297+ string [ ] all_parts = all . Split ( ',' ) ;
298+ if ( all_parts . Length > method . Parameters . Select ( x => x . Required ) . ToArray ( ) . Length && ! method . Parameters . Any ( x => x . IsParams ) )
299+ throw new Exception ( $ "Expects { ( method . Parameters . Any ( x=> x . Required ) ? "at least" : "" ) } { ( method . Parameters . Any ( x => x . Required ) ? method . Parameters . Select ( x=> x . Required ) . ToArray ( ) . Length : method . Parameters . Length ) } parameter for method \" { method . Name } \" but { all_parts . Length } were given") ;
300+ if ( method . Parameters . Any ( x => x . IsParams ) )
301+ {
302+ string [ ] new_parts = [ ] ;
303+ for ( int j = 0 ; j < method . Parameters . Length ; j ++ )
304+ {
305+ if ( method . Parameters [ j ] . IsParams )
306+ {
307+ new_parts = [ .. new_parts , string . Join ( "," , all_parts . Skip ( j ) ) . Replace ( " ," , "," ) ] ;
308+ break ;
309+ }
310+ new_parts = [ .. new_parts , all_parts [ j ] ] ;
311+ }
312+ all_parts = new_parts ;
313+ }
314+ vals = all_parts . Select ( x => x . Trim ( ) ) . Select ( ( x , y ) => x . StartsWith ( "@:|" ) && x . EndsWith ( "{}" ) ? line . Tokens [ int . Parse ( x . Substring ( 3 , x . Length - 5 ) ) ] . Value : GetValue ( x , method . Parameters [ y ] . DataType ) . ToString ( ) ) . Where ( x => x . ToString ( ) != "" ) . ToArray ( ) ;
298315 }
299316 catch ( Exception e )
300317 {
301- if ( e . Message . StartsWith ( "Expects " ) ) throw new Exception ( e . Message ) ;
318+ if ( e . Message . StartsWith ( "Expects " ) )
319+ throw new Exception ( e . Message ) ;
302320 throw new Exception ( "Error getting values for method paramters" ) ;
303321 }
322+ if ( vals . FirstOrDefault ( x => x is RunMethod ) is RunMethod r )
323+ {
324+ for ( int i = 0 ; i < r . Parameters . Length ; i ++ )
325+ {
326+ r . Parameters [ i ] . Value = GetValue ( r . Parameters [ i ] , r . Parameters [ i ] . DataType ) ;
327+ }
328+ }
304329 if ( vals . Length > 0 )
305330 {
306- for ( int i = 0 ; i < method . Params . Length ; i ++ )
331+ for ( int i = 0 ; i < method . Parameters . Length ; i ++ )
307332 {
308- if ( ! method . Params [ i ] . Required && vals . Length - 1 < i )
333+ if ( ! method . Parameters [ i ] . Required && vals . Length - 1 < i )
309334 continue ;
310- vars = [ .. vars , new Var ( method . Params [ i ] . Name , vals [ i ] , line . Line , stackNumber : StackNumber , type : method . Params [ i ] . DataType , required : method . Params [ i ] . Required ) ] ;
335+ object value = method . Parameters [ i ] . IsParams ? string . Join ( "," , vals . Skip ( i ) ) : vals [ i ] ;
336+ vars = [ .. vars , new Var ( method . Parameters [ i ] . Name , value , line . Line , stackNumber : StackNumber , type : method . Parameters [ i ] . DataType , required : method . Parameters [ i ] . Required ) ] ;
311337 }
312- if ( vars . Where ( x => x . Required ) . ToArray ( ) . Length != method . Params . Where ( x => x . Required ) . ToArray ( ) . Length )
338+ if ( vars . Where ( x => x . Required ) . ToArray ( ) . Length != method . Parameters . Where ( x => x . Required ) . ToArray ( ) . Length )
313339 {
314340 throw new Exception ( "Not all parameters are set" ) ;
315341 }
@@ -325,7 +351,7 @@ public int Interperate(LineWithTokens[] LineTokens)
325351 }
326352 else
327353 {
328- if ( method . Params != null && method . Params . Select ( x => x . Required ) . ToArray ( ) . Length > 0 )
354+ if ( method . Parameters != null && method . Parameters . Select ( x => x . Required ) . ToArray ( ) . Length > 0 )
329355 {
330356 throw new Exception ( $ "Method \" { method . Name } \" expects parameters") ;
331357 }
@@ -656,7 +682,7 @@ private IdentType IsType(string token, out object? type)
656682 StackTrace . Push ( $ "method: { method . Name } , file: { WorkingFile } , line: { method . Line . CodeLine } ") ;
657683 parameters ??= [ ] ;
658684 LineWithTokens [ ] lines = method . Lines ;
659- Var [ ] vvars = method . Params ?? [ ] ;
685+ Var [ ] vvars = method . Parameters ?? [ ] ;
660686
661687 for ( int i = 0 ; i < vvars . Length ; i ++ )
662688 {
@@ -798,6 +824,11 @@ public object GetValue(object obj, DataType? type = null)
798824 }
799825 catch
800826 {
827+ try
828+ {
829+ return GetValue ( var . Value , type ) ;
830+ }
831+ catch { }
801832 throw new Exception ( "Error returning correct value" ) ;
802833 }
803834 }
@@ -816,7 +847,7 @@ public object GetValue(object obj, DataType? type = null)
816847 if ( t != - 1 )
817848 {
818849 var backup_vars = Vars . Select ( x => new Var ( x . Name , x . Value , x . Line , x . StackNumber , x . DataType , x . Required ) ) . ToArray ( ) ;
819- var backup_methods = Methods . Select ( x => new Method ( x . Name , x . Line , x . Settings , x . Lines , x . Params , x . Returns ) ) . ToArray ( ) ;
850+ var backup_methods = Methods . Select ( x => new Method ( x . Name , x . Line , x . Settings , x . Lines , x . Parameters , x . Returns ) ) . ToArray ( ) ;
820851 Vars = ( var . Value as Class ) . Properties . Concat ( Vars . Where ( x => x . Global ) ) . ToArray ( ) ;
821852 Methods = ( var . Value as Class ) . Methods . Concat ( Methods . Where ( x => ( x . Settings & Method . MethodSettings . Global ) == Method . MethodSettings . Global ) ) . ToArray ( ) ;
822853 object ? result = MethodRun ( get [ t ] . Method , null ) ;
@@ -866,9 +897,43 @@ public object GetValue(object obj, DataType? type = null)
866897 return GetValue ( var . Value , var . DataType ) ?? obj ;
867898 }
868899 }
869- else if ( Classes . Any ( x => x . Name == obj . ToString ( ) ) )
900+ else if ( obj . ToString ( ) . Contains ( ':' ) )
870901 {
902+ string firstpart = obj . ToString ( ) . Split ( ':' ) [ 0 ] . ToString ( ) . Trim ( ) ;
903+ if ( Vars . Any ( x => x . Name == firstpart ) )
904+ {
905+ string property_name = string . Join ( ":" , obj . ToString ( ) . Split ( ':' ) . Skip ( 1 ) ) . Trim ( ) ;
906+ if ( Vars . FirstOrDefault ( x => x . Name == firstpart ) . Value is Class c )
907+ {
908+ if ( c . Properties . FirstOrDefault ( x => x . Name == property_name ) is Var v )
909+ {
910+ return v . Value ;
911+ }
912+ else
913+ {
914+ throw new Exception ( $ "Could not find the property \" { property_name } \" in the class instance \" { firstpart } \" ") ;
915+ }
916+ }
917+ if ( Vars . FirstOrDefault ( x => x . Name == firstpart ) . Value is RunMethod m )
918+ {
919+ if ( m . Parameters . FirstOrDefault ( x => x . Name == property_name ) is Var v )
920+ {
921+ return v . Value ;
922+ }
923+ else
924+ {
925+ throw new Exception ( $ "Could not find the property \" { property_name } \" in the class instance \" { firstpart } \" ") ;
926+ }
927+ }
928+ else
929+ {
930+ throw new Exception ( $ "Variable \" { firstpart } \" is not a class instance") ;
931+ }
932+ }
933+ else if ( Classes . Any ( x => x . Name == firstpart ) )
934+ {
871935
936+ }
872937 }
873938 }
874939 else if ( obj is RunMethod run )
0 commit comments