1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Foreign function interface for C part of implementation
//! (including C bindings for Lua)

pub use auto::*;
pub use ext::*;

/// Automatically generated FFI
mod auto {
    #![allow(warnings)]
    include!(concat!(env!("OUT_DIR"), "/ffi_cmach.rs"));
}

/// Manual extensions to FFI
mod ext {
    #![allow(dead_code)]
    #![allow(missing_docs)]

    use super::auto;
    use std::os::raw::*;

    pub unsafe fn lua_pop(l: *mut auto::lua_State, n: c_int) {
        auto::lua_settop(l, -n - 1);
    }

    pub unsafe fn lua_tointeger(l: *mut auto::lua_State, index: c_int) -> auto::lua_Integer {
        auto::lua_tointegerx(l, index, 0 as *mut _)
    }

    pub unsafe fn lua_tonumber(l: *mut auto::lua_State, index: c_int) -> auto::lua_Number {
        auto::lua_tonumberx(l, index, 0 as *mut _)
    }

    pub unsafe fn lua_pcall(
        l: *mut auto::lua_State,
        nargs: c_int,
        nresults: c_int,
        msgh: c_int,
    ) -> c_int {
        auto::lua_pcallk(l, nargs, nresults, msgh, 0, None)
    }

    pub unsafe fn lua_pushcfunction(l: *mut auto::lua_State, func: auto::lua_CFunction) {
        auto::lua_pushcclosure(l, func, 0);
    }
}