Raised This Month: $32 Target: $400
 8% 

SMC_SetReaders: within methodmap


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 02-28-2021 , 16:47   SMC_SetReaders: within methodmap
Reply With Quote #1

Hi,

How can I set SMC_SetReaders callback within methodmap?

PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>

methodmap GameDataEx KeyValues
{
    public 
GameDataEx(char[] gameconf)
    {
        
KeyValues kv = new KeyValues("Games");
        
// ...
        
SMCParser parser = new SMCParser();

        
// error 166: cannot use 'this' outside of a methodmap method or property
        // 
        
SMC_SetReaders(parserthis.Config_NewSectionINVALID_FUNCTIONINVALID_FUNCTION);
        
// ...
        
return view_as<GameDataEx>(kv);
    }
    
    
// Alternate:
    
public void Parse()
    {
        
SMCParser parser = new SMCParser();

        
// error 105: cannot find method or property GameDataEx.Config_NewSection
        // 
        
SMC_SetReaders(parserthis.Config_NewSectionINVALID_FUNCTIONINVALID_FUNCTION);
    }
    
    public 
SMCResult Config_NewSection(SMCParser smc, const char[] namebool opt_quotes)
    {
        
// ...
        
return SMCParse_Continue;
    }
}

public 
void OnPluginStart()
{
    
GameDataEx gd;
    
gd = new GameDataEx("cfg.txt");    

Thank you.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 02-28-2021 at 16:49.
Dragokas is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 02-28-2021 , 17:38   Re: SMC_SetReaders: within methodmap
Reply With Quote #2

No, here is conflict.

GameDataEx::Config_NewSection is not static and require "this" argument to be passed.
// SMCResult GameDataEx::Config_NewSection(GameDataEx this, SMCParser smc, const char[] name, bool opt_quotes)
SMC_SetReaders sets requirement for function prototype https://sm.alliedmods.net/new-api/te...SMC_NewSection
SMCResult (SMCParser smc, const char[] name, bool opt_quotes)
__________________
Kailo is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 02-28-2021 , 17:51   Re: SMC_SetReaders: within methodmap
Reply With Quote #3

I see. So, it is impossible to encapsulate it within a methodmap?
I'm not sure if SourcePawn supports the "static" keyword. I tried it and compiler doesn't throw an error.
However it still cannot find the method.
Code:
public static SMCResult Config_NewSection(SMCParser smc, const char[] name, bool opt_quotes)
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 02-28-2021 , 23:32   Re: SMC_SetReaders: within methodmap
Reply With Quote #4

Kailo, ahh, you mean, that each methodmap's method implicitly contains "this" as a first hidden argument, and that's why it doesn't match with the expected prototype.
That's explain everything. Thanks.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-01-2021 , 05:03   Re: SMC_SetReaders: within methodmap
Reply With Quote #5

This is one of the things that SP needs "fat" function references to support, which has been pretty hard to do with all the code assuming functions can be converted to ints - that is finally now a compile error, so this sort of thing should be unblocked.
__________________
asherkin 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 02:53.


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