@@ -15,37 +15,40 @@ Below is an example that fills a destination span with coordinates for the point
1515with either a radius or a diameter as input. While reusing the same machine instance by modifying
1616its source and variables, and re-evaluating the expression.
1717``` cs
18- public unsafe void GetCirclePositions (float value , bool isDiameter , USpan < Vector2 > positions )
18+ public void GetCirclePositions (float radius , Span < Vector2 > positions )
1919{
2020 using Machine vm = new ();
2121 vm .SetVariable (" value" , value );
22- vm .SetVariable (" multiplier" , isDiameter ? 2 : 1 );
23- vm .SetFunction (" cos" , & Cos );
24- vm .SetFunction (" sin" , & Sin );
22+ vm .SetFunction (" cos" , MathF .Cos );
23+ vm .SetFunction (" sin" , MathF .Sin );
2524
26- uint length = positions .Length ;
25+ int length = positions .Length ;
2726 for (int i = 0 ; i < length ; i ++ )
2827 {
2928 float t = i * MathF .PI / (length * 0 . 5 f );
3029 vm .SetVariable (" t" , t );
31- vm .SetSource (" cos(t) * (value * multiplier) " );
30+ vm .SetSource (" cos(t) * radius " );
3231 float x = vm .Evaluate ();
33- vm .SetSource (" sin(t) * (value * multiplier) " );
32+ vm .SetSource (" sin(t) * radius " );
3433 float y = vm .Evaluate ();
3534 positions [i ] = new Vector2 (x , y );
3635 }
36+ }
37+ ```
3738
38- [UnmanagedCallersOnly ]
39- static float Cos (float value )
40- {
41- return MathF .Cos (value );
42- }
39+ ### Checking for compilation issues
4340
44- [UnmanagedCallersOnly ]
45- static float Sin (float value )
46- {
47- return MathF .Sin (value );
48- }
41+ When a text source is assigned to the machine, it returns a compilation result.
42+ This result value can be used to check if there were issues. And can do so with the try-do pattern:
43+ ``` cs
44+ if (vm .TrySetSource (" 5 +" , out Exception ? exception ))
45+ {
46+ // success
47+ }
48+ else
49+ {
50+ // error
51+ throw exception ;
4952}
5053```
5154
0 commit comments