use strict;
use Inline 'SLang';
use Data::Dumper;

# ensure that we convert S-Lang arrays to array references
Inline::SLang::sl_array2perl(0);

my $a1 = send_and_get( [ "hi", "there", "", "a string" ] );
print "\nPerl sent:\n", Dumper($a1), "\n";

__END__
__SLang__

define send_and_get (in) {
  if ( typeof(in) != Array_Type ) error( "Error!" );
  variable adims, ndims, atype;
  ( adims, ndims, atype ) = array_info(in);
  vmessage( "S-Lang sent a %d dim array of %S variables", ndims, atype );
  variable elem;
  foreach ( in ) {
    elem = ();
    vmessage( "  element = '%S'", elem );
  }

  % create the output array
  variable out = [2:7];
  reshape( out, [2,3] );
  return out;
}