【发布时间】:2013-01-29 01:23:58
【问题描述】:
我终于遇到了一个在这里找不到解决方案的问题。我正在使用在这里http://lua-users.org/wiki/CppConvenientLuaWrapperClass 中找到的 Lua 包装类。我们已经能够公开完整的 API 以及更多其他功能,例如串行通信等。
这个 Lua Wrapper 背后的概念是,您在编译之前公开每个方法,因此当您运行程序时,所有方法都将添加到 Lua 堆栈中,这样您就可以执行它们。现在的想法是构建一种 Dll 来完成这个暴露方法的过程。这样您就不需要发布包含所有公开方法的版本,而是通过多个 dll 文件加载它们。
我尝试创建另一个表并在该表中注册其他方法,但这样,以前公开的方法就停止工作了。
我能想到的另一种方法是创建一个 dll,但在 C 中包含所有需要的方法并将其直接加载到 Lua。但我认为另一种方式会更好。
你做过类似的事情吗?我有什么错误的概念吗?
谢谢
嗯...我现在真的不想更改我们的包装。我想我可以设法做到这一点。我没有为插件函数添加一个新表,而是添加了一个新的子表,它将包含要从 Lua 调用的函数名称和 cClosures。 所以最后我们应该有:
application.functionName()
application.plugin.functionName()
即使它以这种方式工作,它也会做得很好。 现在我想知道在公开要添加到 application[plugin][pluginFunction] 而不是 aplication[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 );
关于如何实现将闭包添加到主表(在 mMethodTableIndex)而不是作为 mainTable[functionName] 而是在 maintable[plugin][functionNane] 的任何想法?
【问题讨论】:
-
wxLua 做同样的事情 - 你可以看看他们的代码,看看他们是如何做到的。
-
嗯谢谢,我看看