Extra "ports" of juce-based plugins using the distrho build system
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.

140 lines
3.1KB

  1. Some notes on creating the c++ export header, the c ffi import header, and the lua wrapper from JUCE library code. It's a mix of manual labor and notepad++ regular expression replacements, which was probably faster than doing everything manually or making a full parser and code generator. And it starts with the GNU C preprocessor :
  2. ========== JUCE header to c++ export header =========
  3. cpp -P juce_path.h
  4. manually remove unwanted code, paste PROTO_API in front of desired functions.
  5. Add "self" :
  6. PROTO_API (.*?)\((.*?)\{(.*?)\}
  7. ->
  8. PROTO_API \1\(pPath self, \2\{\3\}
  9. pPath self, )
  10. (normal mode)->
  11. pPath self)
  12. Prefix and create exported function bodies :
  13. PROTO_API (.*?) (.*?)\(pPath self(.*?)\)\r\n\{\r\n\r\n\}
  14. ->
  15. PROTO_API \1 Path_\2\(\3\)\r\n\{\r\n\treturn self.p->\2\(\3\)\r\n\}
  16. (,
  17. (normal mode)->
  18. (
  19. Remove "return" from void function bodies :
  20. PROTO_API void (.*?)return
  21. ->
  22. PROTO_API void \1
  23. Add "self" in definition arguments :
  24. PROTO_API (.*?)\(
  25. (disable . matches newline)->
  26. PROTO_API (.*?)\(pPath self,
  27. , )
  28. )
  29. add the ; which i forgot :
  30. )\r\n}
  31. );\r\n}
  32. Start removing types from function call arguments :
  33. \{([^\}]*?)const (.*?)\}
  34. (repeat until none left)->
  35. \{\1\2\}
  36. Remove default parameter values from call arguments :
  37. \{([^\}]*?) = (.*?)([,\)])(.*?)\}
  38. ->
  39. \{\1\3\4\}
  40. More removing types and replacing them with conversions (repeat until done) :
  41. \{([^\}]*?)AffineTransform& (.*?)([,)])(.*?)\}
  42. (repeat until none left)->
  43. \{\1\2\.toJuceAff\(\)\3\4\}
  44. \{([^\}]*?)Point<float> (.*?)([,)])(.*?)\}
  45. \{\1\2\.toJucePoint\(\)\3\4\}
  46. Remove basic types from function call argument lists :
  47. \{([^\}]*?)float (.*?)\}
  48. \{\1\2\}
  49. Replace classes by structs in definition argument lists (and return type) :
  50. PROTO_API ([^\)]*?)const AffineTransform& (.*?)\)
  51. PROTO_API \1exAffineTransform \2\)
  52. PROTO_API ([^\)]*?)const Point<float> (.*?)\)
  53. PROTO_API \1exPoint_float \2\)
  54. ========== c++ export header to c ffi import header =========
  55. Remove ex, eg. exPoint_int -> Point_int :
  56. ' ex'
  57. ' '
  58. Remove bodies (mwaha) :
  59. PROTO_API (.*?)\)(.*?)\}\r\n
  60. \1\);\r\n
  61. Remove default values :
  62. = (.*?)([),])
  63. \2
  64. ========== c ffi import header to lua wrapper =========
  65. Remove all parameter types : last param :
  66. ,([^\),]*?) ([^ ]*?)\)
  67. , \2\)
  68. Remove all paramter types : middle params in a line :
  69. , ([^\), ]*?) ([^ ]*?),
  70. , \2\,
  71. Remove all paramter types : middle params after newline :
  72. \r\n([ ]+)(.*?) (.*?),
  73. \r\n\1\3,
  74. Wrap it !
  75. \r\n\r\n([^\r\n]*?) Path_(.*?)\((.*?)\);
  76. \2 = function \(\3\)\r\n\treturn\1 protolib\.Path_\2\(\3\)\r\nend;\r\n\r\n
  77. 'returnvoid '
  78. ''
  79. return(.*?)
  80. return
  81. ldoc madness (gradually remove parameters) :
  82. \r\n\t\t(.*?) = function (\(self,
  83. [ \r\n\t]*?([^\) \r\n\t].*?),
  84. [ \r\n\t]*?([^\) \r\n\t].*?),
  85. [ \r\n\t]*?([^\) \r\n\t].*?),
  86. [ \r\n\t]*?([^\) \r\n\t].*?),
  87. [ \r\n\t]*?([^\) \r\n\t].*?),
  88. [ \r\n\t]*?([^\) \r\n\t].*?),
  89. [ \r\n\t]*?([^\) \r\n\t].*?),
  90. [ \r\n\t]*?([^\) \r\n\t].*?),
  91. [ \r\n\t]*?([^\) \r\n\t].*?)\))
  92. \r\n\t\t--- \1\.
  93. \r\n\t\t-- @param \3
  94. \r\n\t\t-- @param \4
  95. \r\n\t\t-- @param \5
  96. \r\n\t\t-- @param \6
  97. \r\n\t\t-- @param \7
  98. \r\n\t\t-- @param \8
  99. \r\n\t\t-- @param \9
  100. \r\n\t\t-- @param ${10}
  101. \r\n\t\t-- @param ${11}
  102. \r\n\t\t-- @function \1
  103. \r\n\t\t\1 = function \2