RealEthanPlayzDev / LuauInLuau

DEPRECATED - https://github.com/RealEthanPlayzDev/LuauCeption

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DEPRECATED

https://github.com/RealEthanPlayzDev/LuauCeption

LuauInLuau

Inspired by @Rerumu's LuauInLuau, I've created this repository to translate Luau to Luau.

Features

  • Running Luau code (with or without safe env)
  • Compiling Luau code into bytecode (with support for setting optimization and debug levels)

Fix list

  • Fix issue where if a error occurs during runtime, it crashes the thread calling the function and does not provide any useful information

Getting LuauInLuau

You can get it from releases or compile using the following instruction: (they were tested in Linux, WSL2 to be specific, using bash)

  1. Clone this repository
  2. Initialize all submodules
  3. Install emsdk (cd emsdk && ./emsdk install latest && ./emsdk activate latest && cd ..)
  4. Compile this project into WebAssembly (sh build.sh, make sure cmake, clang/gcc, and llvm is installed)
  5. Use Wasynth to translate the WebAssembly to Luau (wasm2luau LuauInLuau.wasm > LuauInLuau.luau)
  6. Copy over the contents of ExtraCodeSnippet.txt (at the snippets folder) and comment out the old returned function generated by Wasynth, you might need to change some things if theres a breaking change update.
  7. (ONLY NEEDED IF RUNNING VANILLA LUAU) Copy the contents of Vector3Table.txt (at the snippets folder) to the top of the script, no changes should be required, you need this to have the script work at vanilla Luau (like the luau repl for example) as Wasynth uses Roblox's Vector3 datatype (the snippet checks for the existence of the V3 global and if it doesn't exist then it recreates it + overriding type and typeof for getting the V3 datatype). Alternatively compile Wasynth with default-features = false, since it will include the Vector3 table implementation directly without any need of user interference. (Thanks @Rerumu for the Wasynth compile tip)

How it works and a bit of a motivation background

I've started working on this around December 2022, where I found @Rerumu's LuauInLuau gist which caught my interest since I've been looking for a Luau compiler and interpreter written in Luau, the way it works was pretty simple, you compile C++ code into WebAssembly and use @Rerumu's Wasynth to translate WebAssembly to Luau, @Rerumu and a few others in their server had helped me with this process. I was then able to produce a working LuauInLuau for version 0.556.

Now skipping to January 14 2023, I've come back to this little project under one goal, to be able to compile Luau code and have the bytecode string in Luau, I could have just directly used luau_compile but when I first started trying things, I was too stupid to understand how Wasynth even handles loading and storing string and integers.

My solution? Make a C++ program to wrap around those functions! Yes, that is why there is C++ code in this repository, albeit the functions weren't exported independently and I still had to learn how to load and store things myself, thanks to the cleaner generated code however, I was able to understand the basic principle of how it works. In the end I was able to export functions to run and compile Luau code respectively.

Credits

  • Luau - The Roblox Luau repository
  • emsdk - Emscripten SDK for compiling C++ -> WebAssembly
  • Wasynth - WebAssembly -> Luau translation tool
  • The original LuauInLuau - What started this project, and used some code from it.
  • Fiu - Used their Luau bytecode version verification code
  • NougatBitz/Luau - Used code from here (with permission) to patch things further

Acknowledgements

About

DEPRECATED - https://github.com/RealEthanPlayzDev/LuauCeption

License:MIT License


Languages

Language:C++ 63.1%Language:CMake 24.8%Language:Shell 12.1%