logo

libbulletml

Library of Bullet Markup Language (forked from https://shinh.skr.jp/libbulletml/index_en.html )git clone https://anongit.hacktivis.me/git/libbulletml.git/

create_d_import.pl (1713B)


  1. #!/usr/bin/env perl
  2. use strict;
  3. my @args;
  4. my $in = *STDIN;
  5. if ($ARGV[0]) {
  6. open $in, $ARGV[0];
  7. }
  8. my $out = *STDOUT;
  9. if ($ARGV[1]) {
  10. open $out, "> $ARGV[1]";
  11. }
  12. print $out "extern (C) {\n";
  13. while (<$in>) {
  14. s/const //g;
  15. if (parseArgs("D_CPP_CLASS")) {
  16. my $class = shift @args;
  17. my $name = shift @args;
  18. print $out "alias int $name;\n";
  19. }
  20. if (parseArgs("D_CPP_NEW_\\d")) {
  21. my $class = shift @args;
  22. my $name = shift @args;
  23. my $args = join ', ', @args;
  24. print $out "int* $name($args);\n";
  25. }
  26. if (parseArgs("D_CPP_DELETE")) {
  27. my $class = shift @args;
  28. my $name = shift @args;
  29. print $out "void $name(int*);\n";
  30. }
  31. if (parseArgs("D_CPP_METHOD_\\d")) {
  32. my $class = shift @args;
  33. my $method = shift @args;
  34. my $name = shift @args;
  35. my $ret = shift @args;
  36. my $args = join ', ', @args;
  37. if ($args) {
  38. $args = ", $args";
  39. }
  40. print $out "$ret $name(int* $args);\n";
  41. }
  42. if (parseArgs("D_CPP_STATIC_METHOD_\\d")) {
  43. my $class = shift @args;
  44. my $method = shift @args;
  45. my $name = shift @args;
  46. my $ret = shift @args;
  47. my $args = join ', ', @args;
  48. print $out "$ret $name($args);\n";
  49. }
  50. if (parseArgs("D_CPP_VIRTUAL_METHOD_SETTER_\\d")) {
  51. my $class = shift @args;
  52. my $method = shift @args;
  53. my $name = shift @args;
  54. my $ret = shift @args;
  55. my $args = join ', ', @args;
  56. if ($args) {
  57. $args = ", $args";
  58. }
  59. print $out "void $name(int*, $ret (*fp) (int* $args)); \n";
  60. }
  61. if (parseArgs("D_CPP_D_DECLARE")) {
  62. my $declare = shift @args;
  63. $declare =~ s/^\"//;
  64. $declare =~ s/\"$//;
  65. print $out "$declare\n";
  66. }
  67. }
  68. print $out "}\n";
  69. sub parseArgs {
  70. my $name = shift;
  71. if (/$name\s*\(([^\)]*)\)/) {
  72. @args = split /\s*,\s*/, $1;
  73. return 1;
  74. }
  75. else {
  76. return 0;
  77. }
  78. }