Example Rust program running in LuaLaTeX via WebAssembly
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

initial commit

arthomnix 7c0ff0bb

+52
+9
.cargo/config.toml
··· 1 + [build] 2 + target = "wasm32-unknown-unknown" 3 + rustflags = [ 4 + "-C", "target-feature=-bulk-memory,-bulk-memory-opt,-call-indirect-overlong,-multivalue,-reference-types,-nontrapping-fptoint" 5 + ] 6 + 7 + [unstable] 8 + build-std = ["core", "alloc", "std", "panic_abort"] 9 +
+1
.gitignore
··· 1 + /target
+7
Cargo.lock
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "tex_hello" 7 + version = "0.1.0"
+9
Cargo.toml
··· 1 + [package] 2 + name = "tex_hello" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [lib] 7 + crate-type = ["cdylib"] 8 + 9 + [dependencies]
+1
README.md
··· 1 + An example of a Rust program running inside LuaLaTeX with [wasmtex](https://tangled.org/did:plc:m3l4kxtgyiposiijmnkbholi/wasmtex) and [lwasmlib](https://tangled.org/did:plc:m3l4kxtgyiposiijmnkbholi/lwasmlib).
+17
src/lib.rs
··· 1 + #[link(wasm_import_module = "tex")] 2 + unsafe extern "C" { 3 + fn tex_putchar(c: i32); 4 + fn tex_flush(); 5 + } 6 + 7 + #[unsafe(no_mangle)] 8 + pub extern "C" fn tex_hello(a: i32, b: i32) { 9 + tex_sprint(&format!("Hello \\LaTeX{{}} from Rust! ${a} + {b} = {}$", a+b)); 10 + } 11 + 12 + fn tex_sprint(s: &str) { 13 + for c in s.chars() { 14 + unsafe { tex_putchar(c as i32) }; 15 + } 16 + unsafe { tex_flush() }; 17 + }
+8
test.tex
··· 1 + \documentclass{article} 2 + \usepackage{wasmtex} 3 + 4 + \begin{document} 5 + %\WASMTracingOn 6 + \WASMInstantiateFile{target/wasm32-unknown-unknown/release/tex_hello.wasm}{vm} 7 + \WASMCallExportedFunction{vm}{tex_hello}{42, 25} 8 + \end{document}