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.

60 lines
1.6 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 types
  8. * ----------------------------------------------------------------------------- */
  9. // ------------------------------------------------------------------------
  10. // std::string is typemapped by value
  11. // This can prevent exporting methods which return a string
  12. // in order for the user to modify it.
  13. // However, I think I'll wait until someone asks for it...
  14. // ------------------------------------------------------------------------
  15. %include <exception.i>
  16. %{
  17. #include <string>
  18. %}
  19. namespace std {
  20. %naturalvar string;
  21. class string;
  22. /* Overloading check */
  23. %typemap(typecheck) string = char *;
  24. %typemap(typecheck) const string & = char *;
  25. %typemap(in) string {
  26. if (SCHEME_STRINGP($input))
  27. $1.assign(SCHEME_STR_VAL($input));
  28. else
  29. SWIG_exception(SWIG_TypeError, "string expected");
  30. }
  31. %typemap(in) const string & (std::string temp) {
  32. if (SCHEME_STRINGP($input)) {
  33. temp.assign(SCHEME_STR_VAL($input));
  34. $1 = &temp;
  35. } else {
  36. SWIG_exception(SWIG_TypeError, "string expected");
  37. }
  38. }
  39. %typemap(out) string {
  40. $result = scheme_make_string($1.c_str());
  41. }
  42. %typemap(out) const string & {
  43. $result = scheme_make_string($1->c_str());
  44. }
  45. }