This is part 2.5 of my Lua tutorial. Why 2.5 and not 3? Well, because this tutorial doesn’t introduce any new concepts. I’ll point out some bug fixes I made and what improvements can be done. It won’t be too big.

The code is almost the same, but note that it uses lua_tostring, not lua_tonumber as in template version.
This code is not 100% safe and can fail if your array contains both numbers and strings. To prevent this you can add additional check:

Improvements
Some people noted that using only one Lua state is enough. This way you can make Lua state a static variable. But you have to be careful, because you have to be sure that you’ll open and close files when it’s needed, so you don’t try to read variables from files where they’re not defined.
It’ll look like this:

Open file1

Load data

Close file1

Open file2

Load data

Close file2

That way you don’t have to create new Lua state for every script file. You can load files with luaL_dofile(L, filename) and close them with lua_close(L)

And that’s all for today. Part 3 is unfortunately delayed, because I still don’t use Lua code to modify C++ objects so I don’t really know what works well and what doesn’t.

P. S. I still didn’t recieve enough feedback about the first and the second tutorials. If you want to add something, please, write me. eliasdaler@yandex.ru
P. P. S. Simple “thanks” if you find my tutorials useful will do too! ;D