summaryrefslogtreecommitdiff
path: root/share/swig/2.0.11/ruby/progargcargv.i
diff options
context:
space:
mode:
Diffstat (limited to 'share/swig/2.0.11/ruby/progargcargv.i')
-rw-r--r--share/swig/2.0.11/ruby/progargcargv.i34
1 files changed, 34 insertions, 0 deletions
diff --git a/share/swig/2.0.11/ruby/progargcargv.i b/share/swig/2.0.11/ruby/progargcargv.i
new file mode 100644
index 0000000..a2843c3
--- /dev/null
+++ b/share/swig/2.0.11/ruby/progargcargv.i
@@ -0,0 +1,34 @@
+/*
+int PROG_ARGC
+char **PROG_ARGV
+
+ Some C function receive argc and argv from C main function.
+ This typemap provides ignore typemap which pass Ruby ARGV contents
+ as argc and argv to C function.
+*/
+
+
+
+// argc and argv
+%typemap(in,numinputs=0) int PROG_ARGC {
+ $1 = RARRAY_LEN(rb_argv) + 1;
+}
+
+%typemap(in,numinputs=0) char **PROG_ARGV {
+ int i, n;
+ VALUE ary = rb_eval_string("[$0] + ARGV");
+ n = RARRAY_LEN(ary);
+ $1 = (char **)malloc(n + 1);
+ for (i = 0; i < n; i++) {
+ VALUE v = rb_obj_as_string(RARRAY_PTR(ary)[i]);
+ $1[i] = (char *)malloc(RSTRING_LEN(v) + 1);
+ strcpy($1[i], RSTRING_PTR(v));
+ }
+}
+
+%typemap(freearg) char **PROG_ARGV {
+ int i, n = RARRAY_LEN(rb_argv) + 1;
+ for (i = 0; i < n; i++) free($1[i]);
+ free($1);
+}
+