You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is for user settings and other dynamic data that may be set in an application's C++ code or by a script extension.
All the following examples currently work.
Key / value in C++
table t;
t["health"] = 100;
t["windowsettings"] = table();
t["windowsettings"]["position"] = 3;
for (auto a : t)
{
std::string s = a.first;
Print(s);
s = a.second;
Print(s);
}
Array in C++
table arr;
arr.push_back(1);
arr.push_back(2);
arr.push_back(3);
arr.push_back(4);
arr.push_back(5);
for (int n = 0; n < arr.size(); ++n)
{
Print(std::string(arr[n]));
}
Mixing Key / value and array-style keys
table t;
t["health"] = 100;
t["windowsettings"] = table();
t["windowsettings"]["position"] = 3;
t.resize(10);
for (int n = 0; n < t.size(); ++n)
{
t[n] = n;
}
t.resize(5);
Print("Size: " + String(t.size()));
for (auto a : t)
{
std::string s = a.first;
Print(s);
s = a.second;
Print(s);
}
Key / value in Lua
locala=Table()
a["health"] =100a["color"] ="blue"fork,vinpairs(a) doPrint(k..": "..tostring(v))
end
Arrays in Lua
b=Table()
b[1] =1b[2] =2b[3] =3b[4] =4forn=1, #bdoPrint(b[n])
end
The only thing missing is support for ipairs:
b=Table()
b[1] =1b[2] =2b[3] =3b[4] =4-- "Error: No matching function call takes this number of arguments and the specified types"fork,vinipairs(b) doPrint(b[n])
end
Can we get a similar example for implementing ipairs?
Pairs and ipairs probably are implemented the same way.
Originally totally looked at the wrong things here.
The issue is that in your lua code you do this:
b=Table()
b[1] =1b[2] =2b[3] =3b[4] =4-- "Error: No matching function call takes this number of arguments and the specified types"fork,vinipairs(b) doPrint(b[n])
end
but n in b[n] is not defined.
If you use the same code for printing inside the for loop as you use in pairs then it should work.
I'm developing an STL-like table class for C++
https://github.com/UltraEngine/tableplusplus
Features
This is for user settings and other dynamic data that may be set in an application's C++ code or by a script extension.
All the following examples currently work.
Key / value in C++
Array in C++
Mixing Key / value and array-style keys
Key / value in Lua
Arrays in Lua
The only thing missing is support for ipairs:
I based my pairs() implementation off the code here:
https://github.com/ThePhD/sol2/blob/7aae1aaaaa1bbcc03fd059fe38075cfe3f4b2e90/examples/source/pairs.cpp
Can we get a similar example for implementing ipairs?
The text was updated successfully, but these errors were encountered: