Closed OberKnirps closed 1 month ago
Thanks for this thorough report. Unfortunately this is a squirrel issue mostly, the best we could do is throw the error when trying to set a key with a value that is already a function in the ordered map :/
I don't think there's an alternative complete solution here because you should be able to access the ordered map via dot notation Map.Value
vs Map["Value"]
, and you could not do that with something that is already a function on the ordered map.
I thought as much. An error would be good though, because finding out what the actual cause was, was a bit convoluted.
Other solutions I could think of were:
m
within the ordered map and than accessing it with ordered_map.m["filter"]
, but it then breaks everything that uses ordered maps and kind of defeats the point of how they were written in the first place.::MSU.Functions.OrderedMap.filter(myMap, filterFunction);
which also breaks things and shouldn't be that convoluted.Also a disclaimer/info in the wiki could be helpful, but it's also pretty uncommon problem to run into.
I'd say we disallow adding anything to the container which is a key already present in the container class and we throw it at that point. This way the modder knows that they must choose a different name for their item.
function _newslot( _key, _value )
{
if (_key in ::MSU.Class.OrderedMap)
throw _key + " is a reserved keyword in class";
if (!(_key in this.Table))
{
this.Array.push(_key);
}
this.Table[_key] <- _value;
}
@LordMidas yeah your solution is probably best
Versions
Describe the bug When adding an entry to the map and using "filter" (or any other function name of ordered map) as a key, accessing that entry results in returning the function address of the
filter()
function.To Reproduce
prints
but when accessing directly
it prints the proper result
Additional context I noticed the bug while adding settings for my mod and used "filter" as an ID. At first I wanted to report it as a bug related to
settings_page.nut
, but after a bit of digging it turned out to be a bug inordered map
. Therefore I'm adding my original bug report, but following bug should result in the problem above: