我有一个程序可以创建粗略的类型,以便被其他库覆盖。 例如,一个名为ScriptEng的Base类,它被一个库覆盖,用于脚本实现;例如Lua。
因此,此库从ScriptEng创建一个名为LuaScriptEng的类型。
在运行期间调用libray并创建指向此类型的指针。
ScriptEng* script = LoadClassFromLibrary("LuaScriptEng.dll","LuaScriptEng");
或者
ScriptEng* script = LoadClassFromLibrary("SqurrelScript.dll","SqurrelScriptEng");
当我尝试将Other类方法传递给此实例以暴露此嵌入式语言时,会出现问题。
Game* game = new Game(); //contains stuff.
auto game_bind = script->createClass<Game>("Game", game);
game_bind->bindMethod("helo", &Game::hello);
这一切都很好,直到我必须覆盖LuaScriptEng类中的类方法。
class ScriptEng
{
public:
ScriptEng();
template<class T>
ScriptClass<T>* createClass(const std::string& name,T* cla)
{
//Implement per engine information here in children
return new ScriptClass<T>(cla);
}
virtual bool callFunction(const std::string& name)
{
return true;
}
virtual ~ScriptEng();
};
因为在这个意义上不可能有一个虚拟的&#34;模板功能。
我无法为此做好工作,除非我当然创建了许多静态函数,而不是将类绑定到我使用它们的部分。
我试图将函数暴露给脚本lang,因为它更容易理解调用类型,如
Game.somefunction(); //From lua or some other lang, call the current instance of this function.
现在我的解决方法的想法可能会奏效,但它确实很混乱。
从我读到的内容中,在这种情况下包装泛型将是&#34; Type erasure&#34;但是在这样做的时候,我正在寻找每个脚本调用5-9个函数调用附近的某个地方,这真的会让程序陷入困境。
除此之外,有什么更好的方法可以做到这一点?