Add Rojo C API experiment

This commit is contained in:
Lucien Greathouse
2019-11-07 18:20:55 -08:00
parent f1daafbf9e
commit dfb015acc2
6 changed files with 43 additions and 0 deletions

3
.gitignore vendored
View File

@@ -1,6 +1,9 @@
# Rust output directory
/target
# Headers for clibrojo
/include
# Roblox model and place files in the root, used for debugging
/*.rbxm
/*.rbxmx

7
Cargo.lock generated
View File

@@ -181,6 +181,13 @@ dependencies = [
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "clibrojo"
version = "0.1.0"
dependencies = [
"rojo 0.6.0-dev",
]
[[package]]
name = "clicolors-control"
version = "1.0.1"

View File

@@ -26,12 +26,14 @@ user-plugins = []
members = [
"rojo-test",
"rojo-insta-ext",
"clibrojo",
]
default-members = [
".",
"rojo-test",
"rojo-insta-ext",
"clibrojo",
]
[lib]

13
clibrojo/Cargo.toml Normal file
View File

@@ -0,0 +1,13 @@
[package]
name = "clibrojo"
version = "0.1.0"
authors = ["Lucien Greathouse <me@lpghatguy.com>"]
edition = "2018"
[lib]
crate-type = ["cdylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rojo = { path = ".." }

4
clibrojo/README.md Normal file
View File

@@ -0,0 +1,4 @@
# Rojo as a C Library
This is an experiment to expose a C API for Rojo that would be suitable for embedding it into an existing C/C++ application.
I'm hoping to expand it to drop the HTTP layer and communicate through a channel, which could make it feasible to embed into an existing Roblox IDE with minimal changes or additional code.

14
clibrojo/src/lib.rs Normal file
View File

@@ -0,0 +1,14 @@
use std::{ffi::CStr, os::raw::c_char, path::PathBuf};
use librojo::commands::{serve, ServeOptions};
#[no_mangle]
pub extern "C" fn rojo_serve(path: *const c_char) {
let path = unsafe { PathBuf::from(CStr::from_ptr(path).to_str().unwrap()) };
serve(&ServeOptions {
fuzzy_project_path: path,
port: None,
})
.unwrap();
}