RBX-CPP allows you to program C++ in roblox with the help of emscripten and wasm2luau (from Wasynth).
- Clone the repository
- Run
python3 build.py
in the root directory - Copy the contents of
dist/*.lua
to your roblox project
- Make a new ModuleScript in roblox
- Copy the contents of
dist/*.lua
to the ModuleScript - Require the ModuleScript in a Script and call its exported function(s)
To export a function, edit the CMakeLists.txt file inside src
and add the function name to the EXPORTED_FUNCTIONS
variable. Then, recompile the project. The builder will automatically add the functions to the returned table in dist/main.lua
!
Remember to use module.convertString("<string here>")
when passing strings to the exported functions! (Numbers should work as-is.)
local module = require(script:WaitForChild("ModuleScript"))
module.main()
#include "RBX.h"
extern "C" {
int main() {
RBX::Instance* instance = new RBX::Instance("Part", RBX::Instance::GetInstance("game.Workspace"));
instance->SetProperty("Name", "CppPart");
instance->SetProperty("Parent", RBX::Instance::GetInstance("game.Workspace"));
// instance->SetPropertyRaw("Name", "\"CppPart\"");
RBX::Instance* cloned = instance->Clone();
cloned->SetPropertyRaw("Parent", "game.Workspace");
RBX::print(std::string("PARTS CREATED? Name: ") + instance->GetPropertyRaw("Name"));
}
}
Instance(std::string className, Instance* parent = nullptr);
Instance(std::string className, std::string parent = "game");
Instance* Clone();
void Destroy();
std::string GetPropertyRaw(std::string propertyName);
void SetPropertyRaw(std::string propertyName, std::string value);
std::string GetProperty(std::string propertyName);
void SetProperty(std::string propertyName, std::string value);
Instance* GetInstance(std::string path);
void print(std::string message);
void warn(std::string message);
void error(std::string message);