@@ -10,12 +10,22 @@ const fildes: NativePointer = Memory.alloc(SIZEOF_INT * 2);
1010
1111let stream : UnixInputStream ;
1212
13- const pipe = new NativeFunction ( Module . findExportByName ( null , 'pipe' ) ! , 'int' , [ 'pointer' ] ) ;
14- const dup2 = new NativeFunction ( Module . findExportByName ( null , 'dup2' ) ! , 'int' , [ 'int' , 'int' ] ) ;
15- const close = new NativeFunction ( Module . findExportByName ( null , 'close' ) ! , 'int' , [ 'int' ] ) ;
16- const fcntl = new NativeFunction ( Module . findExportByName ( null , 'fcntl' ) ! , 'int' , [ 'int' , 'int' , 'int' ] ) ;
17-
1813export function start ( ) {
14+ stop ( ) ;
15+
16+ const resolve = ( name : string ) : NativePointer => {
17+ const p = Module . findExportByName ( null , name ) ;
18+ if ( ! p ) {
19+ throw new Error ( `Platform not supported. Is your target on ${ name } ?` ) ;
20+ }
21+ return p ;
22+ }
23+
24+ const pipe = new NativeFunction ( resolve ( 'pipe' ) , 'int' , [ 'pointer' ] ) ;
25+ const dup2 = new NativeFunction ( resolve ( 'dup2' ) , 'int' , [ 'int' , 'int' ] ) ;
26+ const close = new NativeFunction ( resolve ( 'close' ) , 'int' , [ 'int' ] ) ;
27+ const fcntl = new NativeFunction ( resolve ( 'fcntl' ) , 'int' , [ 'int' , 'int' , 'int' ] ) ;
28+
1929 pipe ( fildes ) ;
2030
2131 const input = fildes . readInt ( ) ;
0 commit comments