/* roblox-pyc | python, c, c++ to luau compiler *\

roblox-pyc

Docs | Devforum | Github | Tests/Examples | Discord

What is it?

roblox-pyc is like roblox-ts, a library dedicated to added more language functionality to roblox that includes:

  • Script editor
  • Syntax highlighting
  • Error detection
  • Warning detection
  • Class support
  • Function support
  • All of the built in functions reprogrammed
  • Python list, dict, string reprogrammed in lua.
  • Slice support
  • Case support
  • Supports all VScode sync, including Argon, Rojo.
  • pip library support
  • Full python 3.13 support
  • CLI
  • Async function support
  • bytes, int, floats etc. support
    and way, way more.

Find out the entire list of stuff added in the replies and todo at the end of this post.


Example:

(using 1.0.0, code will have differences from performance improvements and predictive headers if done in current version.)

Python code

"""
Person class:
"""

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]


person = Person()
print('User Bob has been added with id ', person.set_name('Bob'))
print('User associated with id 0 is ', person.get_name(0))

"""
Print numbers 1-10
"""
for i in range(10):
 print(i)

"""
Test the roblox api, change Baseplate color to green after 5 seconds
"""   
task.wait(5)
workspace.Baseplate.Color = Color3.new(0,1,0)

Output

--// Compiled using Roblox-py \\--
		
		
------------------------------------ BUILT IN -------------------------------
local stringmeta, list, dict, staticmethod, class, range, __name__, len, abs, str, int, sum, max, min, reversed, split, round, all, any, ord, char, callable, zip, float, format, hex, id, map = unpack(require(game.ReplicatedStorage["Roblox.py"])(script))
-----------------------------------------------------------------------------
--[[ 
Person class:
 ]]
local Person = class(function(Person)
    Person.name = list {}
    function Person.set_name(self, user_name)
        self.name.append(user_name)
        return (len(self.name) - 1)
    end
    function Person.get_name(self, user_id)
        if (user_id >= len(self.name)) then
            return "There is no such user"
        else
            return self.name[user_id]
        end
    end
    return Person
end, {})
local person = Person()
print("User Bob has been added with id ", person.set_name("Bob"))
print("User associated with id 0 is ", person.get_name(0))
--[[ 
Print numbers 1-10
 ]]
for i in range(10) do
    print(i)
end
--[[ 
Test the roblox api, change Baseplate color to green after 5 seconds
 ]]
task.wait(5)
workspace.Baseplate.Color = Color3.new(0, 1, 0)

Headers are not going to be so long because of predictive headers.


Conclusion

I have been working on this project for a long time, It still isn’t complete but I wanted to just upload it so people can try it out and test it. You can read my goals in the TODO section below and answering my poll will be greatly appreciated.


TODO:

  • pip libraries support
  • game wrapper in python.
  • C support (almost done)

Poll

Do you consider trying this out?
  • Yes
  • No
  • Probably

0 voters

Based on the example code what do you think about this?
  • Looks good
  • Could be better
  • Other - comment
  • Lacks features
  • Bad idea

0 voters

I would greatly appreciate it if you comment in this post with suggestions or criticism

Thanks for your time and goodbye :grin:

30 Likes

I am currently working on a CLI so you can use this alongside Rojo like roblox-ts.

5 Likes

This is really good glad someone made a py to lua compiler

7 Likes

roblox-py 1.1.1

  • Strings python api
  • Dictionary python api
  • List python api
  • CLI (Just for tests at the moment)
  • Tests (use it as an example)
  • Updated API
  • staticmethods
  • id function to get Hexadecimal Memory Address

I will update the devforum and GitHub docs soon.


If you have any ideas or criticism I would greatly appreciate it.

3 Likes

roblox-py 1.2.1

Note: CLI is still not complete and will only work in the tests folder after cloning its repository.

Added support:

  • Bytes supported
  • Lambda supported
  • Try, Except (equivalent to pcall)
  • raise (equivalent to error)
  • Sets supported
  • Format does not fully work but no longer errors, rather than using
f"{a}: A, {b}: B,"

use

format("{a}: A, {b}: B,")
  • “With” supported
  • Slicing supported

Compiler

  • Use [[lua]] alongside a multiline comment to insert lua code into the python script and have the compiler insert it
print("Python Code")
"""[[lua]]
print("Lua Code")
"""
"""
Multiline comment
"""

Functions

  • divmod
  • bool
  • slice

Coroutine related:

  • Async functions

  • Bug fixes
  • Performance improvements
    and way way more.

If you have any ideas or criticisms I would greatly appreciated it :grin:

3 Likes

really interesting but i couldn’t really see this being used for serious development due to its obvious limitations and the differing usecases for python vs luau

5 Likes

As someone who’s learned python and currently adapting to lua, this is really intriguing. I’ll be experimenting with it when I have the time. Good job so far :slight_smile:

3 Likes

Not sure if you are implying to python or the resource, so I will answer both.

  1. I dont think python is more limited, I think the opposite. Python has more widespread usage and functions/utilities.
  2. This resource can support basic-intermediate python, only can’t support modules and filestreams/stuff that the roblox environment doesn’t support

And also the languages dont really have different use cases. They both are embeddable languages into C, both are used to make games and pretty much used for the same thing.

4 Likes

i agree, but luau is very limited and you arent gonna be able to go far trying to convert a language designed for widescale accessibility and use to a language designed to only run within roblox’s controlled and closed off ecosystem.

python generally isn’t used to make games as much as it is used for automation and data analysis. sure, you COULD make a game in python but most if not all modern day games run on C++. I do agree that both lua and python are object oriented languages, and on paper it sounds good, but as someone who mains both python and lua i could not see myself using this for any creation on roblox. although i do agree the concept is certainly unique and i respect that.

6 Likes

True, but the goal of this project is to just bring python with all of its possible features that could be brought into Lua(u). But I understand what you are trying to say and agree.

I see python as an all-in-one language, there is flask which allows for websites, pygame for games, transformers for ai, and more. It is true that some parts are used more than others but python is still capable.


But I understand where you are coming from and agree with some of your points.

3 Likes

In case you haven’t noticed, python is quite unpopular on the forum. Personally I would love to use python to develop roblox games. But I don’t think it’s possible for now.

The problem with this kind of projects, including roblox-ts, is that they make you lose control of the engine, which in turn makes work duplicate.

For example in roblox-ts, in some cases (but not so few), it is not possible to do a direct debugging, you have to read the luau code looking for the error, make the changes in typescript and then test. Remember that the luau code is generated and it is not so easy to match which typescript code generated which luau code.

Another common complaint with roblox-ts is optimization. The generated code is rarely efficient, which forces you to have to write some things in luau anyway.

To work smoothly you must have sufficient knowledge in both languages. Double work.

It would help a lot if roblox would support other languages directly in the engine. This way the debugging would be direct and you would have the possibility to squeeze the engine in your preferred language.

3 Likes

roblox-py 1.2.2

Still the CLI only works with tests.

  • Await
  • Async with
  • Async for
  • Updated async functions
  • in, so you can do
if x in z:
 print(x)
2 Likes

With roblox-py whenever you compile it, it will output errors as if you were running the script, that’s a feature of ast which is made by python. And it’s pretty unlikely for a error to not come out of the output but only occur when you run the script, with all the tests I made I haven’t seen that happen once apart from compiler bugs, even when a feature is unsupported it will still inform you.

At the core it uses a AST (Abstract Syntax Tree), which takes in the Python code turns it into a table and makes it into lua. It will be about as well optimized as you wrote your Python code, for example if the AST reads a while loop, it will add the node and the compiler will simply write the while loop again but in lua.

Yes it may be a bit less optimized but even so your barely giving up any performance because both languages are so similar that pretty much the only things being changed are wording and adding functions.

Not really, you could do this with just knowing one because of what I said above, both languages are way more similar than luau + ts.

2 Likes

roblox-py 1.3.2

  • Huge async functions performance improvement
  • try*
  • Import From
  • Asserting
  • Nonlocal
  • Variables with types
  • Matches (cases)

Matches/Cases example:

x = "10"

match x:
    case "10":
        print("x is 10")
    case "20":
        print("x is 20")
    case _:
        print("x is not 10 or 20")
--// Compiled using Roblox.py \\--
		
		
------------------------------------ BUILT IN -------------------------------
local stringmeta, list, dict, staticmethod, class, range, __name__, len, abs, str, int, sum, max, min, reversed, split, round, all, any, ord, char, callable, zip, float, format, hex, id, map, bool, divmod, slice, operator_in, asynchronousfunction, match = unpack(require(game.ReplicatedStorage["Roblox.py"])(script))
-----------------------------------------------------------------------------
local x = stringmeta "10"
match(x, {
[10] = function()
    print(stringmeta "x is 10")
end,
[20] = function()
    print(stringmeta "x is 20")
end,
["default"] = function()
    print(stringmeta "x is not 10 or 20")
end,
})

Note: This uses the built in library for roblox-py


NOW STATEMENTS ARE UP TO DATE WITH PYTHON 3.13

(note: Python 3.13 is a development build)

  • Still need to add functions
  • Add expressions
  • Add built in variables

roblox-py 1.3.3

44/68 of built in python 3.13 functions have been implemented. The ones that do require environment control not accessible with Roblox’s environment (ex: open, input) will work when used in a normal lua environment but error in Roblox’s.

roblox-py 1.3.4

ALL PYTHON 3.13 (dev) FUNCTIONS ARE NOW SUPPORTED!

Now roblox-py 1.3.4 is equivalent to the latest devbuild of python, the plugin from 1.1.1 is still supported and I will be working on deploying this on pip.

Known issues

  • When indexing local will be applied behind it, like shown below: (Fixed!)

Python 3.13 code:

x = {1,2,3,4,5}
x[1] = 3

Lua(u)

local x = list {1,2,3,4,5}
local x[1] = 3 -- not expected behavior

Nice!

You should add strict-typing, by default I type a lot of my Python functions

2 Likes

Thanks for the recommendation!


So far it just supports variable annotations like shown:

name: str = 'Bob'
age: int = 32
rating: float = 7.9
is_premium: bool = True

type hints like this are in my todo list:

def sum_numbers(a: int, b: int) -> int:
    return a + b

print(sum_numbers(10, 5))
print(sum_numbers(10.3, 5))
print(sum_numbers('Bob', 'Mark'))

and I am also going to write a sort of python class -> lua class converter for stuff like floats which are only in python

roblox-py 1.3.5

  • classmethod
  • Bug fixes
  • py library to fetch services
  • tests redone
  • new cli system using typer (still not done)

A dream came true for once, I will be using this for now on scripting my games. This is so awesome. Where is the roblox plugin link?

2 Likes