Function hlua_badtouch::push_userdata [] [src]

pub fn push_userdata<'lua, L, T, F>(
    data: T,
    lua: L,
    metatable: F
) -> PushGuard<L> where
    F: FnOnce(LuaTable<&mut PushGuard<&mut L>>),
    L: AsMutLua<'lua>,
    T: Send + 'static + Any

Pushes an object as a user data.

In Lua, a user data is anything that is not recognized by Lua. When the script attempts to copy a user data, instead only a reference to the data is copied.

The way a Lua script can use the user data depends on the content of the metatable, which is a Lua table linked to the object.

See this link for more infos.

About the Drop trait

When the Lua context detects that a userdata is no longer needed it calls the function at the __gc index in the userdata's metatable, if any. The hlua library will automatically fill this index with a function that invokes the Drop trait of the userdata.

You can replace the function if you wish so, although you are strongly discouraged to do it. It is no unsafe to leak data in Rust, so there is no safety issue in doing so.

Arguments

  • metatable: Function that fills the metatable of the object.