Support plugins written in C++

Rename use of C++ `template` keyword in plugin API function argument
and add `G_BEGIN_DECLS` and `G_END_DECLS` to public header files to
make them easier to include in C++ code. TagManager and Scintilla
headers already have these `extern "C"` blocks so they shouldn't
require any modifications.

The Autotools build system already adds in a `dummy.cxx` to hint
Automake into C++ linking to support Scintilla, which is quite
convenient for dynamically loading of C++ plugins at run-time into
the otherwise C-only program. The other build systems seem to also
use the correct linking.
This commit is contained in:
Matthew Brush 2012-03-28 22:50:18 -07:00
parent 7b8add4019
commit 51dc2e9baf
21 changed files with 101 additions and 9 deletions

View File

@ -145,7 +145,7 @@
*
* Since Geany 0.12 there is a plugin interface to extend Geany's functionality and
* add new features. This document gives a brief overview about how to add new
* plugins by writing a simple "Hello World" plugin in C.
* plugins by writing a simple "Hello World" plugin in C or C++.
*
*
* @section buildenv Build environment
@ -249,6 +249,22 @@ void plugin_cleanup(void)
* some memory, you are right. But it should compile and load/unload in Geany nicely.
* Now you have the very basic layout of a new plugin. Great, isn't it?
*
* @note
*
* If you would rather write the plugin in C++, you can do that by marking the
* plugin functions that it implements as @c extern @c "C", for example:
*
* @code
*
extern "C" void plugin_init(GeanyData *data)
{
}
extern "C" void plugin_cleanup(void)
{
}
* @endcode
*
* @section building Building
*
* First make plugin.o:
@ -262,6 +278,11 @@ void plugin_cleanup(void)
* If all went OK, put the library into one of the paths Geany looks for plugins,
* e.g. $prefix/lib/geany. See @ref paths "Installation paths" for details.
*
* @note
*
* If you are writing the plugin in C++, then you will need to use your C++
* compiler here, for example @c g++.
*
* @section realfunc Adding functionality
*
* Let's go on and implement some real functionality.

View File

@ -24,6 +24,8 @@
#ifndef GEANY_BUILD_H
#define GEANY_BUILD_H 1
G_BEGIN_DECLS
/* Order is important (see GBO_TO_GBG, GBO_TO_CMD below) */
/* * Geany Known Build Commands.
* These commands are named after their default use.
@ -202,4 +204,6 @@ guint build_get_group_count(const GeanyBuildGroup grp);
gchar **build_get_regex(GeanyBuildGroup grp, GeanyFiletype *ft, guint *from);
G_END_DECLS
#endif

View File

@ -29,6 +29,8 @@
#ifndef GEANY_DOCUMENT_H
#define GEANY_DOCUMENT_H 1
G_BEGIN_DECLS
#include "Scintilla.h"
#include "ScintillaWidget.h"
#include "editor.h"
@ -279,4 +281,6 @@ gint document_compare_by_tab_order_reverse(gconstpointer a, gconstpointer b);
void document_grab_focus(GeanyDocument *doc);
G_END_DECLS
#endif

View File

@ -23,6 +23,8 @@
#ifndef GEANY_EDITOR_H
#define GEANY_EDITOR_H 1
G_BEGIN_DECLS
#include "Scintilla.h"
#include "ScintillaWidget.h"
@ -317,4 +319,6 @@ const gchar *editor_find_snippet(GeanyEditor *editor, const gchar *snippet_name)
void editor_insert_snippet(GeanyEditor *editor, gint pos, const gchar *snippet);
G_END_DECLS
#endif

View File

@ -36,6 +36,7 @@
#ifndef GEANY_ENCODINGS_H
#define GEANY_ENCODINGS_H
G_BEGIN_DECLS
typedef enum
{
@ -187,4 +188,6 @@ GeanyEncodingIndex encodings_scan_unicode_bom(const gchar *string, gsize len, gu
GeanyEncodingIndex encodings_get_idx_from_charset(const gchar *charset);
G_END_DECLS
#endif

View File

@ -23,6 +23,8 @@
#ifndef GEANY_FILETYPES_H
#define GEANY_FILETYPES_H 1
G_BEGIN_DECLS
#include "Scintilla.h"
#include "ScintillaWidget.h"
@ -212,4 +214,6 @@ gboolean filetypes_parse_error_message(GeanyFiletype *ft, const gchar *message,
gboolean filetype_get_comment_open_close(const GeanyFiletype *ft, gboolean single_first,
const gchar **co, const gchar **cc);
G_END_DECLS
#endif

View File

@ -25,12 +25,14 @@
#ifndef GEANY_H
#define GEANY_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#if defined(HAVE_CONFIG_H) && defined(GEANY_PRIVATE)
# include "config.h"
#endif
#include <gtk/gtk.h>
#include "tm_tagmanager.h"
#ifndef PLAT_GTK
@ -96,4 +98,6 @@ void geany_debug(gchar const *format, ...) G_GNUC_PRINTF (1, 2);
#define G_GNUC_WARN_UNUSED_RESULT
#endif
G_END_DECLS
#endif

View File

@ -23,6 +23,8 @@
#ifndef GEANY_HIGHLIGHTING_H
#define GEANY_HIGHLIGHTING_H 1
G_BEGIN_DECLS
#include "Scintilla.h"
#include "ScintillaWidget.h"
@ -53,4 +55,6 @@ gboolean highlighting_is_string_style(gint lexer, gint style);
gboolean highlighting_is_comment_style(gint lexer, gint style);
gboolean highlighting_is_code_style(gint lexer, gint style);
G_END_DECLS
#endif

View File

@ -22,6 +22,8 @@
#ifndef GEANY_KEYBINDINGS_H
#define GEANY_KEYBINDINGS_H 1
G_BEGIN_DECLS
/** Function pointer type used for keybinding callbacks. */
typedef void (*GeanyKeyCallback) (guint key_id);
@ -279,4 +281,6 @@ void keybindings_show_shortcuts(void);
gboolean keybindings_check_event(GdkEventKey *ev, GeanyKeyBinding *kb);
G_END_DECLS
#endif

View File

@ -22,6 +22,7 @@
#ifndef GEANY_MSGWINDOW_H
#define GEANY_MSGWINDOW_H 1
G_BEGIN_DECLS
/**
* Various colors for use in the compiler and messages treeviews when adding messages.
@ -101,4 +102,6 @@ void msgwin_parse_compiler_error_line(const gchar *string, const gchar *dir,
gboolean msgwin_goto_messages_file_line(gboolean focus_editor);
G_END_DECLS
#endif

View File

@ -33,6 +33,8 @@
#ifndef GEANY_PLUGINDATA_H
#define GEANY_PLUGINDATA_H
G_BEGIN_DECLS
/* Compatibility for sharing macros between API and core.
* First include geany.h, then plugindata.h, then other API headers. */
#undef GEANY
@ -739,4 +741,6 @@ BuildFuncs;
#endif /* GEANY_DISABLE_DEPRECATED */
G_END_DECLS
#endif

View File

@ -23,6 +23,8 @@
#ifndef GEANY_PREFS_H
#define GEANY_PREFS_H 1
G_BEGIN_DECLS
/** General Preferences dialog settings. */
typedef struct GeanyPrefs
{
@ -57,4 +59,6 @@ extern GeanyToolPrefs tool_prefs;
void prefs_show_dialog(void);
G_END_DECLS
#endif

View File

@ -23,6 +23,8 @@
#ifndef GEANY_PROJECT_H
#define GEANY_PROJECT_H 1
G_BEGIN_DECLS
#define GEANY_PROJECT_EXT "geany"
@ -94,4 +96,6 @@ void project_setup_prefs(void);
void project_apply_prefs(void);
G_END_DECLS
#endif

View File

@ -28,6 +28,8 @@
#ifndef GEANY_SEARCH_H
#define GEANY_SEARCH_H 1
G_BEGIN_DECLS
/* the flags given in the search dialog for "find next", also used by the search bar */
typedef struct GeanySearchData
{
@ -98,4 +100,6 @@ gint search_replace_target(struct _ScintillaObject *sci, const gchar *replace_te
guint search_replace_range(struct _ScintillaObject *sci, struct Sci_TextToFind *ttf,
gint flags, const gchar *replace_text);
G_END_DECLS
#endif

View File

@ -23,6 +23,8 @@
#ifndef GEANY_STASH_H
#define GEANY_STASH_H
G_BEGIN_DECLS
/** Opaque type for a group of settings. */
typedef struct StashGroup StashGroup;
@ -96,4 +98,6 @@ void stash_tree_display(GtkTreeView *tree);
void stash_tree_update(GtkTreeView *tree);
G_END_DECLS
#endif

View File

@ -25,6 +25,7 @@
* @see GLib's @c gi18n-lib.h.
**/
G_BEGIN_DECLS
#include "geany.h"
@ -39,3 +40,5 @@
# define Q_(String) g_strip_context((String), (String))
# define N_(String) String
#endif
G_END_DECLS

View File

@ -128,7 +128,7 @@ static void init_general_templates(void)
}
void templates_replace_common(GString *template, const gchar *fname,
void templates_replace_common(GString *tmpl, const gchar *fname,
GeanyFiletype *ft, const gchar *func_name)
{
gchar *shortname;
@ -143,18 +143,18 @@ void templates_replace_common(GString *template, const gchar *fname,
else
shortname = g_path_get_basename(fname);
templates_replace_valist(template,
templates_replace_valist(tmpl,
"{filename}", shortname,
"{project}", app->project ? app->project->name : "",
"{description}", app->project ? app->project->description : "",
NULL);
g_free(shortname);
templates_replace_default_dates(template);
templates_replace_command(template, fname, ft->name, func_name);
templates_replace_default_dates(tmpl);
templates_replace_command(tmpl, fname, ft->name, func_name);
/* Bug: command results could have {ob} {cb} strings in! */
/* replace braces last */
templates_replace_valist(template,
templates_replace_valist(tmpl,
"{ob}", "{",
"{cb}", "}",
NULL);

View File

@ -28,6 +28,8 @@
#ifndef GEANY_TEMPLATES_H
#define GEANY_TEMPLATES_H 1
G_BEGIN_DECLS
#define GEANY_TEMPLATES_INDENT 3
enum
@ -70,7 +72,7 @@ gchar *templates_get_template_function(GeanyDocument *doc, const gchar *func_nam
gchar *templates_get_template_licence(GeanyDocument *doc, gint licence_type);
void templates_replace_common(GString *template, const gchar *fname,
void templates_replace_common(GString *tmpl, const gchar *fname,
GeanyFiletype *ft, const gchar *func_name);
void templates_replace_valist(GString *text,
@ -78,4 +80,6 @@ void templates_replace_valist(GString *text,
void templates_free_templates(void);
G_END_DECLS
#endif

View File

@ -22,6 +22,8 @@
#ifndef GEANY_TOOLBAR_H
#define GEANY_TOOLBAR_H
G_BEGIN_DECLS
/** Toolbar settings. */
typedef struct GeanyToolbarPrefs
{
@ -59,4 +61,6 @@ void toolbar_finalize(void);
void toolbar_configure(GtkWindow *parent);
G_END_DECLS
#endif

View File

@ -22,6 +22,8 @@
#ifndef GEANY_UI_UTILS_H
#define GEANY_UI_UTILS_H 1
G_BEGIN_DECLS
/** Sets a name to lookup @a widget from @a owner.
* @param owner Usually a window, dialog or popup menu.
@ -345,5 +347,6 @@ GdkPixbuf *ui_get_mime_icon(const gchar *mime_type, GtkIconSize size);
void ui_focus_current_document(void);
G_END_DECLS
#endif

View File

@ -27,6 +27,7 @@
#ifndef GEANY_UTILS_H
#define GEANY_UTILS_H 1
G_BEGIN_DECLS
#include <time.h>
@ -276,4 +277,6 @@ gchar *utils_str_remove_chars(gchar *string, const gchar *chars);
gchar **utils_copy_environment(const gchar **exclude_vars, const gchar *first_varname, ...) G_GNUC_NULL_TERMINATED;
G_END_DECLS
#endif