Bug 6188 - Cyclical methodmap references
Cyclical methodmap references
Status: NEW
Product: SourceMod
Classification: Unclassified
Component: Transitional API
1.7 branch
All All
: P5 enhancement
Assigned To: SourceMod Bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-07-13 20:23 PDT by Ryan Stecker [:VoiDeD]
Modified: 2017-08-04 18:43 PDT (History)
5 users (show)

See Also:


Attachments

Description Ryan Stecker [:VoiDeD] 2014-07-13 20:23:40 PDT
Would it be possible to introduce cyclical methodmap references?

I know that the transitional API wiki page states "methodmaps must be declared before they are used.", but can this restriction be easily worked around?

For instance, a methodmap layout like this is impossible to implement, but would be very useful:

methodmap Player
{
	public Weapon GetWeapon()
	{
		return Weapon:1;
	}
};

methodmap Weapon
{
	public Player GetOwningPlayer()
	{
		return Player:1;
	}
};

In C/C++, this is worked around with forward declarations, whereas in C# the declaration order doesn't matter to the compiler.

Would one of these options be feasible?
Comment 1 David Anderson [:dvander] 2014-07-13 20:48:14 PDT
If you don't need anything fancier, you can forward-declare the tags by doing:

enum Weapon: {};

(The : after "Weapon" adds the tag without creating an actual empty enum-struct.)

Otherwise... if for example GetWeapon needs to construct an actual weapon via its constructor, that entrains the exact same problems as the other bug you mentioned involving use-before-declaration. It's feasible, but complicate.
Comment 2 Ryan Stecker [:VoiDeD] 2014-07-13 20:57:27 PDT
(In reply to David Anderson [:dvander] from comment #1)
Ideally I'd like to be able to construct using Weapon, but being able to forward declare the Weapon tag can work for now.

The only problem when doing this is a tag mismatch warning when retagging `Weapon:1`:

enum Weapon: {};

methodmap Player
{
	public Weapon GetWeapon()
	{
		// warning 213: tag mismatch
		return Weapon:1;
	}
};

methodmap Weapon
{
	public Player GetOwningPlayer()
	{
		return Player:1;
	}
};
Comment 3 David Anderson [:dvander] 2014-07-13 21:14:25 PDT
Yeah, I agree it's gross. I'll think about how to approach this though I don't think I'll tackle it immediately.
Comment 4 Facundo [:fakuivan] 2017-08-04 14:47:30 PDT
I've come up with a (gross) workaround, but I still get the missing tags warning

https://forums.alliedmods.net/showthread.php?t=300065

Hope this gets fixed
Comment 5 Fyren 2017-08-04 18:43:04 PDT
I started a patch to do this forever ago, but forgot about it.  Bother me on IRC in like a week if I haven't finished it.  I think the incomplete work is a PR currently.

Note You need to log in before you can comment on or make changes to this bug.