Skip to content

Commit 5b62b71

Browse files
committed
Added bridging functionallity to PHP.
1 parent 0aa5e2f commit 5b62b71

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

Cargo.toml

Lines changed: 4 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"] # should have "Rules/", but then one can't run build.rs to build the zip file
1212

13-
1413
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1514

1615
[dependencies]
@@ -34,6 +33,7 @@ env_logger = "0.8.4"
3433
cfg-if = "1.0"
3534
zip = { version = "0.6.2", default-features = false, features = ["deflate"] }
3635
getrandom = { version = "0.2.3", features = ["js"] }
36+
ext-php-rs = "0.10.0"
3737

3838
# # dependencies because of need to build wasm version for file i/o
3939
# yew = "0.18.0"
@@ -56,14 +56,15 @@ getrandom = { version = "0.2.3", features = ["js"] }
5656
# ]
5757

5858

59-
6059
[build-dependencies]
6160
bitflags = "1.2.1"
6261
phf = { version = "0.8.0", features = ["macros"] }
6362
zip = { version = "0.6.2", default-features = false, features = ["deflate"] }
63+
cc = "1.0.79"
64+
bindgen = "0.64.0"
6465

6566
[lib]
66-
name = "libmathcat"
67+
name = "mathcat"
6768
crate-type = ["rlib", "cdylib"]
6869

6970
[profile.release]

src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ mod chemistry;
6161
pub mod shim_filesystem; // really just for override_file_for_debugging_rules, but the config seems to throw it off
6262
pub use shim_filesystem::ZIPPED_RULE_FILES;
6363
pub use interface::*;
64+
pub use ext_php_rs::prelude::*;
6465

6566
#[cfg(test)]
6667
pub fn init_logger() {
@@ -115,3 +116,28 @@ pub fn are_strs_canonically_equal(test: &str, target: &str) -> bool {
115116
return are_strs_canonically_equal_with_locale(test, target, ", \u{00A0}\u{202F}", ".");
116117
}
117118

119+
#[php_function]
120+
pub fn mathcat_set_rules_dir(dir: String) {
121+
let _ = set_rules_dir(dir);
122+
}
123+
124+
#[php_function]
125+
pub fn mathcat_set_mathml(mathml_str: String) -> String {
126+
return set_mathml(mathml_str).unwrap();
127+
}
128+
129+
#[php_function]
130+
pub fn mathcat_get_spoken_text() -> String {
131+
return get_spoken_text().unwrap();
132+
}
133+
134+
#[php_function]
135+
pub fn mathcat_set_preference(name: String, value: String) {
136+
let _ = set_preference(name, value);
137+
}
138+
139+
#[php_module]
140+
pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
141+
module
142+
}
143+

0 commit comments

Comments
 (0)