AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Enum Structs Available This Holiday Season (https://forums.alliedmods.net/showthread.php?t=312822)

AdRiAnIlloO 06-25-2020 05:14

Re: Enum Structs Available This Holiday Season
 
Quote:

Originally Posted by Deather (Post 2707143)
There is also a problem with using the same struct type as a method argument type:
Code:

enum
struct STest
{
    int a;

    void Add(STest x)
    {
      a += x.a;
    }
}
STest test;


Right, it seems you can't use same enum struct inside one's definition. Though you also need to always prefix self members with this. (so this.a in your example), otherwise it's an error.

Also, I wanted to suggest. I think enum structs should support constructors, I guess it would be easy since they allow for normal functions already, and it would be the most natural next-step for me. In relation to this, the fact that methodmaps have constructors already wouldn't be a reason for not making same on enum structs - methodmaps can't contain member variables.

Once this is done, enum structs will be much more valuable.

MAGNAT2645 06-27-2020 03:33

Re: Enum Structs Available This Holiday Season
 
Quote:

Originally Posted by AdRiAnIlloO (Post 2707184)
Right, it seems you can't use same enum struct inside one's definition. Though you also need to always prefix members with this. (so a.this in your example), otherwise it's an error.

Also, I wanted to suggest. I think enum structs should support constructors, I guess it would be easy since they allow for normal functions already, and it would be the most natural next-step for me. In relation to this, the fact that methodmaps have constructors already wouldn't be a reason for not making same on enum structs - methodmaps can't contain member variables.

Once this is done, enum structs will be much more valuable.

this.a (which means this STest.a), not a.this

ainn 11-26-2020 20:01

Re: Enum Structs Available This Holiday Season
 
First of all, thanks for the useful feature.

I'm curious, is this a bug or working as intended:

PHP Code:

// This compiles (SourcePawn Compiler 1.10)

enum struct Foo {
    
int a;
    
    
int bar()
    {
        
int b this.a;
        return 
b;
    }
}

public 
void OnPluginStart()
{
    
Foo foo;
    
foo.bar();


But this doesn't work, regardless of the pragma.
PHP Code:

// This doesn't compile:
//     plugin.sp(10) : error 147: new-style declarations are required

#pragma newdecls optional

enum struct Foo {
    
int a;
    
    
int bar()
    {
        new 
this.a// old-style decl
        
return b;
    }
}

public 
void OnPluginStart()
{
    
Foo foo;
    
foo.bar();


While you might wonder why I'd want to do this in the first place, I ran into the issue while using some legacy boilerplate for a newer project. Not a big deal having to rewrite it in newdecls style, but just wondering whether the pragma is actually supposed to allow this.

asherkin 11-27-2020 08:34

Re: Enum Structs Available This Holiday Season
 
Newdecl constructs (like methodmaps and enum structs) enforce newdecls on their interior items.


All times are GMT -4. The time now is 00:52.

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