Merge pull request #7 from jonas-schievink/popen

Enable `io.popen` on Linux
This commit is contained in:
kyren 2017-06-17 16:31:09 -04:00 committed by GitHub
commit 75b7024a93
2 changed files with 51 additions and 2 deletions

View file

@ -1,8 +1,17 @@
extern crate gcc;
use std::env;
fn main() {
gcc::Config::new()
.define("LUA_USE_APICHECK", None)
let mut config = gcc::Config::new();
if env::var("CARGO_CFG_TARGET_OS") == Ok("linux".to_string()) {
// Among other things, this enables `io.popen` support.
// Despite the name, we could enable this on more platforms.
config.define("LUA_USE_LINUX", None);
}
config.define("LUA_USE_APICHECK", None)
.include("lua")
.file("lua/lapi.c")
.file("lua/lauxlib.c")

40
examples/repl.rs Normal file
View file

@ -0,0 +1,40 @@
//! This example shows a simple read-evaluate-print-loop (REPL).
extern crate rlua;
use rlua::*;
use std::io::prelude::*;
use std::io::{stdin, stdout, stderr, BufReader};
fn main() {
let lua = Lua::new();
let mut stdout = stdout();
let mut stdin = BufReader::new(stdin());
loop {
write!(stdout, "> ").unwrap();
stdout.flush().unwrap();
let mut line = String::new();
loop {
stdin.read_line(&mut line).unwrap();
match lua.eval::<LuaMultiValue>(&line) {
Ok(values) => {
println!("{}", values.iter().map(|value| format!("{:?}", value)).collect::<Vec<_>>().join("\t"));
break;
}
Err(LuaError(LuaErrorKind::IncompleteStatement(_), _)) => {
// continue reading input and append it to `line`
write!(stdout, ">> ").unwrap();
stdout.flush().unwrap();
}
Err(e) => {
writeln!(stderr(), "error: {}", e).unwrap();
break;
}
}
}
}
}