Lua API: Named tuples no longer all have the same __metatable
Now the __metatable contains the list of member names. This means that wesnoth.type won't treat named tuples with different members as the same thing – not evne if they're the same length. Which is probably a good thing!
This commit is contained in:
parent
2a26a68025
commit
1b63da9974
1 changed files with 11 additions and 1 deletions
|
@ -720,7 +720,17 @@ void luaW_push_namedtuple(lua_State* L, const std::vector<std::string>& names)
|
|||
{ nullptr, nullptr }
|
||||
};
|
||||
luaL_setfuncs(L, callbacks, 0);
|
||||
lua_pushliteral(L, "named tuple");
|
||||
static const char baseName[] = "named tuple";
|
||||
std::ostringstream str;
|
||||
str << baseName << '(';
|
||||
if(!names.empty()) {
|
||||
str << names[0];
|
||||
}
|
||||
for(size_t i = 1; i < names.size(); i++) {
|
||||
str << ", " << names[i];
|
||||
}
|
||||
str << ')';
|
||||
lua_push(L, str.str());
|
||||
lua_setfield(L, -2, "__metatable");
|
||||
lua_push(L, names);
|
||||
lua_setfield(L, -2, "__names");
|
||||
|
|
Loading…
Add table
Reference in a new issue