📝 doc: make it obvious that LWVM only handles bytecode for now
parent
af49dc68be
commit
d9bba9fc07
|
@ -4,7 +4,7 @@ LunarWaveVM is a Lua 5.4 virtual machine written in Rust.
|
||||||
|
|
||||||
LunarWaveVM relies on the PUC-Rio implementation of `luac` to compile bytecode.
|
LunarWaveVM relies on the PUC-Rio implementation of `luac` to compile bytecode.
|
||||||
|
|
||||||
`cargo run -- --script test_vectors/fizz_buzz.lua`
|
`luac5.4 -o - test_vectors/fizz_buzz.lua | cargo run -- --pipe-bytecode`
|
||||||
|
|
||||||
```
|
```
|
||||||
1
|
1
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -11,24 +11,33 @@ mod tests;
|
||||||
fn main () {
|
fn main () {
|
||||||
use state::State;
|
use state::State;
|
||||||
|
|
||||||
let mut script = String::from ("test_vectors/hello.lua");
|
let mut pipe_bytecode = false;
|
||||||
|
let mut script = None;
|
||||||
|
|
||||||
let mut args = std::env::args ();
|
let mut args = std::env::args ();
|
||||||
let exe_name = args.next ().unwrap ();
|
let exe_name = args.next ().unwrap ();
|
||||||
|
|
||||||
while let Some (arg) = args.next () {
|
while let Some (arg) = args.next () {
|
||||||
match arg.as_str () {
|
match arg.as_str () {
|
||||||
"--script" => script = args.next ().unwrap (),
|
"--pipe-bytecode" => pipe_bytecode = true,
|
||||||
|
"--script" => script = Some (args.next ().unwrap ()),
|
||||||
"--" => break,
|
"--" => break,
|
||||||
_ => panic! ("can't parse args"),
|
_ => panic! ("can't parse args"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let lua_file = {
|
let lua_file = if let Some (script) = script {
|
||||||
let source = std::fs::read (script).expect ("couldn't load Lua source code");
|
let source = std::fs::read (script).expect ("couldn't load Lua source code");
|
||||||
let bytecode = loader::compile_bytecode(source);
|
let bytecode = loader::compile_bytecode(source);
|
||||||
let mut rdr = std::io::Cursor::new (bytecode);
|
let mut rdr = std::io::Cursor::new (bytecode);
|
||||||
loader::parse_chunk (&mut rdr).unwrap ()
|
loader::parse_chunk (&mut rdr).unwrap ()
|
||||||
|
}
|
||||||
|
else if pipe_bytecode {
|
||||||
|
let mut stdin = std::io::stdin ().lock ();
|
||||||
|
loader::parse_chunk (&mut stdin).unwrap ()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
unimplemented!();
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut vm = State::default ();
|
let mut vm = State::default ();
|
||||||
|
|
Loading…
Reference in New Issue