实现插件支持的最佳方式

发布于 2024-10-14 01:30:43 字数 133 浏览 3 评论 0原文

我有一个 C++ MFC 中的软件,它有一些使用 C 导出的插件的公共接口。

我即将打开该软件以供外部 3 方开发。 但使用 C 导出是针对铁杆程序员的。

实施它的最佳方式是什么?我听说过 LUA,但想了解其他可能性。

i have a software in c++ MFC that have some public interface for plugin using C exports.

I´m about to open the software for external 3 party development.
But using a C export are for hardcore programmers.

What the best way to implement it ? I heard about LUA, but want to know about other possibilities.

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

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

发布评论

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

评论(5

情丝乱 2024-10-21 01:30:43

我认为这实际上取决于节目的类型和目标受众。如果魔兽世界需要 C 和编译器来编写它们,那么它肯定不会有那么多的插件。但我肯定不想用 Lua 写一个大的插件。

因此,首先您需要决定是要使用脚本语言还是编译语言。如果您的目标是临时用户,那么脚本语言可能是更好的选择。如果您的目标是专业开发人员(例如,其插件由内部程序员开发的财务包),那么编译语言可能效果最好。

哦,还有 - 你为什么不问问一群潜在的插件开发人员呢?

I think this really depends on the type of program and your target audience. WoW sure wouldn't have as many addons as it does had it required C and a compiler to write them. But I sure wouldn't want to write a large addon in Lua.

So, before anything else you need to decide whether you want to use a scripting language or a compiled language. If you target casual users then a scripting language might be a better choice. If you target professional developers (say, a financial package whose addons are developed by in-house programmers) then compiled language might work best.

Oh, and also - why don't you ask a bunch of potential plugin developers?

一抹微笑 2024-10-21 01:30:43

如果您有适合您的 C 导出编程示例,我建议您将先入为主的“核心”概念放在一边,正如 Nike 所说的“只管去做”。

这很可能比您预期的要容易。

If you have C export programming examples that work for you I suggest you put your pre-conceived "hardcore" notions aside and as Nike says "just do it."

It may well be easier than you expected.

短叹 2024-10-21 01:30:43

我们使用 c 命名约定和 dlopen\LoadLibrary 系列函数来加载插件(.dll 或 .so),找到 3 个所需的方法 (create_plugin()destroy_plugin()get_type()

插件实现者只需确保等效项(无论他们使用什么语言)在库中可见,

extern "C" PLUGIN_API plugin_interface* create_plugin( arg_pack* );
extern "C" PLUGIN_API void destroy_plugin( plugin_interface* );
extern "C" PLUGIN_API const char* get_type();

具体取决于什么。您需要您的插件来执行此操作,可以将 arg_pack 替换为特定参数。

查看 [gmodule][1] 的文档以查看执行此类操作的跨平台库。

We use a c-naming convention and the dlopen\LoadLibrary family of functions to load a plugin (.dll or .so), find the 3 needed methods (create_plugin(), destroy_plugin(), and get_type().

A plugin implementer merely has to make sure that the equivalent (in whatever language they use) is visibile in the library

extern "C" PLUGIN_API plugin_interface* create_plugin( arg_pack* );
extern "C" PLUGIN_API void destroy_plugin( plugin_interface* );
extern "C" PLUGIN_API const char* get_type();

Depending on what you need your plugin to do, arg_pack can be replaced with specific arguments.

Check out the documentation for [gmodule][1] to see a cross-platform library to do this type of thing.

十年不长 2024-10-21 01:30:43

想要吸引人吗? JavaScript 很热门。嵌入 v8 引擎。

http://code.google.com/apis/v8/embed.html

Want to attract folks? JavaScript is hot. Embed the v8 engine.

http://code.google.com/apis/v8/embed.html

我喜欢麦丽素 2024-10-21 01:30:43

使用导出的 C 函数来创建和返回接口来实现二进制接口。

// your_plugin_header

// Plugins must implement this interface
struct PluginInterface {
  virtual void Release()=0;
  virtual void Method()=0;
  virtual void Method2()=0;
};


// Plugin dll's must export this function that creates a new object that implements
// the PluginInterface;
extern "C" bool CreatePluginObject(PluginInterface**);

然后,实现一个示例插件作为 Lua / Javascript / Python 桥接器,并将其与您的软件捆绑在一起。开箱即用,您既支持紧密耦合的 C++ 接口,又支持高度可脚本化的插件接口,并且,如果有人喜欢不同的脚本,他们可以自己完成。

Implement a binary interface using exported C functions to create and return interfaces.

// your_plugin_header

// Plugins must implement this interface
struct PluginInterface {
  virtual void Release()=0;
  virtual void Method()=0;
  virtual void Method2()=0;
};


// Plugin dll's must export this function that creates a new object that implements
// the PluginInterface;
extern "C" bool CreatePluginObject(PluginInterface**);

Then, implement an example plugin as a Lua / Javascript / Python bridge, and bundle that with your software. Out the box you support both a tightly coupled C++ interface, PLUS a highly scriptable plugin interface, AND, if anyone prefers a different script, they can do it themselves.

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