Enum Structs Available This Holiday Season
Hi Folks,
As of PR #934, SourceMod 1.10 has support for enum structs. This is some long-overdue syntactic sugar that makes SourcePawn feel more like a real language. Enum Structs are internally implemented as arrays, but the syntax is a lot nicer than before and we've fixed a lot of the corner cases and rough edges around using them. You can also have enum struct methods now. You can read more about enum structs either in the Transitional Syntax Docs, or in the commit message. If you're too impatient to read that, I'll just copy and paste the sample code from the doc: PHP Code:
|
Re: Enum Structs Available This Holiday Season
Like a breath of fresh air. Well done!
|
Re: Enum Structs Available This Holiday Season
I really appreciate this!
but looks like latest mac compiler can't compile this expression...? |
Re: Enum Structs Available This Holiday Season
If I ever get around to working on it again, this will greatly simplify some the code to a plugin I was working on to replace the aging UMC plugin.
|
Re: Enum Structs Available This Holiday Season
All this sugar is pretty epic. Already added support to BasicPawn.
Lets hope we dont get diabetes :lol: |
Re: Enum Structs Available This Holiday Season
Looks great but why 'enum' is needed its seems like c struct
|
Re: Enum Structs Available This Holiday Season
Because it's still just syntactic sugar over arrays, just like old enum structs, but with nicer syntax.
|
Re: Enum Structs Available This Holiday Season
Quote:
Edit: Also text document because I'm too lazy to use a UML diagram maker to do it. |
Re: Enum Structs Available This Holiday Season
Is there a way we can push enum structs with array fields in them into an ArrayList? For example,
PHP Code:
Code:
Start |
Re: Enum Structs Available This Holiday Season
Seems like a bug to me. You should open an issue on the github page: https://github.com/alliedmodders/sourcepawn/issues
|
Re: Enum Structs Available This Holiday Season
|
Re: Enum Structs Available This Holiday Season
Quote:
Quote:
|
Re: Enum Structs Available This Holiday Season
You never gave blocksize to the ArrayList constructor.
|
Re: Enum Structs Available This Holiday Season
Quote:
It helps if you know arrays are a reference type. When I say that, I mean when you do this: PHP Code:
|
Re: Enum Structs Available This Holiday Season
Quote:
|
Re: Enum Structs Available This Holiday Season
BAILOPAN, great update, so handy, btw can we wait some update in methodmaps part ? We need some improvements there, something look like a clases with proper constructor and destructor or may be a posibility to create values inside a methodmap class, like in a new struct and use them only there
|
Re: Enum Structs Available This Holiday Season
methodmaps != classes
While 'enum structs' can hold multiple values because they are arrays, methodmaps can only hold one. If you want to store something *in* methodmaps use StringMap's (or any other list). StringMap's are more readable. Example: PHP Code:
PHP Code:
|
Re: Enum Structs Available This Holiday Season
New-style enum structs having a "methodmap" built-in is meant to solve the problem of methodmaps not having storage - what is lacking?
|
Re: Enum Structs Available This Holiday Season
Quote:
|
Re: Enum Structs Available This Holiday Season
I can't help but notice when I try to include an enum struct in a native definition that the compiler tells me that I can't do this:
Code:
error 135: cannot use enum struct type "MapChoices_GetMapData" in natives Also, the error is reporting the native name rather than the enum struct name. |
Re: Enum Structs Available This Holiday Season
Quote:
https://github.com/alliedmodders/sourcepawn/issues/295 |
Re: Enum Structs Available This Holiday Season
PHP Code:
I don't know how sizeof of structs works, but if i have 3 members, calling g_Players = new ArrayList(3) it's wrong (only the first paramater - "steam" works fine), so g_Players = new ArrayList(sizeof(PlayerInfo)) it's the correct one. |
Re: Enum Structs Available This Holiday Season
Quote:
|
Re: Enum Structs Available This Holiday Season
I've made a very slight change to the enum struct syntax. The final closing brace (}) must now be followed by a newline. Semicolons are not allowed even with #pragma semicolon, to be consistent with most other close-brace scenarios.
|
Re: Enum Structs Available This Holiday Season
Quote:
|
Re: Enum Structs Available This Holiday Season
Done, thanks!
|
Re: Enum Structs Available This Holiday Season
Hello,
Why this one is invalid ? error 008: must be a constant expression; assumed zero PHP Code:
used version 6421 |
Re: Enum Structs Available This Holiday Season
Quote:
|
Re: Enum Structs Available This Holiday Season
Quote:
|
Re: Enum Structs Available This Holiday Season
Quote:
|
Re: Enum Structs Available This Holiday Season
Can we get the following methods and properties:?
Those would be useful for serialization/deserialization. |
Re: Enum Structs Available This Holiday Season
Code:
enum _:Roles |
Re: Enum Structs Available This Holiday Season
Quote:
PHP Code:
|
Re: Enum Structs Available This Holiday Season
Is anyone able to help with the above, like many others I'm running a fork of ckSurf which if using the latest SM compiler, will not compile due to the use of enums.
I'm not the most knowledgeable when it comes to the transitional syntax and I've been having trouble getting things to compile and function when making my own efforts to convert my fork of the timer. Notepad++ isn't the most forthcoming either! Sample of Code Code:
enum MapZone Code:
int g_mapZones[MAXZONES][MapZone]; // Map Zone array Many thanks in advance for anyones input on the above. |
Re: Enum Structs Available This Holiday Season
Quote:
Code:
enum struct MapZone |
Re: Enum Structs Available This Holiday Season
Quote:
Thank you so much. :) |
Re: Enum Structs Available This Holiday Season
Quote:
enum view_as<int>(Roles) just doesn't seem right to me. |
Re: Enum Structs Available This Holiday Season
Is it possible to return enum struct in function? Code below doesn't work.
Code:
enum struct STest |
Re: Enum Structs Available This Holiday Season
The compiler doesn't appear to currently understand it as a type when parsing the function declaration, interestingly using it as any[] appears to work correctly but I have no idea if that is intended.
As with other array-like things in SourcePawn, it's almost certainly better to pass it as a param to be filled in by the callee. PHP Code:
|
Re: Enum Structs Available This Holiday Season
Code:
enum struct STest There is also a problem with using the same struct type as a method argument type: Code:
enum |
All times are GMT -4. The time now is 12:19. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.