Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB

  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. }