extern crate byteorder;
extern crate libc;
pub mod bytecode;
mod write;
mod read;
pub use write::write_file;
pub use read::read_file;
pub const SIGNATURE: &'static [u8] = b"\x1bLua";
pub const VERSION: u8 = 0x53;
pub const FORMAT: u8 = 0;
pub const DATA: &'static [u8] = b"\x19\x93\r\n\x1a\n";
pub const TEST_INT: Integer = 0x5678;
pub const TEST_NUMBER: Number = 370.5;
pub type Int = libc::c_int;
pub type Size = libc::size_t;
pub type Instruction = u32;
pub type Integer = i64;
pub type Number = f64;
#[derive(Clone, Debug, PartialEq)]
pub enum Constant {
Nil,
Boolean(bool),
Float(Number),
Int(Integer),
ShortString(String),
LongString(String),
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Upvalue {
Outer(u8),
Stack(u8),
}
#[derive(Clone, Debug, PartialEq)]
pub struct LocalVar {
pub name: String,
pub start_pc: Int,
pub end_pc: Int,
}
#[derive(Clone, Debug, PartialEq)]
pub struct Debug {
pub lineinfo: Vec<Int>,
pub localvars: Vec<LocalVar>,
pub upvalues: Vec<String>,
}
impl Debug {
pub fn none() -> Debug {
Debug {
lineinfo: vec![],
localvars: vec![],
upvalues: vec![],
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Function {
pub source: String,
pub line_start: Int,
pub line_end: Int,
pub num_params: u8,
pub is_vararg: bool,
pub max_stack_size: u8,
pub code: Vec<Instruction>,
pub constants: Vec<Constant>,
pub upvalues: Vec<Upvalue>,
pub protos: Vec<Function>,
pub debug: Debug,
}