atl::value
atl::Value: a handle to a Lua value, and the conversions between Rust and Lua types.
pub struct ValueA handle to any Lua value: tables, functions, game objects, strings... The handle is freed when the Value is dropped; clones get their own handle.
Methods
pub const fn nil() -> ValueNil.
pub fn adopt(h: Handle) -> ValueTakes ownership of a raw handle.
pub fn borrow(h: Handle) -> ValueWraps a raw handle without taking ownership; it isn't freed.
pub fn release(mut self) -> HandleGives up ownership and returns a raw handle the caller must free.
pub fn global(path: &str) -> ValueLooks up a dotted global path, e.g. Value::global("sm.vec3.new").
pub fn table() -> ValueA new empty table.
pub fn from<T: IntoLua + ?Sized>(v: &T) -> ValueConverts a Rust value to Lua.
pub fn handle(&self) -> HandleThe raw handle.
pub fn is_nil(&self) -> boolTrue for nil.
pub fn kind(&self) -> TypeThe Lua type.
pub fn is(&self, t: Type) -> boolTrue when the type is t.
pub fn truthy(&self) -> boolLua truthiness: false only for nil and false.
pub fn to_number(&self) -> f64The value as a number (0 if it isn't one).
pub fn to_lua_string(&self) -> StringLua's tostring() of the value.
pub fn to_bytes(&self) -> Vec<u8>The bytes of a Lua string (or of tostring() for anything else).
pub fn to<T: FromLua>(&self) -> TConverts the value to T.
pub fn field<K: Key>(&self, key: K) -> Valuet[key], where the key is a field name, a 1-based index or a Value.
pub fn get<T: FromLua, K: Key>(&self, key: K) -> Tt[key] converted to T.
pub fn number(&self, field: &str) -> f64t[field] as a number, without creating a handle.
pub fn set<K: Key, T: IntoLua + ?Sized>(&self, key: K, v: &T) -> &Selft[key] = v. Returns self for chaining.
pub fn length(&self) -> i32The length operator #t.
pub fn append<T: IntoLua + ?Sized>(&self, v: &T) -> &SelfAppends v at t[#t + 1].
pub fn pairs(&self) -> Pairs<'_>Iterates the table's key/value pairs with Lua's next().
pub fn call<R: FromLua>(&self, args: impl Args) -> RCalls the value as a function and returns its first result as R. A Lua error traps the mod.
pub fn method<R: FromLua>(&self, name: &str, args: impl Args) -> RCalls value:name(args...) and returns its first result as R. A Lua error traps the mod.
pub fn try_call(&self, args: impl Args) -> Option<Vec<Value>>Calls the value as a function and returns every result, or None if it raised
an error, so the mod can handle the failure itself.
pub fn try_method(&self, name: &str, args: impl Args) -> Option<Vec<Value>>Calls value:name(args...) and returns every result, or None on a Lua error.
pub fn method_all(&self, name: &str, args: impl Args) -> Vec<Value>Calls value:name(args...) and returns every result.
pub fn call_all(&self, args: impl Args) -> Vec<Value>Calls the value as a function and returns every result.
Implements Clone, Codec, Debug, Default, Display, Drop, FromLua, IntoLua, Key, PartialEq
pub struct Pairs<'a>Iterator over a table with Lua's next(); used by Value::pairs().
Implements Iterator
pub struct NilConverts to Lua nil; pass Nil as an argument.
Implements Clone, Copy, Debug, Default, Eq, IntoLua, PartialEq
Global
Section titled "Global"pub struct Global<T>(UnsafeCell<T>)A static holding mutable state. WASM mods are single-threaded, so this is a plain cell.
Methods
pub const fn new(v: T) -> SelfImplements Sync
GlobalCell
Section titled "GlobalCell"pub struct GlobalCellA Lua global looked up once and cached (global!).
Methods
pub const fn new() -> Selfpub fn get(&'static self, path: &str) -> &'static ValueThe global, looked up on first use.
Implements Default, Sync
pub enum TypeThe Lua type of a Value. Game objects (Shape, Vec3, ...) are Userdata.
Variants
Nil = 0Boolean = 1Number = 2String = 3Table = 4Function = 5Userdata = 6Thread = 7
Implements Clone, Copy, Debug, Eq, PartialEq
pub enum Arg<'a>One argument of a pending call, converted without creating a handle where possible (numbers, booleans and strings go straight to the host).
Variants
NilNumber(f64)Bool(bool)Str(&'a [u8])Handle(Handle): A handle owned by someone else.Owned(Value): A handle created for this call, freed with the Arg.
Methods
pub fn push(&self)Appends this argument to the host's argument buffer.
pub fn into_value(self) -> ValueTurns the argument into a standalone Lua value.
pub trait KeyA table key: a string field or a 1-based integer index.
IntoLua
Section titled "IntoLua"pub trait IntoLuaConverts a Rust value to a Lua argument. Implement it to pass your own types to Lua.
Trait items
fn to_arg(&self) -> Arg<'_>The value as an argument; borrowed strings and handles stay borrowed.
FromLua
Section titled "FromLua"pub trait FromLua: SizedConverts a Lua value to a Rust value. Implement it to read your own types from Lua.
Trait items
fn from_lua(v: &Value) -> SelfReads the value.
pub trait ArgsThe arguments of a call: a tuple of IntoLua values, () for none.
Trait items
type Prepared<'a>: AsRef<[Arg<'a>]> where Self: 'aThe prepared arguments.
fn prepare(&self) -> Self::Prepared<'_>Converts every argument before the call starts (a conversion may itself call Lua).
Object
Section titled "Object"pub trait Object: SizedBase trait for game object wrappers (Shape, Body, Player, ...). Holds the Lua object and calls its methods.
Trait items
const LUA_TYPE: &'static strThe Lua type name type() reports for this object ("Shape", ...).
fn value(&self) -> &ValueThe wrapped Lua value.
fn from_value(v: Value) -> SelfWraps a Lua value.
fn is_nil(&self) -> boolTrue for nil.
fn exists(&self) -> boolTrue when the object still exists in the game (sm.exists).
fn method<R: FromLua>(&self, name: &str, args: impl Args) -> RCalls the Lua method name on the object.
Functions
Section titled "Functions"pub fn lua_error(context: &str) -> !Traps the mod with context and the host's last error message.
pub fn invoke<A: Args + ?Sized>(f: Handle, args: &A) -> i32Calls f(args...) on the host; returns the result count, or -1 on a Lua error.
pub fn invoke_method<A: Args + ?Sized>(obj: Handle, name: &str, args: &A) -> i32Calls obj:name(args...) on the host; returns the result count, or -1 on a Lua error.