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 pythonimport
function. -
Textfiles and JSON support (new)
roblox-pyc can compile textfiles and JSON files in Lua(u) and with the python built inopen
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++,
andrbxlun cd
for Lunar/Moonscript. -
You should now have a folder like this
-
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 usingrbx<?> cd
. -
Modify the
default.project.json
to use the pathsrc-compiled
rather thansrc
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.
- Yes
- No
0 voters
Thanks for reading!