diff --git a/src/library.cpp b/src/library.cpp index 2a7bbf07b3..ae3212d6f3 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -38,6 +38,7 @@ #include "neighbor.h" #include "region.h" #include "output.h" +#include "plugin.h" #include "thermo.h" #include "timer.h" #include "universe.h" @@ -4581,6 +4582,59 @@ int lammps_id_name(void *handle, const char *category, int idx, return 0; } +/* ---------------------------------------------------------------------- */ + +/** Count the number of loaded plugins + * +\verbatim embed:rst +This function counts how many plugins are currently loaded. + +.. versionadded:: 10Mar2021 + +\endverbatim + * + * \return number of loaded plugins + */ +int lammps_plugin_count() +{ + return plugin_get_num_plugins(); +} + +/* ---------------------------------------------------------------------- */ + +/** Look up the info of a loaded plugin by its index in the list of plugins + * +\verbatim embed:rst +This function copies the name of the *style* plugin with the index +*idx* into the provided C-style string buffer. The length of the buffer +must be provided as *buf_size* argument. If the name of the style +exceeds the length of the buffer, it will be truncated accordingly. +If the index is out of range, the function returns 0 and *buffer* is +set to an empty string, otherwise 1. + +.. versionadded:: 10Mar2021 + +\endverbatim + * + * \param idx index of the plugin in the list all or *style* plugins + * \param stylebuf string buffer to copy the style of the plugin to + * \param namebuf string buffer to copy the name of the plugin to + * \param buf_size size of the provided string buffers + * \return 1 if successful, otherwise 0 + */ +int lammps_plugin_name(int idx, char *stylebuf, char *namebuf, int buf_size) +{ + stylebuf[0] = namebuf[0] = '\0'; + + const lammpsplugin_t *plugin = plugin_get_info(idx); + if (plugin) { + strncpy(stylebuf,plugin->style,buf_size); + strncpy(namebuf,plugin->name,buf_size); + return 1; + } + return 0; +} + // ---------------------------------------------------------------------- // utility functions // ---------------------------------------------------------------------- diff --git a/src/library.h b/src/library.h index d98bf426b3..11cd72388a 100644 --- a/src/library.h +++ b/src/library.h @@ -205,6 +205,9 @@ int lammps_has_id(void *, const char *, const char *); int lammps_id_count(void *, const char *); int lammps_id_name(void *, const char *, int, char *, int); +int lammps_plugin_count(); +int lammps_plugin_name(int, char *, char *, int); + /* ---------------------------------------------------------------------- * Utility functions * ---------------------------------------------------------------------- */