There is no custom type in lua, anything except nil could be a key in map.
fgl
Type
TMap = specialize TFPGMap<Foo, TData>;
If Foo is not a "simple" type, it must implement class operators _=, _< and _>. This because TMap inherits the method Sort.
use Object::Pad;
class Foo {
has $x :param = 0;
}
my $p = Foo->new(x =>5);
my %map;
$map{$p} = 'some data';
This uses Object::Pad to define a "type", but could just as easily use Moose or Moo, or an old-fashioned blessed hashref. An object is instantiated and inserted into %map. Perl calls the object's stringify method to form the key so it better return a unique value for every object! See also Tie::RefHash.
package Foo {
subnew{
my $class = shift;
returnbless { @_ }, $class
}
};
my $p = Foo->new(x =>5);
my %map;
$map{$p} = 'some data';
Using perl classic OO, define a class Foo, then object $p, and insert $p in hash %map with value 'some data'. Perl will stringify $p to Foo=HASH(0x######), which is the address of the object reference. Add a stringify method and overload to provide a different key for hashing.