Best way to implement plugin support

I have software in C ++ MFC that has some open interface for a plugin using export C.

I am going to open the software for external 3-way development. But using export C for hardcore programmers.

What is the best way to implement it? I heard about LUA, but I want to learn about other features.

+5
source share
5 answers

I think it really depends on the type of program and your target audience. WoW probably wouldn't have as many add-ons as C and the compiler would need to write them. But I do not want to write a big addon in Lua.

, , . , . (, , ), .

, - ?

+3

C-, , "" , Nike " ".

, .

0

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], - .

0

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 must export this function that creates a new object that implements
// the PluginInterface;
extern "C" bool CreatePluginObject(PluginInterface**);

Then we implement the sample plugin as a Lua / Javascript / Python bridge and link it to your software. In a field that you support as a closely related C ++ interface, PLUS is a scripted interface with plugins, and if someone prefers another script, he can do it himself.

0
source

All Articles