Template based pre-compile
#1

I stumbled upon this discussion in Southclaw's Scavenge Survive's repository and I believe this could take PAWN scripting to the next level.

It would allow us to write nicer and readable code and achieve things that are very hard or impossible now. I believe the .amx file size will notably increase, but it's worth it for me.

What do you guys think?

Examples
Some random examples so you get the grasp of the idea.

Input
Code:
hook event() { }
hook event() { }
Output:
Code:
public event() {
    event_01();
    event_02();
}
forward event_01(); public event_01() { }
forward event_02(); public event_02() { }
Input:
Code:
new Float:pos[3];
GetPlayerPos(target, pos);
SetPlayerPos(playerid, pos);
Output:
Code:
new Float:pos[3];
GetPlayerPos(target, pos[0], pos[1], pos[2]);
SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
Input:
Code:
new CharacterData[MAX_PLAYERS][inline enum {
    name[MAX_PLAYER_NAME],
    age(default:18)}];
Output
Code:
enum E_CharacterData {
    CharacterData_name[MAX_PLAYER_NAME],
    CharacterData_age
}
new CharacterData[MAX_PLAYERS][E_CharacterData];

// gamemode init, i'm 100% sure this is not the correct way to do this. just some pseudo code
for(new i; i!=sizeof(CharacterData); i++) CharacterData[i][CharacterData_Age] = 18;
Reply
#2

Idea of pre-preprocessor was discussed a few times. Slice started working on Prawn, but currently it is abandoned I think - https://github.com/oscar-broman/Prawn . As for your examples, you'd have parse to AST as well, so you might get some good ideas from there
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)