开发者

Parse C header file to generate files

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜