Skip to content

RBX-CPP allows you to program C++ in roblox with the help of emscripten and wasm2luau (from Wasynth).

License

Notifications You must be signed in to change notification settings

Malte0621/RBX-CPP

Repository files navigation

RBX-CPP

RBX-CPP allows you to program C++ in roblox with the help of emscripten and wasm2luau (from Wasynth).

How to use

Prerequisites

Compiling

  1. Clone the repository
  2. Run python3 build.py in the root directory
  3. Copy the contents of dist/*.lua to your roblox project

Running

  1. Make a new ModuleScript in roblox
  2. Copy the contents of dist/*.lua to the ModuleScript
  3. Require the ModuleScript in a Script and call its exported function(s)

Exporting

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.)

Example

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"));
	}
}

Documentation

RBX::Instance

Constructors

Instance(std::string className, Instance* parent = nullptr);
Instance(std::string className, std::string parent = "game");

Methods

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);

RBX::Instance::GetInstance

Instance* GetInstance(std::string path);

RBX::print

void print(std::string message);

RBX::warn

void warn(std::string message);

RBX::error

void error(std::string message);

About

RBX-CPP allows you to program C++ in roblox with the help of emscripten and wasm2luau (from Wasynth).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published