Generate a lambda wrapper for a member function reference type: "webcc::function " method_name: "handleNoopEvent" Returns: "[this](const webcc::string& _arg0) { this->handleNoopEvent(_arg0); }"
| 26 | // method_name: "handleNoopEvent" |
| 27 | // Returns: "[this](const webcc::string& _arg0) { this->handleNoopEvent(_arg0); }" |
| 28 | inline std::string generate_member_function_lambda(const std::string &type, const std::string &method_name) |
| 29 | { |
| 30 | // Parse function type to extract parameters |
| 31 | // Format: webcc::function<return_type(param_types...)> |
| 32 | size_t left_angle = type.find('<'); |
| 33 | size_t right_angle = type.rfind('>'); |
| 34 | if (left_angle == std::string::npos || right_angle == std::string::npos) |
| 35 | return method_name; |
| 36 | |
| 37 | std::string inner = type.substr(left_angle + 1, right_angle - left_angle - 1); |
| 38 | // inner is "void(webcc::string)" or "void()" etc. |
| 39 | |
| 40 | size_t left_paren = inner.find('('); |
| 41 | size_t right_paren = inner.rfind(')'); |
| 42 | if (left_paren == std::string::npos || right_paren == std::string::npos) |
| 43 | return method_name; |
| 44 | |
| 45 | std::string return_type = inner.substr(0, left_paren); |
| 46 | std::string params_str = inner.substr(left_paren + 1, right_paren - left_paren - 1); |
| 47 | |
| 48 | // Parse parameters (comma-separated) |
| 49 | std::vector<std::string> param_types; |
| 50 | if (!params_str.empty()) |
| 51 | { |
| 52 | int depth = 0; |
| 53 | std::string current; |
| 54 | for (char c : params_str) |
| 55 | { |
| 56 | if (c == '<') |
| 57 | depth++; |
| 58 | else if (c == '>') |
| 59 | depth--; |
| 60 | else if (c == ',' && depth == 0) |
| 61 | { |
| 62 | // Trim whitespace |
| 63 | size_t start = current.find_first_not_of(" \t"); |
| 64 | size_t end = current.find_last_not_of(" \t"); |
| 65 | if (start != std::string::npos) |
| 66 | { |
| 67 | param_types.push_back(current.substr(start, end - start + 1)); |
| 68 | } |
| 69 | current.clear(); |
| 70 | continue; |
| 71 | } |
| 72 | current += c; |
| 73 | } |
| 74 | if (!current.empty()) |
| 75 | { |
| 76 | size_t start = current.find_first_not_of(" \t"); |
| 77 | size_t end = current.find_last_not_of(" \t"); |
| 78 | if (start != std::string::npos) |
| 79 | { |
| 80 | param_types.push_back(current.substr(start, end - start + 1)); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // Generate lambda |