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.

63 lines
1.7 KiB

  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * std_string.i
  6. *
  7. * SWIG typemaps for std::string
  8. * ----------------------------------------------------------------------------- */
  9. %{
  10. #include <string>
  11. %}
  12. namespace std {
  13. %naturalvar string;
  14. class string;
  15. /* Overloading check */
  16. %typemap(typecheck) string = char *;
  17. %typemap(typecheck) const string & = char *;
  18. %typemap(in, pikedesc="tStr") string {
  19. if ($input.type != T_STRING)
  20. Pike_error("Bad argument: Expected a string.\n");
  21. $1.assign(STR0($input.u.string));
  22. }
  23. %typemap(in, pikedesc="tStr") const string & (std::string temp) {
  24. if ($input.type != T_STRING)
  25. Pike_error("Bad argument: Expected a string.\n");
  26. temp.assign(STR0($input.u.string));
  27. $1 = &temp;
  28. }
  29. %typemap(out, pikedesc="tStr") string "push_text($1.c_str());";
  30. %typemap(out, pikedesc="tStr") const string & "push_text($1->c_str());";
  31. %typemap(directorin) string, const string &, string & "$1_name.c_str()";
  32. %typemap(directorin) string *, const string * "$1_name->c_str()";
  33. %typemap(directorout) string {
  34. if ($input.type == T_STRING)
  35. $result.assign(STR0($input.u.string));
  36. else
  37. throw Swig::DirectorTypeMismatchException("string expected");
  38. }
  39. %typemap(directorout) const string & (std::string temp) {
  40. if ($input.type == T_STRING) {
  41. temp.assign(STR0($input.u.string));
  42. $result = &temp;
  43. } else {
  44. throw Swig::DirectorTypeMismatchException("string expected");
  45. }
  46. }
  47. }