1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . IO ;
44using System . Net ;
1414using System . Windows . Forms ;
1515using Microsoft . JScript ;
1616using Microsoft . Win32 ;
17+ using System . Reflection ;
1718
1819namespace OwnLang . ast . lib
1920{
@@ -115,7 +116,7 @@ public void getModule(string name)
115116 }
116117 break ;
117118 }
118- case "cs " :
119+ case "winapi " :
119120 {
120121 try
121122 {
@@ -204,16 +205,23 @@ public void getModule(string name)
204205 }
205206 break ;
206207 }
207- case "winapi " :
208+ case "cs " :
208209 {
209210 try
210211 {
211-
212+ functions . Add ( "exec_cs_method" , new ExecuteCsMethod ( ) ) ;
213+ functions . Add ( "get_cs_class_inst" , new GetCsClassInstance ( ) ) ;
214+ functions . Add ( "import_cs_class" , new ImportCsClass ( ) ) ;
212215 }
213216
214217 catch
215218 {
216-
219+ functions . Remove ( "exec_cs_method" ) ;
220+ functions . Remove ( "get_cs_class_inst" ) ;
221+ functions . Remove ( "import_cs_class" ) ;
222+ functions . Add ( "exec_cs_method" , new ExecuteCsMethod ( ) ) ;
223+ functions . Add ( "get_cs_class_inst" , new GetCsClassInstance ( ) ) ;
224+ functions . Add ( "import_cs_class" , new ImportCsClass ( ) ) ;
217225 }
218226 break ;
219227 }
@@ -331,6 +339,68 @@ public static void set(string key, Function function)
331339 }
332340 }
333341
342+ public class ExecuteCsMethod : Function
343+ {
344+ private static NumberValue ZERO = new NumberValue ( 0 ) ;
345+
346+ public Value execute ( Value [ ] args )
347+ {
348+ object t0 = ( ( ObjectValue ) args [ 0 ] ) . asObject ( ) ;
349+ Type t = ( Type ) t0 ;
350+ MethodInfo mi = t . GetMethod ( args [ 2 ] . asString ( ) ) ;
351+ StackValue stack = ( StackValue ) args [ 3 ] ;
352+ List < object > values = new List < object > ( ) ;
353+ foreach ( Value val in stack . getElements ( ) )
354+ {
355+ try
356+ {
357+ StringValue str = ( StringValue ) val ;
358+ values . Add ( str . asString ( ) ) ;
359+ }
360+ catch
361+ {
362+ try
363+ {
364+ NumberValue str = ( NumberValue ) val ;
365+ values . Add ( str . asNumber ( ) ) ;
366+ }
367+ catch
368+ {
369+ BoolValue str = ( BoolValue ) val ;
370+ values . Add ( str . asBool ( ) ) ;
371+ }
372+ }
373+ }
374+ return new ObjectValue ( mi . Invoke ( ( ( ObjectValue ) args [ 1 ] ) . asObject ( ) , values . ToArray ( ) ) ) ;
375+ }
376+ }
377+
378+ public class GetCsClassInstance : Function
379+ {
380+ private static NumberValue ZERO = new NumberValue ( 0 ) ;
381+
382+ public Value execute ( Value [ ] args )
383+ {
384+ Assembly a = Assembly . Load ( args [ 0 ] . asString ( ) ) ;
385+ object instance = a . CreateInstance ( args [ 1 ] . asString ( ) ) ;
386+
387+ return new ObjectValue ( instance ) ;
388+ }
389+ }
390+
391+ public class ImportCsClass : Function
392+ {
393+ private static NumberValue ZERO = new NumberValue ( 0 ) ;
394+
395+ public Value execute ( Value [ ] args )
396+ {
397+ Assembly a = Assembly . Load ( args [ 0 ] . asString ( ) ) ;
398+ Type type = a . GetType ( args [ 1 ] . asString ( ) ) ;
399+
400+ return new ObjectValue ( type ) ;
401+ }
402+ }
403+
334404 public class Sin : Function
335405 {
336406 public Value execute ( Value [ ] args )
@@ -1220,4 +1290,4 @@ This is the multiline comment.
12201290 Why?
12211291 IDK.
12221292
1223- */
1293+ */
0 commit comments