diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Cargo.lock | 71 | ||||
| -rw-r--r-- | Cargo.toml | 10 | ||||
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | src/lib.rs | 70 |
5 files changed, 157 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae5903e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.hgignore +.hg/ +target/ diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..4c3223d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,71 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "bstr" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cc" +version = "1.0.49" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.66" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "memchr" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num-traits" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rlua" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.49 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rlua_ext" +version = "0.1.0" +dependencies = [ + "rlua 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" +"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +"checksum bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8d6c2c5b58ab920a4f5aeaaca34b4488074e8cc7596af94e6f8c6ff247c60245" +"checksum cc 1.0.49 (registry+https://github.com/rust-lang/crates.io-index)" = "e450b8da92aa6f274e7c6437692f9f2ce6d701fb73bacfcf87897b3f89a4c20e" +"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" +"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" +"checksum num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c81ffc11c212fa327657cb19dd85eb7419e163b5b076bede2bdb5c974c07e4" +"checksum rlua 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "25fa5b2c667bae0b6218361e96d365e414fe4a0fa80f476b9631aa2dea2c6881" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..b823b22 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "rlua_ext" +version = "0.1.0" +authors = ["N/A <N/A>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rlua = "0.17"
\ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..2c0de3c --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# rlua_ext + +A few extensions to the [`rlua`](https://crates.io/crates/rlua) crate.
\ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..628dcc0 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,70 @@ +use std::fmt::{Display, Formatter, Result}; + +use rlua::Value; + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum ValueType { + /// The Lua value `nil`. + Nil, + /// The Lua value `true` or `false`. + Boolean, + /// A "light userdata" object, equivalent to a raw pointer. + LightUserData, + /// An integer number. + /// + /// Any Lua number convertible to a `Integer` will be represented as this variant. + Integer, + /// A floating point number. + Number, + /// An interned string, managed by Lua. + /// + /// Unlike Rust strings, Lua strings may not be valid UTF-8. + String, + /// Reference to a Lua table. + Table, + /// Reference to a Lua function (or closure). + Function, + /// Reference to a Lua thread (or coroutine). + Thread, + /// Reference to a userdata object that holds a custom type which implements `UserData`. + /// Special builtin userdata types will be represented as other `Value` variants. + UserData, + /// `Error` is a special builtin userdata type. When received from Lua it is implicitly cloned. + Error, +} + +impl Display for ValueType { + fn fmt(&self, f: &mut Formatter) -> Result { + use ValueType::*; + + match self { + Nil => write!(f, "Nil"), + Boolean => write!(f, "Boolean"), + LightUserData => write!(f, "LightUserData"), + Integer => write!(f, "Integer"), + Number => write!(f, "Number"), + String => write!(f, "String"), + Table => write!(f, "Table"), + Function => write!(f, "Function"), + Thread => write!(f, "Thread"), + UserData => write!(f, "UserData"), + Error => write!(f, "Error"), + } + } +} + +pub fn value_type(value: &Value) -> ValueType { + match value { + Value::Nil => ValueType::Nil, + Value::Boolean(_) => ValueType::Boolean, + Value::LightUserData(_) => ValueType::LightUserData, + Value::Integer(_) => ValueType::Integer, + Value::Number(_) => ValueType::Number, + Value::String(_) => ValueType::String, + Value::Table(_) => ValueType::Table, + Value::Function(_) => ValueType::Function, + Value::Thread(_) => ValueType::Thread, + Value::UserData(_) => ValueType::UserData, + Value::Error(_) => ValueType::Error, + } +} |