Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables macros parsers #4

Open
pawnoholic opened this issue Jun 20, 2018 · 1 comment
Open

Variables macros parsers #4

pawnoholic opened this issue Jun 20, 2018 · 1 comment

Comments

@pawnoholic
Copy link

pawnoholic commented Jun 20, 2018

I like it:

// by Y-Less
#define OO_TYPE(%6,%7)%0[%1]%2. (_:@vb:@va:%6:%7@%0[%1]%2[E_%6_%0:@vw:@vx:@vy:@vz:@vs:$E_%6_%0_]
#define @va:%6:%7@%0[%1][@%2] %7%0[%1])[E_%6_%0_%2]
#define @vb:@va:%6:%7@%0[%1][%2][@%3] %7%0[%1])[%2][E_%6_%0_%3]

// First move the ] out as far as required.
#define @vw:%9$%0]%1[ @vv:@vu:@vt:@vr:@vq$%0%1][
#define @vx:%9$%0]%1; @vv:@vu:@vt:@vr:@vq$%0%1];
#define @vy:%9$%0]%1) @vv:@vu:@vt:@vr:@vq$%0%1])
#define @vz:%9$%0]%1, @vv:@vu:@vt:@vr:@vq$%0%1],
#define @vs:%9$%0]%1: @vv:@vu:@vt:@vr:@vq$%0%1]:
 
// Second, move it in again to constrain the contents.  We don't need to scan
// for `[` again since it was the first one looked for above and so can't
// possibly be within the square brackets.  This is good, because scanning for
// `[` from within `[]` is problematic.
 
#define @vv:%9$%0;%1] %9$%0];%1
#define @vu:%9$%0)%1] %9$%0])%1
#define @vt:%9$%0,%1] %9$%0],%1
#define @vr:%9$%0:%1] %9$%0]:%1
 
#define @vq$

I use this:

#define Player. OO_TYPE(PLAYER,Player)

enum E_PLAYER_Vehicle
{
    Float:E_PLAYER_Vehicle_x,
    Float:E_PLAYER_Vehicle_y,
    Float:E_PLAYER_Vehicle_z,
    Float:E_PLAYER_Vehicle_a
};
new PlayerVehicle[MAX_PLAYERS][E_PLAYER_Vehicle];

Player.Vehicle[playerid].x = 10.0;
Player.Vehicle[playerid].y = 10.0;
Player.Vehicle[playerid].z = 10.0;
Player.Vehicle[playerid].a = 10.0;

Result:

C:\Dev\Pawn\samp-neptune\gamemodes\samp-neptune.pwn:17 (error) undefined symbol "Player@Vehicle"
C:\Dev\Pawn\samp-neptune\gamemodes\samp-neptune.pwn:17 (error) invalid expression, assumed zero
C:\Dev\Pawn\samp-neptune\gamemodes\samp-neptune.pwn:17 (error) invalid expression, assumed zero
C:\Dev\Pawn\samp-neptune\gamemodes\samp-neptune.pwn:17 (fatal) too many error messages on one line

I believe my problem is the lack of code for @vb: and @va: defines

@Misiur
Copy link
Contributor

Misiur commented Jun 20, 2018

If you are going to use exclusively the dot syntax, you can simplify this a bit:

#define OO_TYPE(%6,%7)%0[%1]%2. %7%0[%1]%2[E_%6_%0:@vw:@vx:@vy:@vz:@vs:$E_%6_%0_]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants