Raised This Month: $13 Target: $400
 3% 

Methodmap Circular Dependency


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
clug
Junior Member
Join Date: May 2016
Location: Australia
Old 03-03-2018 , 06:21   Methodmap Circular Dependency
Reply With Quote #1

Hi guys,
I've been working on an include for some custom data structures I need that other extensions/includes don't seem to solve. However, I've hit a roadblock, as I have two methodmaps that depend on each other, and I can't seem to find a way to prototype them as I would in any other language to make it work.

Here's a slimmed down example of what I'm trying to achieve:
PHP Code:
methodmap _Array {
    public 
_Object Get_Object() { /* code here */ };
    public 
bool Set_Object(_Object value) { /* code here */ };
}

methodmap _Object {
    public 
_Array Get_Array() { /* code here */ };
    public 
bool Set_Array(_Array value) { /* code here */ };

Obviously by default it won't work, but does prototyping exist for methodmaps in Pawn? I attempted putting this at the top of the include:
PHP Code:
methodmap _Object { }
methodmap _Array { } 
So that they are visible to one another, but this just results in an error:
Code:
error 110: _Array has already been defined (previously seen as methodmap)
Any ideas?
Thanks!

Last edited by clug; 03-03-2018 at 06:23.
clug is offline
KliPPy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-03-2018 , 07:00   Re: Methodmap Circular Dependency
Reply With Quote #2

https://github.com/alliedmodders/sourcepawn/pull/65
It's in the works but no there haven't been any updates for a long time.
__________________
KliPPy is offline
clug
Junior Member
Join Date: May 2016
Location: Australia
Old 03-04-2018 , 01:53   Re: Methodmap Circular Dependency
Reply With Quote #3

Thanks for that, I ended up merging them into one methodmap with a boolean to denote which it should represent.
clug is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 03-05-2018 , 05:19   Re: Methodmap Circular Dependency
Reply With Quote #4

You can "forward-declare" the tag using
Code:
enum _Object {};
before the _Array methodmap definition. You'll only be able to use the literal tag though, not any of the methods you declare later for the _Object tag.
__________________
Peace-Maker is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-05-2018 , 15:52   Re: Methodmap Circular Dependency
Reply With Quote #5

Using Dynamic, the best I can achieve is declaring the circular reference members as Dynamic and using view_as<>().

http://console.aus-tg.com/index.php?...tedynamicclass
__________________
Neuro Toxin is offline
clug
Junior Member
Join Date: May 2016
Location: Australia
Old 09-24-2019 , 13:07   Re: Methodmap Circular Dependency
Reply With Quote #6

Quote:
Originally Posted by Peace-Maker View Post
You can "forward-declare" the tag using
Code:
enum _Object {};
before the _Array methodmap definition. You'll only be able to use the literal tag though, not any of the methods you declare later for the _Object tag.
I appear to have arrived at this topic once again (by forgetting I had even asked this question and finding it on Google!). This suggestion has worked for me, except in my _Array methodmap I get a tag mismatch warning when attempting to return from a function which is typehinted to return _Object. I've tried all my usual tricks of putting it into a variable of the same type and typecasting it to no avail.

For example:

PHP Code:
enum _Object { }

methodmap _Array {
    public 
_Object GetObject(int index) {
        
_Object result view_as<_Object>(this.GetHandle(index));
        return 
result;  // <-- warning 213: tag mismatch
    
}

Am I chasing the impossible by trying to get this to compile without errors? I do have workarounds, as both _Array and _Object inherit from _Base, so I can simply make this return _Base and typecast it once outside the methodmap, but this doesn't feel clean compared to the theoretical alternative.

Thanks again.
clug is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-24-2019 , 16:20   Re: Methodmap Circular Dependency
Reply With Quote #7

If it's a tag mismatch it would still compile and work as expected wouldnt it?
__________________
Neuro Toxin is offline
clug
Junior Member
Join Date: May 2016
Location: Australia
Old 09-24-2019 , 20:11   Re: Methodmap Circular Dependency
Reply With Quote #8

Quote:
Originally Posted by Neuro Toxin View Post
If it's a tag mismatch it would still compile and work as expected wouldnt it?
You are correct, I meant to say compile without warnings sorry. For CI purposes I like clean compiles with no warnings or errors.
clug is offline
Reply


Thread Tools
Display Modes

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 05:20.


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