diff options
| author | coco875 <59367621+coco875@users.noreply.github.com> | 2024-10-05 23:49:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-05 15:49:07 -0600 |
| commit | 9cf1f9e1d7a8c365c6cb98fab54cfd40a47573e8 (patch) | |
| tree | faeccca320bb6e857921a2c13f78245d34968f98 /mods/python-rust/src | |
| parent | e5f4fddddace5043e45f678bb6de124922e00672 (diff) | |
[Modding] start add wasm integration (#84)
* start add wasm integration
* some test
* some improvement
* try more language
* expend try with python
* update
* half working python
* improve and extend test
* get py2wasm work but not so well
* convert to use in cpp
* start prepare multimodule
* improve a little by using cpp (but still not great)
* Update wasm.cpp
* try ocaml
* add a working example of python with a not complete function
* remove type to be even more curse
* start add a proper mod loader
* allow mod to communicate between
* example of hook
---------
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
Diffstat (limited to 'mods/python-rust/src')
| -rw-r--r-- | mods/python-rust/src/lib.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/mods/python-rust/src/lib.rs b/mods/python-rust/src/lib.rs new file mode 100644 index 000000000..c056c172f --- /dev/null +++ b/mods/python-rust/src/lib.rs @@ -0,0 +1,29 @@ +use std::env; + +use rustpython::vm; + +fn main() { + let mut setting: vm::Settings = Default::default(); + setting.path_list.push("".to_string()); + let inter = vm::Interpreter::without_stdlib(setting); + let ret: vm::PyResult<()> = inter.enter(|vm| { + let scope = vm.new_scope_with_builtins(); + let source = r#"print("Hello World from python!")"#; + let code_obj = vm + .compile(source, vm::compiler::Mode::Exec, "<embedded>".to_owned()) + .map_err(|err| vm.new_syntax_error(&err, Some(source)))?; + + vm.unwrap_pyresult(vm.run_code_obj(code_obj, scope)); + + Ok(()) + }); +} + +#[no_mangle] +pub fn fib(n: u32) -> u32 { + if n <= 1 { + main(); + return n; + } + return fib(n - 1) + fib(n - 2); +} |
