Raised This Month: $51 Target: $400
 12% 

Workaround for cross calling methods from methodmaps


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fakuivan
Senior Member
Join Date: Nov 2015
Old 08-04-2017 , 10:07   Workaround for cross calling methods from methodmaps
Reply With Quote #1

Calling a method of methodmap1 from methodmap2, while still being able to call a method of methodmap2 from methodmap1 is not something that you can do on sourcepawn. But if you are desperate to do so, I found a workaround (that does not break the compiler ).

Code:
#include <sourcemod>
#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo =  {
	name = "", 
	author = "", 
	description = "", 
	version = "0.0.0", 
	url = ""
};

//we'll define MM2 as a enum, since we won't be calling its functions directly,
//and it can be overwritten by the methodmap later
enum MM2 {  }

methodmap MM1 {
	public MM1()
	{
		//because the methodmap MM2 does not exist yet for sourcepawn, we need to call a function that calls the method
		//functions can be called first and defined later, methods can't
		InstatiateMM2();
		return view_as<MM1>(0);
	}
}

methodmap MM2 {
	public MM2()
	{
		//since MM1 was already defined, we can call it without problems
		MM1 mm1 = MM1();
		return view_as<MM2>(0);
	}
}

//this wraps the MM2 constructor allowing us to call it before it being defined
//this needs to be defined AFTER the method we are trying to call
MM2 InstatiateMM2()
{
	return MM2();
}

public void OnPluginStart()
{
	//infinite loop
	MM1 mm1 = MM1();
}
Note: You'll get a missing tag waring on places where the compiler expected a the methodmap to be returned but the enum was given instead (and vice versa).
__________________

Last edited by fakuivan; 08-06-2017 at 00:27.
fakuivan is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 08-06-2017 , 17:48   Re: Workaround for cross calling methods from methodmaps
Reply With Quote #2

Can you access properties from MM2 via MM1?
__________________
Neuro Toxin is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 08-07-2017 , 22:53   Re: Workaround for cross calling methods from methodmaps
Reply With Quote #3

Quote:
Originally Posted by Neuro Toxin View Post
Can you access properties from MM2 via MM1?
No you can't, unless you make a wrapper for it, like how I did with the MM2 constructor on InstatiateMM2.
__________________
fakuivan is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 08-08-2017 , 09:53   Re: Workaround for cross calling methods from methodmaps
Reply With Quote #4

VoiDeD already filed the bug like 3 years ago. Hopefully someone will patch it.
__________________
fakuivan is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:50.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode