PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1.3.35/Lib/ruby/argcargv.i

#
Swig | 48 lines | 22 code | 4 blank | 22 comment | 0 complexity | c53598d53736458d041f15338f2f62ad MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* ------------------------------------------------------------
  2. * --- Argc & Argv ---
  3. * ------------------------------------------------------------ */
  4. /* ------------------------------------------------------------
  5. Use it as follow:
  6. %apply (int ARGC, char **ARGV) { (size_t argc, const char **argv) }
  7. %inline %{
  8. int mainApp(size_t argc, const char **argv)
  9. {
  10. return argc;
  11. }
  12. then in the ruby side:
  13. args = ["asdf", "asdf2"]
  14. mainApp(args);
  15. * ------------------------------------------------------------ */
  16. %typemap(in) (int ARGC, char **ARGV) {
  17. if (rb_obj_is_kind_of($input,rb_cArray)) {
  18. int i;
  19. int size = RARRAY_LEN($input);
  20. $1 = ($1_ltype) size;
  21. $2 = (char **) malloc((size+1)*sizeof(char *));
  22. VALUE *ptr = RARRAY_PTR($input);
  23. for (i=0; i < size; i++, ptr++) {
  24. $2[i]= STR2CSTR(*ptr);
  25. }
  26. $2[i]=NULL;
  27. } else {
  28. $1 = 0; $2 = 0;
  29. %argument_fail(SWIG_TypeError, "int ARGC, char **ARGV", $symname, $argnum);
  30. }
  31. }
  32. %typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
  33. $1 = rb_obj_is_kind_of($input,rb_cArray);
  34. }
  35. %typemap(freearg) (int ARGC, char **ARGV) {
  36. free((char *) $2);
  37. }