satoren / kaguya

C++ binding to Lua
Boost Software License 1.0
345 stars 70 forks source link

Access subtables directly #67

Closed Sygmei closed 7 years ago

Sygmei commented 7 years ago

Is there another way to access a subtable ?

I know you can do :

luavm["a"]["b"]["c"] = 10;

But is it possible to do something like :

std::string path = "a.b.c";
luavm.access(path);

?

OvermindDL1 commented 7 years ago

Nested tables are actually tables inside tables, they are not keyed based on the full path. Doing a dot access like that needs to be run 'inside' the lua vm, so you can access it just be executing inside the vm a string of that form as that is what would have to be done anyway.

satoren commented 7 years ago
std::string path = "a.b.c";
kaguya::LuaRef value = luavm.loadstring("return "+path)(); // get
luavm.loadstring(path + "= ...")("newvalue"); // set
Sygmei commented 7 years ago

What I needed ! Thank you :)