assyrianic / SourceGo

SourceGo is a transpiler that transforms a subset of Golang-like code to equivalent SourcePawn.
https://forums.alliedmods.net/showthread.php?t=328269
MIT License
25 stars 3 forks source link
go golang transpiler

SourceGo

v1.4 beta

Introduction

SourceGo is a transpiler that transforms a subset of Golang code to equivalent SourcePawn. The rationale behind SourceGo is to automate as much of the boilerplate possible when creating SourcePawn plugins.

Purpose

To increase SourcePawn plugin development time by using Golang's streamline engineered syntax.

Features

Array/slice types will be automatically const unless passed by reference like: *[]type. So having parameters such as []int will be generated as const int[] while *[]int will be generated as int[].

Becomes:

#include "file"

switch { case x < 10, x+y < 10.0:

default:

}

```sourcepawn
/// SourcePawn
switch (x)
{
    case 1, 2:
    {
    }
    default:
    {
    }
}

if (x < 10 || x+y < 10.0)
{
}
else
{
}

Expression-less switchs are useful for a more compact if-else-if series.

func OnClientPutInServer(client Entity) {}

Becomes:
```c
public void OnPluginStart() {
    Function CB = OnClientPutInServer;
    for (int i = 1; i <= MaxClients; i++) {
        Call_StartFunction(null, CB);
        Call_PushCell(i);
        Call_Finish();
    }
}

public void OnClientPutInServer(int client) {}

__sp__ only takes a single string of raw SourcePawn code. Optionally, you can also use a named string constant (it will be generated into the resulting code file, so keep that in mind.)

/// using raw string quotes here so that single & double quotes don't have to be escaped.
var kv KeyValues
__sp__(`kv = new KeyValues("key_value", "key", "val");`)

...
__sp__(`delete kv;`)

Planned Features

Goal

Generate SourcePawn source code that is compileable by spcomp without having to modify/assist the generate source code.

Contributing

To submit a patch, file an issue and/or hit up a pull request.

Help

Command line options:

If you need help or have any question, simply file an issue with [HELP] in the title.

Installation

Requirements

Latest Golang version.

Credits

License

This project is licensed under MIT License.