Restructure and compartmentalize the project

This commit is contained in:
Rerumu
2022-06-23 20:14:04 -04:00
parent 59a5a3219f
commit 223895e617
34 changed files with 105 additions and 93 deletions
+34
View File
@@ -0,0 +1,34 @@
use std::io::{Result, Write};
use parity_wasm::{deserialize_file, elements::Module};
fn load_module(name: &str) -> Module {
deserialize_file(name)
.expect("Failed to parse WebAssembly file")
.parse_names()
.unwrap_or_else(|v| v.1)
}
fn do_runtime(lock: &mut dyn Write) -> Result<()> {
let runtime = codegen_luajit::RUNTIME;
writeln!(lock, "local rt = (function()")?;
writeln!(lock, "{runtime}")?;
writeln!(lock, "end)()")
}
fn main() -> Result<()> {
let wasm = match std::env::args().nth(1) {
Some(name) => load_module(&name),
None => {
eprintln!("usage: wasm2luajit <file>");
return Ok(());
}
};
let lock = &mut std::io::stdout().lock();
do_runtime(lock)?;
codegen_luajit::from_module_untyped(&wasm, lock)
}