1 /* ------------------------------------------------------------ 2 * --- Argc & Argv --- 3 * ------------------------------------------------------------ */ 4 5 /* ------------------------------------------------------------ 6 7 Use it as follow: 8 9 %apply (int ARGC, char **ARGV) { (size_t argc, const char **argv) } 10 11 %inline %{ 12 13 int mainApp(size_t argc, const char **argv) 14 { 15 return argc; 16 } 17 18 then in the ruby side: 19 20 args = ["asdf", "asdf2"] 21 mainApp(args); 22 23 * ------------------------------------------------------------ */ 24 25 %typemap(in) (int ARGC, char **ARGV) { 26 if (rb_obj_is_kind_of($input,rb_cArray)) { 27 int i; 28 int size = RARRAY_LEN($input); 29 $1 = ($1_ltype) size; 30 $2 = (char **) malloc((size+1)*sizeof(char *)); 31 VALUE *ptr = RARRAY_PTR($input); 32 for (i=0; i < size; i++, ptr++) { 33 $2[i]= StringValuePtr(*ptr); 34 } 35 $2[i]=NULL; 36 } else { 37 $1 = 0; $2 = 0; 38 %argument_fail(SWIG_TypeError, "int ARGC, char **ARGV", $symname, $argnum); 39 } 40 } 41 42 %typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) { 43 $1 = rb_obj_is_kind_of($input,rb_cArray); 44 } 45 46 %typemap(freearg) (int ARGC, char **ARGV) { 47 free((char *) $2); 48 } 49