60 f.lineNumber = lineNumber;
62 std::string clean = line;
63 std::erase(clean,
';');
65 size_t paren = clean.find(
'(');
66 if (paren == std::string::npos)
71 std::string retAndName = clean.substr(0, paren);
72 std::string paramStr = clean.substr(paren + 1, clean.find(
')') - paren - 1);
74 std::istringstream iss(retAndName);
75 iss >> f.returnType >> f.name;
77 paramStr =
trim(paramStr);
78 if (paramStr.empty() || paramStr ==
"void")
83 std::istringstream pstream(paramStr);
85 while (std::getline(pstream, param,
','))
93 std::istringstream ps(param);
103 f.params.push_back(p);
203 std::string inputFile =
"winapi.h";
204 std::string outputFile =
"phasor_winapi.cpp";
210 if (argc >= 4 && std::string(argv[2]) ==
"-o")
212 outputFile = argv[3];
215 std::ifstream infile(inputFile);
216 std::ofstream outfile(outputFile);
218 outfile <<
"#define PHASOR_FFI_BUILD_DLL\n";
219 outfile <<
"#include <PhasorFFI.h>\n";
220 outfile <<
"#include <windows.h>\n";
221 outfile <<
"#include \"../src/Bindings/win32/handle.hpp\"\n\n";
222 outfile <<
"// =====BEGIN PATCHES=====\n";
223 for (
const auto &patch :
PATCHES)
225 outfile << patch <<
"\n";
227 outfile <<
"// ======END PATCHES======\n\n";
231 std::vector<Function> funcs;
233 while (std::getline(infile, line))
242 if (!f.returnType.empty())
248 for (
const auto &f : funcs)
253 outfile <<
"PHASOR_FFI_EXPORT void phasor_plugin_entry(const PhasorAPI* api, PhasorVM* vm) {\n";
254 for (
const auto &f : funcs)
256 outfile <<
" api->register_function(vm, \"win32_" << f.name <<
"\", win32_" << f.name <<
");\n";
bool isSupportedParam(const std::string &type)
std::string trim(const std::string &str)
const std::vector< std::string > PATCHES
bool isHandleType(const std::string &type)
Function parseFunction(const std::string &line, int lineNumber)
void generateWrapper(const Function &f, std::ostream &out)