Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bridging functionallity to PHP. #247

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ documentation = "https://nsoiffer.github.io/MathCAT/"
edition = "2018"
exclude = ["src/main.rs"] # should have "Rules/", but then one can't run build.rs to build the zip file


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

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

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



[build-dependencies]
bitflags = "1.2.1"
phf = { version = "0.8.0", features = ["macros"] }
zip = { version = "0.6.2", default-features = false, features = ["deflate"] }
cc = "1.0.79"
bindgen = "0.64.0"

[lib]
name = "libmathcat"
name = "mathcat"
crate-type = ["rlib", "cdylib"]

[profile.release]
Expand Down
26 changes: 26 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ mod chemistry;
pub mod shim_filesystem; // really just for override_file_for_debugging_rules, but the config seems to throw it off
pub use shim_filesystem::ZIPPED_RULE_FILES;
pub use interface::*;
pub use ext_php_rs::prelude::*;

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

#[php_function]
pub fn mathcat_set_rules_dir(dir: String) {
let _ = set_rules_dir(dir);
}

#[php_function]
pub fn mathcat_set_mathml(mathml_str: String) -> String {
return set_mathml(mathml_str).unwrap();
}

#[php_function]
pub fn mathcat_get_spoken_text() -> String {
return get_spoken_text().unwrap();
}

#[php_function]
pub fn mathcat_set_preference(name: String, value: String) {
let _ = set_preference(name, value);
}

#[php_module]
pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
module
}