正确的软件工程方法使 Lua 绑定到我的 C++课程?

发布于 2024-09-06 05:20:31 字数 1431 浏览 8 评论 0原文

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

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

发布评论

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

评论(2

饮湿 2024-09-13 05:20:31

我明白你问的意思

从软件设计的角度来看,
不是编码视角

,但我不确定两者之间有明显的区别。或者,更准确地说,您采用的编码方法将决定您的设计选项。例如,如果您使用 SWIG,问题中的选项实际上没有意义,因为您编写了一个单独的“接口”文件。如果您使用 luabind,这些选项确实有意义,但我肯定会选择 1) 在这种情况下,因为 luabind 标头会显着减慢编译速度,我希望将它们包含在尽可能少的编译单元中。如果你的“编码”方法没有 luabind 的缺点,那么 2) 似乎是更明智的做法。

I understand what you mean by asking

from a software design perspective,
not a coding perspective

however I'm not sure there's clear distinction between the two. Or, more correctly, the coding approach you take will determine your design options. For example, if you use SWIG, the options in your question don't really make sense, since you write a separate "interface" file. If you are using luabind, the options do make sense, but I would definitely choose 1) in that case as luabind headers slow compilation dramatically and I'd like to have them included in as few compilation units as possible. If your "coding" approach doesn't have that luabind shortcoming then 2) seems like the more sensible thing to do.

自此以后,行同陌路 2024-09-13 05:20:31

你的第二种方法会很有效。避免多次注册的一种方法是使用静态初始化列表方法。每个类都会向静态 std::set pre-main 添加一个 Lua 注册函数。然后,当应用程序启动时,您将遍历此 std::set 并将每个类构造函数绑定添加到 Lua 运行时。这将确保您的类绑定仅注册一次。

Your second approach will work well. One way to avoid multiple registrations is to use a static initialization list approach. Each class would add a Lua registration function to a static std::set pre-main. Then you'd walk this std::set when your application starts and add each class constructor binding to your Lua runtime. This would ensure your class bindings are registered only once.

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