Skip to content

Commit 43f1cf0

Browse files
committed
:qAdded bridging functionallity to PHP.
1 parent bf2db5e commit 43f1cf0

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ documentation = "https://nsoiffer.github.io/MathCAT/"
1010
edition = "2018"
1111
exclude = ["src/main.rs", "docs", "PythonScripts"] # should have "Rules/", but then one can't run build.rs to build the zip file
1212

13-
1413
[features]
1514
"include-zip" = []
1615
"enable-logs" = ["android_logger"]
@@ -38,6 +37,7 @@ log = "0.4"
3837
env_logger = "0.11.8"
3938
cfg-if = "1.0.1"
4039
fastrand = { version = "2.3.0" }
40+
ext-php-rs = "0.10.0"
4141

4242
[target.'cfg(target_family = "wasm")'.dependencies]
4343
zip = { version = "4.3", default-features = false, features = ["deflate"] }
@@ -47,17 +47,17 @@ zip = { version = "4.3", default-features = false, features = ["bzip2"] }
4747
android_logger = {version = "0.15.1", optional = true}
4848

4949

50-
5150
[build-dependencies]
5251
bitflags = "2.6"
5352
error-chain = "0.12.4"
5453
[target.'cfg(target_family = "wasm")'.build-dependencies]
5554
zip = { version = "4.3", default-features = false, features = ["deflate"] }
5655
[target.'cfg(not(target_family = "wasm"))'.build-dependencies]
5756
zip = { version = "4.3", default-features = false, features = ["bzip2"] }
57+
bindgen = "0.64.0"
5858

5959
[lib]
60-
name = "libmathcat"
60+
name = "mathcat"
6161
crate-type = ["rlib", "cdylib"]
6262

6363
[profile.test]

src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ mod chemistry;
6363

6464
pub mod shim_filesystem; // really just for override_file_for_debugging_rules, but the config seems to throw it off
6565
pub use interface::*;
66+
pub use ext_php_rs::prelude::*;
6667

6768
#[cfg(test)]
6869
pub fn init_logger() {
@@ -124,3 +125,28 @@ pub fn are_strs_canonically_equal(test: &str, target: &str) -> bool {
124125
return are_strs_canonically_equal_with_locale(test, target, ", \u{00A0}\u{202F}", ".");
125126
}
126127

128+
#[php_function]
129+
pub fn mathcat_set_rules_dir(dir: String) {
130+
let _ = set_rules_dir(dir);
131+
}
132+
133+
#[php_function]
134+
pub fn mathcat_set_mathml(mathml_str: String) -> String {
135+
return set_mathml(mathml_str).unwrap();
136+
}
137+
138+
#[php_function]
139+
pub fn mathcat_get_spoken_text() -> String {
140+
return get_spoken_text().unwrap();
141+
}
142+
143+
#[php_function]
144+
pub fn mathcat_set_preference(name: String, value: String) {
145+
let _ = set_preference(name, value);
146+
}
147+
148+
#[php_module]
149+
pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
150+
module
151+
}
152+

0 commit comments

Comments
 (0)