解析C头文件生成文件

发布于 2024-12-09 14:11:56 字数 1352 浏览 1 评论 0 原文

我正在致力于将 GTK+ 移植到 Node.js,其中一个困难是将 GTK+ 函数转换为相应的 C++ 调用。例如,

void       gtk_window_set_title                (GtkWindow           *window,
                        const gchar         *title);
G_CONST_RETURN gchar *gtk_window_get_title     (GtkWindow           *window);
void       gtk_window_set_role                 (GtkWindow           *window,
                                                const gchar         *role);
void       gtk_window_set_startup_id           (GtkWindow           *window,
                                                const gchar         *startup_id);
G_CONST_RETURN gchar *gtk_window_get_role      (GtkWindow           *window);

将转换为:

SETTER_METHOD (Window , "setTitle"      , gtk_window_set_title      , const gchar*) ;
GETTER_METHOD (Window , "getTitle"      , gtk_window_get_title      , const gchar*) ;
SETTER_METHOD (Window , "setRole"       , gtk_window_set_role       , const gchar*) ;
SETTER_METHOD (Window , "setStartupId"  , gtk_window_set_startup_id , const gchar*) ;
GETTER_METHOD (Window , "getRole"       , gtk_window_get_role       , const gchar*) ;

因此 1) 我必须在新的宏调用中保留 C 声明的参数(实际上,它们将扩展为模板参数)。 2)必须区分返回某些内容和不返回任何内容的函数,它们将被称为 SETTER_METHODGETTER_METHOD,这是因为我无法将它们合并到一个调用中需要部分函数模板专门化。

有没有工具可以实现这一目标?

I'm working on porting GTK+ to node.js, one difficulty is converting GTK+ functions to corresponding C++ call. For example,

void       gtk_window_set_title                (GtkWindow           *window,
                        const gchar         *title);
G_CONST_RETURN gchar *gtk_window_get_title     (GtkWindow           *window);
void       gtk_window_set_role                 (GtkWindow           *window,
                                                const gchar         *role);
void       gtk_window_set_startup_id           (GtkWindow           *window,
                                                const gchar         *startup_id);
G_CONST_RETURN gchar *gtk_window_get_role      (GtkWindow           *window);

will be converted to:

SETTER_METHOD (Window , "setTitle"      , gtk_window_set_title      , const gchar*) ;
GETTER_METHOD (Window , "getTitle"      , gtk_window_get_title      , const gchar*) ;
SETTER_METHOD (Window , "setRole"       , gtk_window_set_role       , const gchar*) ;
SETTER_METHOD (Window , "setStartupId"  , gtk_window_set_startup_id , const gchar*) ;
GETTER_METHOD (Window , "getRole"       , gtk_window_get_role       , const gchar*) ;

So 1) I must preserve the parameters of C declarations in the new macro calls (indeed, they will be expanded to template arguments). And 2) functions returning something and those return nothing must be distinguished, they will be called as SETTER_METHOD or GETTER_METHOD, this is because I can't merge them in one call which needs partial function template specialization.

Is there a tool to achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风挽心 2024-12-16 14:11:56

node.js 似乎是 V8 Google Chrome 使用的 JavaScript 引擎。您想要创建的是 GTK 的新 javascript 绑定,这应该使用 GObject-introspection 工作来完成,而不是手动绑定每个函数。

看看 GjsSeed 官方 GTK 的 Javascript 绑定

node.js seems to be the Javascript implementation of the V8 Javascript engine used by Google Chrome. What you want to create is a new javascript binding for GTK, and this should be done using the GObject-introspection work, not binding each function by hand.

Give a look at what has been done for Gjs and Seed official Javascript bindings for GTK.

说好的呢 2024-12-16 14:11:56

不确定是否有特定的工具,但您应该能够使用 REGEX 快速创建一个解析器。 BOOST 正则表达式非常容易理解,应该可以让您快速理解。

Not sure there is a specific tool, but you should be able to whip up a quick parser using REGEX. BOOST regex is quite easy to understand and should get you there quickly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文