PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/overload_extend.i

#
Swig | 66 lines | 53 code | 13 blank | 0 comment | 0 complexity | b4cdad9ff410fe84325ae98855e64f68 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module overload_extend
  2. #ifndef __cplusplus
  3. %{
  4. #include <stdlib.h>
  5. %}
  6. %typemap(default) double y "$1=1000;";
  7. #endif
  8. #ifdef SWIGLUA
  9. // lua only has one numeric type, so some overloads shadow each other creating warnings
  10. %warnfilter(SWIGWARN_PARSE_REDEFINED, SWIGWARN_LANG_OVERLOAD_SHADOW) Foo::test;
  11. #else
  12. %warnfilter(SWIGWARN_PARSE_REDEFINED) Foo::test;
  13. #endif
  14. %extend Foo {
  15. int test() { return 0; }
  16. int test(int x) { x = 0; return 1; }
  17. int test(char *s) { s = 0; return 2; }
  18. #ifdef __cplusplus
  19. double test(double x, double y = 1000) { return x + y; }
  20. #else
  21. double test(double x, double y) { return x + y; }
  22. #endif
  23. };
  24. %inline %{
  25. struct Foo {
  26. int variable;
  27. #ifdef __cplusplus
  28. int test() { return -1; }
  29. #endif
  30. };
  31. %}
  32. %extend Bar {
  33. #ifdef __cplusplus
  34. Bar() {
  35. return new Bar();
  36. }
  37. ~Bar() {
  38. delete $self;
  39. }
  40. #else
  41. Bar() {
  42. return (Bar *) malloc(sizeof(Bar));
  43. }
  44. ~Bar() {
  45. free($self);
  46. }
  47. #endif
  48. }
  49. %inline %{
  50. typedef struct {
  51. int variable;
  52. } Bar;
  53. %}