roblox-cr
roblox-cr
roblox-cr is a Crystal-to-Luau compiler for Roblox. It takes a string of Crystal code and converts it into Lua.
It's pretty unfinished, pretty undocumented, and should probably never be used for anything. It's a good project to learn how to make a source-to-source compiler though.
If you would like to contribute to or make something like this but only need the help to, consider contacting us in our Discord server.
Example (from examples/fibonacci)
Source
def fib(n : Int) : Int
n <= 1 ? n : (fib(n - 1) + fib(n - 2))
end
puts fib 10 #=> 55
Output
function Fib(N)
return (N <= 1 and N or Fib(N - 1) + Fib(N - 2))
end
print(Fib(10))
Installation
- Clone the repository
- Run
make install
- Check if everything is working by running
rbxcr -h
Usage
- Make a Roblox Crystal project using
rbxcr --init
- Write some code
- Compile using
rbxcr
if you're inside of your project folder, otherwiserbxcr -D <project_dir>
- Sync to Roblox using Rojo or another syncing plugin.
Gotchas
All identifiers are converted to PascalCase during compilation. This is due to Crystal not allowing the use of PascalCase identifiers for method names and class members. This means you need to be mindful of naming conflicts. Say you have a class, A
, and you create a new instance of that class using A.new
and assign it to a variable called a
. The A
class name will be overwritten by the a
variable.
If you have any better solutions, please make a pull request.
Likely to be added
- Enums
case
-when
blocks*
(splat) operator for converting arrays to tuples
Might be added
- Macros
- Annotations
Will not be added
loop
blocksout
keyword- Uninitialized variables
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- R-unic - creator and maintainer
roblox-cr
- 2
- 1
- 0
- 0
- 3
- over 1 year ago
- May 5, 2023
MIT License
Thu, 07 Nov 2024 20:56:54 GMT