Question

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.

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top