我终于遇到了一个问题,我在这里找不到解决方案。我正在使用在这里找到的Lua Wrapper类http://lua-users.org/wiki/CppConvenientLuaWrapperClass。我们已经能够公开一个完整的API以及其他更多的功能,如串行通信等等。Lua Wrapper类 - 通过DLL向Lua公开C++静态方法
这个Lua Wrapper背后的概念是,你在编译之前公开每一个方法,所以当你运行你的程序时,所有的方法都会被添加到Lua栈中,并以这种方式执行它们。现在的想法是构建一种Dll来完成这个暴露方法的过程。这样你就不需要发布一个包含所有公开方法的版本,而是通过多个dll文件加载它们。
我试着创建另一个表,并在该表中注册其他方法,但与此,以前暴露的方法停止工作。
另一种方式我可以想到的是创建一个DLL,但在C中包含所有可取的方法,并直接加载到Lua。但我认为另一种方式会更好。
你能够做类似的事情吗?我有一些错误的概念吗?
感谢
赫姆...我真的不希望在这个时候改变我们的包装。我想我可以设法做到这一点。我没有为插件函数添加一个新表格,而是添加了一个新的子表格,其中包含要从Lua调用的函数名称和cClosures。 所以在最后,我们应该有:
application.functionName()
application.plugin.functionName()
即使这样工作就会做得很好。 现在我想知道如何在公开要添加到应用程序[plugin] [pluginFunction]而不是应用程序[pluginFunction]的函数时引用lua_settable ?! 这是怎样的正常功能被暴露:
//mState is a pointer to a Lua_State
lua_pushstring(mState, functionName);
//methodDesc is a pointer to an object that describes the function arguments/returns
lua_pushlightuserdata(mState, methodDesc);
//exposeMethodProxy is the method that is responsible for conneting lua c-calls to the c-functions
lua_pushcclosure(mState, exposedMethodProxy, 1);
//mMethodTableIndex is a member variable that contains the index of the table tha hold all exposed functions
lua_settable(mState, mMethodTableIndex);
上我如何能实现将所述cclosures不到主表(在mMethodTableIndex)作为mainTable [functionName],但在maintable [插件]任何想法[functionNane] 。?
wxLua做同样的事情 - 你可以看看他们的代码,看看他们是如何做到的。 – finnw 2013-02-13 14:19:40
Humm谢谢,我会看看 – MRodrigues 2013-02-14 14:07:14