| roblox-pyc | A Python, C, C++, Moonscript, Text/Json port to Roblox, because we need a better language

roblox-pyc

docs | github | discord | donate

Features

  • C and C++ compiler
    Using clang and libclang roblox-pyc can compile C and C++ into Luau

  • Python compiler
    Python, one of the most used languages has full 3.13 → Luau support.

  • All VScode sync plugins supported
    Because of roblox-pyc’s flexibility you can use Rojo or Argon or anything else, it is your choice.

  • Infers project structure (new)
    roblox-pyc can compile in different modes and infer your projects structure to make your programming experience easier.

  • Wally support (new)
    If you use wally, roblox-pyc can install from wally out of the box because it uses the Wally registry API and downloads it in a way that can be installed from the python import function.

  • Textfiles and JSON support (new)
    roblox-pyc can compile textfiles and JSON files in Lua(u) and with the python built in open function you can open them.

  • roblox-ts support (coming soon)
    roblox-pyc allows you to use roblox-ts alongside it also if you want to use multiple languages.

  • Package manager (new)
    roblox-pyc comes with a built-in package manager which allows you to use pip(3), luarocks, and wally packages alongside the packages made specifically for roblox-pyc.

  • Lua support (docs)
    If you are still learning Lua, you can embed lua into python or use Lua alongside the included languages.

  • Studio Plugin (not uploaded yet, get from gh releases)
    If you do not use a Code Editor, for python only there is a Studio Plugin with the compiler there also.

  • All Code editors supported
    Since roblox-pyc isn’t a plugin but rather a CLI, so you can use any code-editor even Notepad!

  • Moonscript
    Moonscript is a language that compiles to Lua, we offer a slightly modified version of Moonscript with an extended standard library called Lunar

Note: This is a full release post, not a Creations Feedback like my other one


Why should I use Python rather than Luau

Python, one of the most popular languages is way more documented meaning that you can find way more resources or libraries and help for it, Not only that but Python is way simpler here are is an example,

Examples:

if "a" not in myTable:
 print("Not found!")

vs

if not table.find(mytable, "a") then
 print("Not found")
end

After using this python feature, I got so used to it I was wondering why does Lua not have something so simple.


class Person:
    name = []

    def set_name(self, user_name):
        self.name.append(user_name)
        return len(self.name) - 1

    def get_name(self, user_id):
        if user_id >= len(self.name):
            return 'There is no such user'
        else:
            return self.name[user_id]

MyPerson = Person()

vs
(there are a lot of ways to do this in lua)

local Person = {}
Person.__index = Person

function Person.new()
  local New = Person
  New.name = []
  return New
end

function Person:set_name(user_name)
  table.insert(self, user_name)
  return #self.name-1
end

function Person:get_name(user_id)
  if user_id >= #(self.name) then
    return "There is no such user"
  else
     return self.name[user_id]
end

local MyPerson = Person.new()

Huge difference, you could save a lot of time with Pythons easier syntax and even more with its ~100 built in functions and even more libraries!


Frequently Asked Questions.

But, why not just use roblox-ts?!

It is all about preference, I find python easier for more general stuff and TypeScript for front end. Some perks of python are

  • More readable
  • Way larger standard library (which has been rewritten in Luau)
  • Popularity

But roblox-ts has stuff like better syntax, TSX, and more. So I am working on adding roblox-ts support where you can use one language for some scripts and another for more, But roblox-pyc does support Lunar/Moonscript and if you are looking for syntax sugar that’s a great alternative

Would it be highly unoptimized?

Actually it’s pretty much the opposite, the code runs performantly and some parts may even run faster. If you care about optimization so much you can still embed Lua into python like shown:

print("This is python code!")

"""[[lua]]
local X = true -- this is lua code
for i, v in range(10) do -- I can still access python built in functions
  print(v)
end
"""

How to install

  • Open your terminal
  • Enter the following, make sure you have pip installed
pip install roblox-pyc
  • Test by writing the following in the terminal: rpyc info
  • Congrats! You just installed roblox-pyc.

Using rojo CLI

This is using the CLI not plugin, I will write a plugin later soon

  • Verify you have both Rojo and roblox-pyc installed

  • Use rojo init in your target directory to make an example game

  • Use cd src to go inside of the newly created source folder

  • Clone the directory with roblox-pyc using
    rbxpy cd for python,
    rbxc cd for C,
    rbxcpp cd for C++,
    and rbxlun cd for Lunar/Moonscript.

  • You should now have a folder like this

Screenshot 2023-07-23 at 7.56.56 PM

  • In the terminal use cd ../src to go to the src folder even if it seems like you are already there because sometimes the terminal doesn’t detect changes after using rbx<?> cd.

  • Modify the default.project.json to use the path src-compiled rather than src

default.project.json should be:
{
  "name": "<REPLACE WITH GAMENAME>",
  "tree": {
    "$className": "DataModel",

    "ReplicatedStorage": {
      "Shared": {
        "$path": "src-compiled/shared"
      }
    },

    "ServerScriptService": {
      "Server": {
        "$path": "src-compiled/server"
      }
    },

    "StarterPlayer": {
      "StarterPlayerScripts": {
        "Client": {
          "$path": "src-compiled/client"
        }
      }
    },

    "Workspace": {
      "$properties": {
        "FilteringEnabled": true
      },
      "Baseplate": {
        "$className": "Part",
        "$properties": {
          "Anchored": true,
          "Color": [
            0.38823,
            0.37254,
            0.38823
          ],
          "Locked": true,
          "Position": [
            0,
            -10,
            0
          ],
          "Size": [
            512,
            20,
            512
          ]
        }
      }
    },
    "Lighting": {
      "$properties": {
        "Ambient": [
          0,
          0,
          0
        ],
        "Brightness": 2,
        "GlobalShadows": true,
        "Outlines": false,
        "Technology": "Voxel"
      }
    },
    "SoundService": {
      "$properties": {
        "RespectFilteringEnabled": true
      }
    }
  }
}
  • Write rpyc d for cross language compilation, it will compile the code from python to lua and clicking enter in the terminal again will recompile

  • Once you want to build using Rojo, Click ctrl+c in the terminal

  • Go to the compiled folder with cd ../src-compiled

  • write rojo build -o build.rbxlx and you should get a roblox place file

This may seem long, but if you learn Rojo and get used to using roblox-pyc you will get the hand of it.

Installing dependencies

  • Inside of the src path, open the terminal
  • First find out which package you want to download from the roblox-pyc registry it will be formatted like so:
    signal
    and for Wally
    @roblox/roact
    for rbxts/npm
    @rbxts/promise
  • Install! Here are some example install commands:
rpyc install spring // From our registry
rpyc install signal // From our registry
rpyc install @sleitnick/knit // From wally
rpyc install @rbxts/roact // From NPM rbxts

Downloading the plugin

If you cannot use VScode or find the roblox script editor easier, it’s fine!

There is a plugin file download available in the discord server,


Using the plugin

You first want to open your terminal make sure you have roblox-pyc installed and run rpyc p.

Then you want to open roblox studio (after installing the plugin) and click the roblox.py plugin button, you should get a new code editor window and a script inside of your selected object in the explorer.

From the code editor you can write python code, click the green button and it will compile!


Known issues

  • Dependencies do not fully work
  • Syntax Slicing do not work, use slice()
  • default.project.json will require manual changes
  • Format using f"" doesn’t work
  • rpyc d can give issues
    if you need help or find any other issues report them on discord.

How to support this project

I work on this project on my own so I would greatly appreciate if you make any contribution or donate in GitHub Sponsors.


Should I continue working on this?
  • Yes
  • No

0 voters

Thanks for reading! :grin:

54 Likes

Lua’s implementation is already simple


I’m likely not going to use this as-is because I don’t use python for anything, but if you manage to add C/C++ support, I may start glancing at this

9 Likes

Agreed but python does have more features and perks either ways. If you are looking for a better language python in my opinion is the go to.


I am definitely going to be adding C and C++ support, I already have an AST for it and a light compiler ready.

3 Likes

I hate Lua but I am forced to use it. I enjoy making games in general so I don’t mind being forced to use Lua. I just wish Swift was an option in Roblox. Would it be possible to add Swift support to this?

1 Like

Really nice idea! I will look into that, do you also want SwiftUI and SwiftData implemented?

Edit: https://swift-ast-explorer.com, if I do plan on adding this I will use this

3 Likes

This would be really nice, I love SwiftUI and would love to make my Roblox UI with SwiftUI to make it more consistent with my other products (outside of Roblox)

However, would it still be possible to import Roblox Packages with the import command?

import CollectionService

let taggedItems = CollectionService:GetTagged("Apple is the best")

taggedItems.forEach { row in
    row.forEach { element in
        // Do something them them.
    }
}
1 Like

I might plan on adding this in the future after I get C and C++ done.

Maybe not like this but more like

let CollectionService = game.CollectionService

because just like with the python compiler, game will be a built in library.


Import will be reserved for requiring.

1 Like

if you could please think about C# as well, as i believe they should transpile quite nicely if done correctly

4 Likes

also might add this, thanks for the recommendation!

1 Like

When I add all these new languages (including C and C++) I might have to switch the system from a Py->PyAst->Luau to a Py->PyAst->LuauAst->Luau and build the luau code using roblox-ts’s luau-ast.

1 Like

Woah! This seems cool! I wonder how long it took you to make this :exploding_head:

I don’t think I’d even know how to start making this! Props to you!

2 Likes

Do you plan on adding Java Script?

2 Likes

No, roblox-ts exists and that has typescript which is a superset of Javascript so you can kind of use Javascript code with that.

not only that but I believe roblox-js exists

3 Likes

Release notes

GitHub

Release v2.25.111 · AsynchronousAI/roblox-pyc

Log

  • Test mode
  • Use environment variable export ENABLE_BETA_RPYC=True to enable C and C++
  • A lot of bug fixes
  • Thanks tututuana on GitHub for unnecessary double checking file type fix #1
  • Redid the code to be more modular
  • Standalone executables (recommended by lawmixer in the discord server
  • Added LuauAST by roblox-ts for future roblox-pyc versions #2
  • Cleaned up code
  • Finished plugin, download link in discord server
  • Fixed addition issue where you cannot concat in python (safeadd)
  • Added footer
  • Fixed issue in Lunar where it will automatically return <> the last line
  • Thanks BazirGames on GitHub for reporting a lot of bugs in the discord server
  • Safe-autoupdate using rpyc info to update so config files are not lost

The below release notes are autogenerated by GitHub

Pull requests

Full Changelog: Comparing v1.16.15…v2.25.111 · AsynchronousAI/roblox-pyc · GitHub


The executables for the CLI are being built right now and will be posted on Github releases and discord when compiled.

2 Likes
what got me

the “pyc” in the title part got me, I am currently trying to understand russian and greek, and the first russian word I know is Русский (pronounced as Russkiy) and my laptop language in russian says “РУС”, though it’s probably for “Python C”

though I do like this concept (there is already something like this for typescript called roblox-ts aka rbxts, if anyone wants javascript, then go to rbxts, typescript is like javascrpt), I am also willing to code in python and C/C++

also I do want Java and C# to be added

2 Likes

Yeah that is way better for front ends also, I am thinking of having a way of integrating that.

C# is definitely something I want to add, I might also do Java.

2 Likes

If you can truly bring clang to roblox… no way.

2 Likes

I assume with libraries you mean some of the built-in libraries?
I’d be interested in knowing which libraries are supported, as many of them use c/c++ under the hood.

Wow, this is awesome! I love using another transpiler you mentioned (roblox-ts), so I’m definitely excited to try this at some point in the future!
Also, the discord link is busted, please fix it.