Merge pull request #7 from jonas-schievink/popen
Enable `io.popen` on Linux
This commit is contained in:
commit
75b7024a93
13
build.rs
13
build.rs
|
@ -1,8 +1,17 @@
|
||||||
extern crate gcc;
|
extern crate gcc;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
gcc::Config::new()
|
let mut config = gcc::Config::new();
|
||||||
.define("LUA_USE_APICHECK", None)
|
|
||||||
|
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")
|
.include("lua")
|
||||||
.file("lua/lapi.c")
|
.file("lua/lapi.c")
|
||||||
.file("lua/lauxlib.c")
|
.file("lua/lauxlib.c")
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue