Raised This Month: $ Target: $400
 0% 

SourceGo: Golang to SourcePawn Transpiler (v1.4 beta)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
nergal
Veteran Member
Join Date: Apr 2012
Old 11-02-2020 , 17:18   SourceGo: Golang to SourcePawn Transpiler (v1.4 beta)
Reply With Quote #1

I'm happy to announce that, with the help of many SM devs, I've created an experimental Golang to SourcePawn source to source compiler aka a transpiler.

What does it do? It takes (a subset of) Golang code and converts it to an equivalent SourcePawn version, here's a quick example:

Code:
/// SourceGo
package main

const (
	a, b = "A", MAXPLAYERS
	c = a
	d string = "D"
	e = "e1"
	f = 1.00
)

var (
	myself = Plugin{
		name: "SrcGo Plugin",
		author: "Nergal",
		description: "Plugin made into SP from SrcGo.",
		version: "1.0a",
		url: "https://github.com/assyrianic/Go2SourcePawn",
	}
	
	str_array = [...]string{
		"kek",
		"foo",
		"bar",
		"bazz",
	}
)

type (
	Point struct{ x, y float }
	QAngle Vec3
	Name [64]char
	Color = [4]int
	
	PlayerInfo struct {
		Origin Vec3
		Angle QAngle
		Weaps [3]Entity
	}
	
	Kektus    func(i, x Vec3, b string, blocks *Name, KC *int)   Handle
	EventFunc func(event Event, name string, dontBroadcast bool) Action
)


func OnlyScoutsLeft(team int) bool {
	for i:=0; i<=MaxClients; i++ {
		if !IsValidClient(i) || !IsPlayerAlive(i) {
			continue;
		} else if GetClientTeam(i) == team && TF2_GetPlayerClass(i) != TFClass_Scout {
			return false
		}
	}
	return true
}


func IsClientInGame(client Entity) bool

func main() {
	for i := 1; i<=MaxClients; i++ {
		if IsClientInGame(i) {
			OnClientPutInServer(i)
		}
	}
}

func OnClientPutInServer(client Entity) {
	/// do something with client.
}
Code:
/// Generated SourcePawn:
#include <sourcemod>

char a[] = "A";
int b = MAXPLAYERS;
char c[] = a;
char d[] = "D";
char e[] = "e1";
float f = 1.00;

public Plugin myself = {
	name = "SrcGo Plugin",
	author = "Nergal",
	description = "Plugin made into SP from SrcGo.",
	version = "1.0a",
	url = "https://github.com/assyrianic/Go2SourcePawn"
};
char str_array[4][] = {
	"kek",
	"foo",
	"bar",
	"bazz"
};

enum struct Point {
	float x;
	float y;
}
enum struct PlayerInfo {
	float Origin[3];
	float Angle[3];
	int Weaps[3];
}
typedef Kektus = function Handle (const float i[3], const float x[3], const char[] b, char blocks[64], int& KC);
typedef EventFunc = function Action (Event event, const char[] name, bool dontBroadcast);


public bool OnlyScoutsLeft(int team) {
	for (int i = 0; i <= MaxClients; i++) {
		if (!IsValidClient(i) || !IsPlayerAlive(i)) {
			continue;
		}
		else if (GetClientTeam(i) == team && TF2_GetPlayerClass(i) != TFClass_Scout) {
			return false;
		}

	}
	return true;
}

native bool IsClientInGame(int client);
public void OnPluginStart() {
	for (int i = 1; i <= MaxClients; i++) {
		if (IsClientInGame(i)) {
			OnClientPutInServer(i);
		}

	}

}

public void OnClientPutInServer(int client) {
}

The transpiler itself is written in Golang and can easily be cross-compiled for Windows 32-bit, 64-bit and Linux/Mac 32-bit, 64-bit from the Go compiler directly.

The project is MIT licensed and is currently in open Alpha phase.

The purpose of this project is to help automate and abstract over many SourcePawn constructs in order to significantly improve plugin development time. Part of this is stronger typing & type abstraction and a simpler, more expressive syntax.

Project Repo.

An important thing to remember is that, with SourceGo, you're not making SourceMod plugins with Golang, you're using Golang's syntax that is then transformed into its SourcePawn equivalent code.
__________________

Last edited by nergal; 02-11-2021 at 17:42. Reason: update
nergal is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:01.


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