简体   繁体   中英

How can I get list of all table names in .lua script using Lua C API?

I have a lua file which looks like this:

tableA = {…}
tableB = {…}
tableC = {…}

I want to get std::vector which will contain the names of all tables defined in file: {"tableA", "tableB", "tableC"}

How can I do this with Lua C API?

To get the names of random global variables created during the execution of a script file you will need to use environment games to run the script in your own "global" context.

If you can modify the script it would be much easier to get it to return the tables (or just their names) to the calling script.

Tables don't have names. Variables do. In this case, the variables are globals so the variable name is just a key in the globals table. That said, if this is an API you're writing, then it's probably a bad design. You should give the script a means of "registering" meaningful values rather than forcing the script author to put them in a specific place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM