pub struct CFunction(/* private fields */);Expand description
A wrapper around ffi::lua_CFunction to push C functions
into lua as values.
§Example
use tlua::{Lua, CFunction, LuaState, ffi};
let lua = Lua::new();
unsafe extern "C-unwind" fn return_42(lua: LuaState) -> libc::c_int {
ffi::lua_pushinteger(lua, 42);
1
}
assert_eq!(
lua.eval_with::<_, i32>("local fn = ...; return fn()", &CFunction::new(return_42))
.unwrap(),
42
);Implementations§
Source§impl CFunction
impl CFunction
pub fn new(f: lua_CFunction) -> Self
pub fn into_inner(self) -> lua_CFunction
Trait Implementations§
Source§impl From<unsafe extern "C-unwind" fn(*mut lua_State) -> i32> for CFunction
impl From<unsafe extern "C-unwind" fn(*mut lua_State) -> i32> for CFunction
Source§fn from(f: lua_CFunction) -> Self
fn from(f: lua_CFunction) -> Self
Converts to this type from the input type.
Source§impl<L: AsLua> Push<L> for CFunction
impl<L: AsLua> Push<L> for CFunction
Source§impl<L: AsLua> PushInto<L> for CFunction
impl<L: AsLua> PushInto<L> for CFunction
impl Copy for CFunction
Auto Trait Implementations§
impl Freeze for CFunction
impl RefUnwindSafe for CFunction
impl Send for CFunction
impl Sync for CFunction
impl Unpin for CFunction
impl UnwindSafe for CFunction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more