如何编写 C++字典到Lua表?

发布于 2024-09-07 03:12:08 字数 174 浏览 2 评论 0原文

我有一些 C++ 代码与一些 Lua 代码交互。基本上,我希望能够从查询消息中获取一些结果(以字典的形式,也称为项目集合),然后将它们作为表推送到 Lua,以便我可以通过以下方式轻松访问 Lua 的所有结果:使用字典。

现在,我只得到一个我想要的特定值并将其发送出去,但最好将所有这些值都发送出去,而不必请求特定的值。

I have some C++ code that interacts with some Lua code. Basically, I want to be able to get some results (in the form of a dictionary a.k.a. a collection of items) from a query message and then push them out to Lua as a table so that I can easily access all the results from Lua by using the dictionary.

Right now, I just get one specific value that I want and send that out but it would be nice to send all of them out and not have to request a specific one.

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

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

发布评论

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

评论(1

衣神在巴黎 2024-09-14 03:12:08

假设您总体上熟悉 Lua API,以下是基本过程:

  1. 在堆栈上创建一个新表 (lua_newtable)
  2. 对于字典中的每一项
    1. 将值压入堆栈
    2. 将密钥压入堆栈
    3. 调用lua_settable

Assuming you're familiar with the Lua API in general, here's the basic process:

  1. Create a new table on the stack (lua_newtable)
  2. For each item in the dictionary
    1. Push the value onto the stack
    2. Push the key onto the stack
    3. Call lua_settable
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文