cargo fmt
This commit is contained in:
parent
affa85feb0
commit
b23ee6a162
|
@ -66,7 +66,8 @@ fn call_add_function(c: &mut Criterion) {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
lua.create_registry_value(f).unwrap()
|
||||
};
|
||||
(lua, f)
|
||||
|
@ -104,7 +105,8 @@ fn call_add_callback(c: &mut Criterion) {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
lua.create_registry_value(f).unwrap()
|
||||
};
|
||||
(lua, f)
|
||||
|
@ -129,7 +131,8 @@ fn call_append_callback(c: &mut Criterion) {
|
|||
let c: LuaFunction = lua
|
||||
.create_function(|_, (a, b): (LuaString, LuaString)| {
|
||||
Ok(format!("{}{}", a.to_str()?, b.to_str()?))
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
lua.globals().set("callback", c).unwrap();
|
||||
let f: LuaFunction = lua
|
||||
.eval(
|
||||
|
@ -141,7 +144,8 @@ fn call_append_callback(c: &mut Criterion) {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
lua.create_registry_value(f).unwrap()
|
||||
};
|
||||
(lua, f)
|
||||
|
|
25
build.rs
25
build.rs
|
@ -1,5 +1,5 @@
|
|||
use std::io;
|
||||
use std::env;
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
|
@ -10,12 +10,16 @@ trait CommandExt {
|
|||
impl CommandExt for Command {
|
||||
/// Execute the command and return an error if it exited with a failure status.
|
||||
fn execute(&mut self) -> io::Result<()> {
|
||||
self.status()
|
||||
.map(|_| ())
|
||||
.map_err(|_| {
|
||||
io::Error::new(io::ErrorKind::Other, format!("The command\n\
|
||||
\t{:?}\n\
|
||||
did not run successfully.", self))
|
||||
self.status().map(|_| ()).map_err(|_| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!(
|
||||
"The command\n\
|
||||
\t{:?}\n\
|
||||
did not run successfully.",
|
||||
self
|
||||
),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -42,9 +46,12 @@ fn main() {
|
|||
// Compile and run glue.c
|
||||
let glue = build_dir.join("glue");
|
||||
|
||||
config.get_compiler().to_command()
|
||||
config
|
||||
.get_compiler()
|
||||
.to_command()
|
||||
.arg("src/ffi/glue/glue.c")
|
||||
.arg("-o").arg(&glue)
|
||||
.arg("-o")
|
||||
.arg(&glue)
|
||||
.execute()
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -22,10 +22,10 @@
|
|||
|
||||
//! Contains definitions from `lauxlib.h`.
|
||||
|
||||
use libc::{c_int, c_long, c_char, c_void, size_t};
|
||||
use libc::{c_char, c_int, c_long, c_void, size_t};
|
||||
use std::ptr;
|
||||
|
||||
use super::lua::{self, lua_State, lua_CFunction, lua_Integer, lua_Number};
|
||||
use super::lua::{self, lua_CFunction, lua_Integer, lua_Number, lua_State};
|
||||
use super::luaconf::LUAL_BUFFERSIZE;
|
||||
|
||||
pub use super::glue::LUAL_NUMSIZES;
|
||||
|
@ -36,115 +36,145 @@ pub const LUA_ERRFILE: c_int = lua::LUA_ERRERR + 1;
|
|||
|
||||
#[repr(C)]
|
||||
pub struct luaL_Reg {
|
||||
pub name: *const c_char,
|
||||
pub func: lua_CFunction,
|
||||
pub name: *const c_char,
|
||||
pub func: lua_CFunction,
|
||||
}
|
||||
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn luaL_checkversion(L: *mut lua_State) {
|
||||
luaL_checkversion_(L, lua::LUA_VERSION_NUM as lua_Number, LUAL_NUMSIZES as size_t)
|
||||
luaL_checkversion_(
|
||||
L,
|
||||
lua::LUA_VERSION_NUM as lua_Number,
|
||||
LUAL_NUMSIZES as size_t,
|
||||
)
|
||||
}
|
||||
|
||||
extern {
|
||||
pub fn luaL_checkversion_(L: *mut lua_State, ver: lua_Number, sz: size_t);
|
||||
extern "C" {
|
||||
pub fn luaL_checkversion_(L: *mut lua_State, ver: lua_Number, sz: size_t);
|
||||
|
||||
pub fn luaL_getmetafield(L: *mut lua_State, obj: c_int, e: *const c_char) -> c_int;
|
||||
pub fn luaL_callmeta(L: *mut lua_State, obj: c_int, e: *const c_char) -> c_int;
|
||||
pub fn luaL_tolstring(L: *mut lua_State, idx: c_int, len: *mut size_t) -> *const c_char;
|
||||
pub fn luaL_argerror(L: *mut lua_State, arg: c_int, l: *const c_char) -> c_int;
|
||||
pub fn luaL_checklstring(L: *mut lua_State, arg: c_int, l: *mut size_t) -> *const c_char;
|
||||
pub fn luaL_optlstring(L: *mut lua_State, arg: c_int, def: *const c_char, l: *mut size_t) -> *const c_char;
|
||||
pub fn luaL_checknumber(L: *mut lua_State, arg: c_int) -> lua_Number;
|
||||
pub fn luaL_optnumber(L: *mut lua_State, arg: c_int, def: lua_Number) -> lua_Number;
|
||||
pub fn luaL_checkinteger(L: *mut lua_State, arg: c_int) -> lua_Integer;
|
||||
pub fn luaL_optinteger(L: *mut lua_State, arg: c_int, def: lua_Integer) -> lua_Integer;
|
||||
pub fn luaL_getmetafield(L: *mut lua_State, obj: c_int, e: *const c_char) -> c_int;
|
||||
pub fn luaL_callmeta(L: *mut lua_State, obj: c_int, e: *const c_char) -> c_int;
|
||||
pub fn luaL_tolstring(L: *mut lua_State, idx: c_int, len: *mut size_t) -> *const c_char;
|
||||
pub fn luaL_argerror(L: *mut lua_State, arg: c_int, l: *const c_char) -> c_int;
|
||||
pub fn luaL_checklstring(L: *mut lua_State, arg: c_int, l: *mut size_t) -> *const c_char;
|
||||
pub fn luaL_optlstring(
|
||||
L: *mut lua_State,
|
||||
arg: c_int,
|
||||
def: *const c_char,
|
||||
l: *mut size_t,
|
||||
) -> *const c_char;
|
||||
pub fn luaL_checknumber(L: *mut lua_State, arg: c_int) -> lua_Number;
|
||||
pub fn luaL_optnumber(L: *mut lua_State, arg: c_int, def: lua_Number) -> lua_Number;
|
||||
pub fn luaL_checkinteger(L: *mut lua_State, arg: c_int) -> lua_Integer;
|
||||
pub fn luaL_optinteger(L: *mut lua_State, arg: c_int, def: lua_Integer) -> lua_Integer;
|
||||
|
||||
pub fn luaL_checkstack(L: *mut lua_State, sz: c_int, msg: *const c_char);
|
||||
pub fn luaL_checktype(L: *mut lua_State, arg: c_int, t: c_int);
|
||||
pub fn luaL_checkany(L: *mut lua_State, arg: c_int);
|
||||
pub fn luaL_checkstack(L: *mut lua_State, sz: c_int, msg: *const c_char);
|
||||
pub fn luaL_checktype(L: *mut lua_State, arg: c_int, t: c_int);
|
||||
pub fn luaL_checkany(L: *mut lua_State, arg: c_int);
|
||||
|
||||
pub fn luaL_newmetatable(L: *mut lua_State, tname: *const c_char) -> c_int;
|
||||
pub fn luaL_setmetatable(L: *mut lua_State, tname: *const c_char);
|
||||
pub fn luaL_testudata(L: *mut lua_State, ud: c_int, tname: *const c_char) -> *mut c_void;
|
||||
pub fn luaL_checkudata(L: *mut lua_State, ud: c_int, tname: *const c_char) -> *mut c_void;
|
||||
pub fn luaL_newmetatable(L: *mut lua_State, tname: *const c_char) -> c_int;
|
||||
pub fn luaL_setmetatable(L: *mut lua_State, tname: *const c_char);
|
||||
pub fn luaL_testudata(L: *mut lua_State, ud: c_int, tname: *const c_char) -> *mut c_void;
|
||||
pub fn luaL_checkudata(L: *mut lua_State, ud: c_int, tname: *const c_char) -> *mut c_void;
|
||||
|
||||
pub fn luaL_where(L: *mut lua_State, lvl: c_int);
|
||||
pub fn luaL_error(L: *mut lua_State, fmt: *const c_char, ...) -> c_int;
|
||||
pub fn luaL_where(L: *mut lua_State, lvl: c_int);
|
||||
pub fn luaL_error(L: *mut lua_State, fmt: *const c_char, ...) -> c_int;
|
||||
|
||||
// TODO: test this
|
||||
pub fn luaL_checkoption(L: *mut lua_State, arg: c_int, def: *const c_char, lst: *const *const c_char) -> c_int;
|
||||
// TODO: test this
|
||||
pub fn luaL_checkoption(
|
||||
L: *mut lua_State,
|
||||
arg: c_int,
|
||||
def: *const c_char,
|
||||
lst: *const *const c_char,
|
||||
) -> c_int;
|
||||
|
||||
pub fn luaL_fileresult(L: *mut lua_State, stat: c_int, fname: *const c_char) -> c_int;
|
||||
pub fn luaL_execresult(L: *mut lua_State, stat: c_int) -> c_int;
|
||||
pub fn luaL_fileresult(L: *mut lua_State, stat: c_int, fname: *const c_char) -> c_int;
|
||||
pub fn luaL_execresult(L: *mut lua_State, stat: c_int) -> c_int;
|
||||
}
|
||||
|
||||
// pre-defined references
|
||||
pub const LUA_NOREF: c_int = -2;
|
||||
pub const LUA_REFNIL: c_int = -1;
|
||||
|
||||
extern {
|
||||
pub fn luaL_ref(L: *mut lua_State, t: c_int) -> c_int;
|
||||
pub fn luaL_unref(L: *mut lua_State, t: c_int, r: c_int);
|
||||
extern "C" {
|
||||
pub fn luaL_ref(L: *mut lua_State, t: c_int) -> c_int;
|
||||
pub fn luaL_unref(L: *mut lua_State, t: c_int, r: c_int);
|
||||
|
||||
pub fn luaL_loadfilex(L: *mut lua_State, filename: *const c_char, mode: *const c_char) -> c_int;
|
||||
pub fn luaL_loadfilex(L: *mut lua_State, filename: *const c_char, mode: *const c_char)
|
||||
-> c_int;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn luaL_loadfile(L: *mut lua_State, f: *const c_char) -> c_int {
|
||||
luaL_loadfilex(L, f, ptr::null())
|
||||
luaL_loadfilex(L, f, ptr::null())
|
||||
}
|
||||
|
||||
extern {
|
||||
pub fn luaL_loadbufferx(L: *mut lua_State, buff: *const c_char, sz: size_t, name: *const c_char, mode: *const c_char) -> c_int;
|
||||
pub fn luaL_loadstring(L: *mut lua_State, s: *const c_char) -> c_int;
|
||||
extern "C" {
|
||||
pub fn luaL_loadbufferx(
|
||||
L: *mut lua_State,
|
||||
buff: *const c_char,
|
||||
sz: size_t,
|
||||
name: *const c_char,
|
||||
mode: *const c_char,
|
||||
) -> c_int;
|
||||
pub fn luaL_loadstring(L: *mut lua_State, s: *const c_char) -> c_int;
|
||||
|
||||
pub fn luaL_newstate() -> *mut lua_State;
|
||||
pub fn luaL_newstate() -> *mut lua_State;
|
||||
|
||||
pub fn luaL_len(L: *mut lua_State, idx: c_int) -> lua_Integer;
|
||||
pub fn luaL_len(L: *mut lua_State, idx: c_int) -> lua_Integer;
|
||||
|
||||
pub fn luaL_gsub(L: *mut lua_State, s: *const c_char, p: *const c_char, r: *const c_char) -> *const c_char;
|
||||
pub fn luaL_gsub(
|
||||
L: *mut lua_State,
|
||||
s: *const c_char,
|
||||
p: *const c_char,
|
||||
r: *const c_char,
|
||||
) -> *const c_char;
|
||||
|
||||
pub fn luaL_setfuncs(L: *mut lua_State, l: *const luaL_Reg, nup: c_int);
|
||||
pub fn luaL_setfuncs(L: *mut lua_State, l: *const luaL_Reg, nup: c_int);
|
||||
|
||||
pub fn luaL_getsubtable(L: *mut lua_State, idx: c_int, fname: *const c_char) -> c_int;
|
||||
pub fn luaL_getsubtable(L: *mut lua_State, idx: c_int, fname: *const c_char) -> c_int;
|
||||
|
||||
pub fn luaL_traceback(L: *mut lua_State, L1: *mut lua_State, msg: *const c_char, level: c_int);
|
||||
pub fn luaL_traceback(L: *mut lua_State, L1: *mut lua_State, msg: *const c_char, level: c_int);
|
||||
|
||||
pub fn luaL_requiref(L: *mut lua_State, modname: *const c_char, openf: lua_CFunction, glb: c_int);
|
||||
pub fn luaL_requiref(
|
||||
L: *mut lua_State,
|
||||
modname: *const c_char,
|
||||
openf: lua_CFunction,
|
||||
glb: c_int,
|
||||
);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(unused_variables)]
|
||||
pub unsafe fn luaL_newlibtable(L: *mut lua_State, l: *const luaL_Reg) {
|
||||
// TODO: figure out how to pass an appropriate hint for the second param
|
||||
// this involves correcting the second parameter's type; in C this is
|
||||
// sizeof(l)/sizeof(l[0])
|
||||
lua::lua_createtable(L, 0, 0)
|
||||
// TODO: figure out how to pass an appropriate hint for the second param
|
||||
// this involves correcting the second parameter's type; in C this is
|
||||
// sizeof(l)/sizeof(l[0])
|
||||
lua::lua_createtable(L, 0, 0)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn luaL_newlib(L: *mut lua_State, l: *const luaL_Reg) {
|
||||
luaL_checkversion(L);
|
||||
luaL_newlibtable(L, l);
|
||||
luaL_setfuncs(L, l, 0)
|
||||
luaL_checkversion(L);
|
||||
luaL_newlibtable(L, l);
|
||||
luaL_setfuncs(L, l, 0)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn luaL_argcheck(L: *mut lua_State, cond: c_int, arg: c_int, extramsg: *const c_char) {
|
||||
if cond == 0 {
|
||||
luaL_argerror(L, arg, extramsg);
|
||||
}
|
||||
if cond == 0 {
|
||||
luaL_argerror(L, arg, extramsg);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn luaL_checkstring(L: *mut lua_State, n: c_int) -> *const c_char {
|
||||
luaL_checklstring(L, n, ptr::null_mut())
|
||||
luaL_checklstring(L, n, ptr::null_mut())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn luaL_optstring(L: *mut lua_State, n: c_int, d: *const c_char) -> *const c_char {
|
||||
luaL_optlstring(L, n, d, ptr::null_mut())
|
||||
luaL_optlstring(L, n, d, ptr::null_mut())
|
||||
}
|
||||
|
||||
// From 5.3 user manual:
|
||||
|
@ -155,110 +185,115 @@ pub unsafe fn luaL_optstring(L: *mut lua_State, n: c_int, d: *const c_char) -> *
|
|||
#[inline(always)]
|
||||
//#[deprecated]
|
||||
pub unsafe fn luaL_checkint(L: *mut lua_State, n: c_int) -> c_int {
|
||||
luaL_checkinteger(L, n) as c_int
|
||||
luaL_checkinteger(L, n) as c_int
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
//#[deprecated]
|
||||
pub unsafe fn luaL_optint(L: *mut lua_State, n: c_int, d: c_int) -> c_int {
|
||||
luaL_optinteger(L, n, d as lua_Integer) as c_int
|
||||
luaL_optinteger(L, n, d as lua_Integer) as c_int
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
//#[deprecated]
|
||||
pub unsafe fn luaL_checklong(L: *mut lua_State, n: c_int) -> c_long {
|
||||
luaL_checkinteger(L, n) as c_long
|
||||
luaL_checkinteger(L, n) as c_long
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
//#[deprecated]
|
||||
pub unsafe fn luaL_optlong(L: *mut lua_State, n: c_int, d: c_long) -> c_long {
|
||||
luaL_optinteger(L, n, d as lua_Integer) as c_long
|
||||
luaL_optinteger(L, n, d as lua_Integer) as c_long
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn luaL_typename(L: *mut lua_State, i: c_int) -> *const c_char {
|
||||
lua::lua_typename(L, lua::lua_type(L, i))
|
||||
lua::lua_typename(L, lua::lua_type(L, i))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn luaL_dofile(L: *mut lua_State, filename: *const c_char) -> c_int {
|
||||
let status = luaL_loadfile(L, filename);
|
||||
if status == 0 {
|
||||
lua::lua_pcall(L, 0, lua::LUA_MULTRET, 0)
|
||||
} else {
|
||||
status
|
||||
}
|
||||
let status = luaL_loadfile(L, filename);
|
||||
if status == 0 {
|
||||
lua::lua_pcall(L, 0, lua::LUA_MULTRET, 0)
|
||||
} else {
|
||||
status
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn luaL_dostring(L: *mut lua_State, s: *const c_char) -> c_int {
|
||||
let status = luaL_loadstring(L, s);
|
||||
if status == 0 {
|
||||
lua::lua_pcall(L, 0, lua::LUA_MULTRET, 0)
|
||||
} else {
|
||||
status
|
||||
}
|
||||
let status = luaL_loadstring(L, s);
|
||||
if status == 0 {
|
||||
lua::lua_pcall(L, 0, lua::LUA_MULTRET, 0)
|
||||
} else {
|
||||
status
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn luaL_getmetatable(L: *mut lua_State, n: *const c_char) {
|
||||
lua::lua_getfield(L, lua::LUA_REGISTRYINDEX, n);
|
||||
lua::lua_getfield(L, lua::LUA_REGISTRYINDEX, n);
|
||||
}
|
||||
|
||||
// luaL_opt would be implemented here but it is undocumented, so it's omitted
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn luaL_loadbuffer(L: *mut lua_State, s: *const c_char, sz: size_t, n: *const c_char) -> c_int {
|
||||
luaL_loadbufferx(L, s, sz, n, ptr::null())
|
||||
pub unsafe fn luaL_loadbuffer(
|
||||
L: *mut lua_State,
|
||||
s: *const c_char,
|
||||
sz: size_t,
|
||||
n: *const c_char,
|
||||
) -> c_int {
|
||||
luaL_loadbufferx(L, s, sz, n, ptr::null())
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct luaL_Buffer {
|
||||
pub b: *mut c_char,
|
||||
pub size: size_t,
|
||||
pub n: size_t,
|
||||
pub L: *mut lua_State,
|
||||
pub initb: [c_char; LUAL_BUFFERSIZE as usize]
|
||||
pub b: *mut c_char,
|
||||
pub size: size_t,
|
||||
pub n: size_t,
|
||||
pub L: *mut lua_State,
|
||||
pub initb: [c_char; LUAL_BUFFERSIZE as usize],
|
||||
}
|
||||
|
||||
// TODO: Test this thoroughly
|
||||
#[inline(always)]
|
||||
pub unsafe fn luaL_addchar(B: *mut luaL_Buffer, c: c_char) {
|
||||
// (B)->n < (B) -> size || luaL_prepbuffsize((B), 1)
|
||||
if (*B).n < (*B).size {
|
||||
luaL_prepbuffsize(B, 1);
|
||||
}
|
||||
// (B)->b[(B)->n++] = (c)
|
||||
let offset = (*B).b.offset((*B).n as isize);
|
||||
ptr::write(offset, c);
|
||||
(*B).n += 1;
|
||||
// (B)->n < (B) -> size || luaL_prepbuffsize((B), 1)
|
||||
if (*B).n < (*B).size {
|
||||
luaL_prepbuffsize(B, 1);
|
||||
}
|
||||
// (B)->b[(B)->n++] = (c)
|
||||
let offset = (*B).b.offset((*B).n as isize);
|
||||
ptr::write(offset, c);
|
||||
(*B).n += 1;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn luaL_addsize(B: *mut luaL_Buffer, s: size_t) {
|
||||
(*B).n += s;
|
||||
(*B).n += s;
|
||||
}
|
||||
|
||||
extern {
|
||||
pub fn luaL_buffinit(L: *mut lua_State, B: *mut luaL_Buffer);
|
||||
pub fn luaL_prepbuffsize(B: *mut luaL_Buffer, sz: size_t) -> *mut c_char;
|
||||
pub fn luaL_addlstring(B: *mut luaL_Buffer, s: *const c_char, l: size_t);
|
||||
pub fn luaL_addstring(B: *mut luaL_Buffer, s: *const c_char);
|
||||
pub fn luaL_addvalue(B: *mut luaL_Buffer);
|
||||
pub fn luaL_pushresult(B: *mut luaL_Buffer);
|
||||
pub fn luaL_pushresultsize(B: *mut luaL_Buffer, sz: size_t);
|
||||
pub fn luaL_buffinitsize(L: *mut lua_State, B: *mut luaL_Buffer, sz: size_t) -> *mut c_char;
|
||||
extern "C" {
|
||||
pub fn luaL_buffinit(L: *mut lua_State, B: *mut luaL_Buffer);
|
||||
pub fn luaL_prepbuffsize(B: *mut luaL_Buffer, sz: size_t) -> *mut c_char;
|
||||
pub fn luaL_addlstring(B: *mut luaL_Buffer, s: *const c_char, l: size_t);
|
||||
pub fn luaL_addstring(B: *mut luaL_Buffer, s: *const c_char);
|
||||
pub fn luaL_addvalue(B: *mut luaL_Buffer);
|
||||
pub fn luaL_pushresult(B: *mut luaL_Buffer);
|
||||
pub fn luaL_pushresultsize(B: *mut luaL_Buffer, sz: size_t);
|
||||
pub fn luaL_buffinitsize(L: *mut lua_State, B: *mut luaL_Buffer, sz: size_t) -> *mut c_char;
|
||||
}
|
||||
|
||||
pub unsafe fn luaL_prepbuffer(B: *mut luaL_Buffer) -> *mut c_char {
|
||||
luaL_prepbuffsize(B, LUAL_BUFFERSIZE as size_t)
|
||||
luaL_prepbuffsize(B, LUAL_BUFFERSIZE as size_t)
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct luaL_Stream {
|
||||
pub f: *mut ::libc::FILE,
|
||||
pub closef: lua_CFunction
|
||||
pub f: *mut ::libc::FILE,
|
||||
pub closef: lua_CFunction,
|
||||
}
|
||||
|
||||
// omitted: old module system compatibility
|
||||
|
|
336
src/ffi/lua.rs
336
src/ffi/lua.rs
|
@ -22,14 +22,14 @@
|
|||
|
||||
//! Contains definitions from `lua.h`.
|
||||
|
||||
use libc::{c_void, c_int, c_char, c_uchar, size_t};
|
||||
use libc::{c_char, c_int, c_uchar, c_void, size_t};
|
||||
use std::ptr;
|
||||
|
||||
use super::luaconf;
|
||||
|
||||
pub use super::glue::LUA_REGISTRYINDEX;
|
||||
pub use super::glue::{LUA_AUTHORS, LUA_COPYRIGHT, LUA_RELEASE, LUA_VERSION};
|
||||
pub use super::glue::{LUA_VERSION_MAJOR, LUA_VERSION_MINOR, LUA_VERSION_NUM, LUA_VERSION_RELEASE};
|
||||
pub use super::glue::{LUA_VERSION, LUA_RELEASE, LUA_COPYRIGHT, LUA_AUTHORS};
|
||||
pub use super::glue::{LUA_REGISTRYINDEX};
|
||||
|
||||
pub const LUA_SIGNATURE: &'static [u8] = b"\x1bLua";
|
||||
|
||||
|
@ -38,7 +38,7 @@ pub const LUA_MULTRET: c_int = -1;
|
|||
|
||||
#[inline(always)]
|
||||
pub fn lua_upvalueindex(i: c_int) -> c_int {
|
||||
LUA_REGISTRYINDEX - i
|
||||
LUA_REGISTRYINDEX - i
|
||||
}
|
||||
|
||||
// thread status
|
||||
|
@ -91,54 +91,62 @@ pub type lua_KContext = luaconf::LUA_KCONTEXT;
|
|||
pub type lua_CFunction = unsafe extern "C" fn(L: *mut lua_State) -> c_int;
|
||||
|
||||
// Type for continuation functions
|
||||
pub type lua_KFunction = unsafe extern "C" fn(L: *mut lua_State, status: c_int, ctx: lua_KContext) -> c_int;
|
||||
pub type lua_KFunction =
|
||||
unsafe extern "C" fn(L: *mut lua_State, status: c_int, ctx: lua_KContext) -> c_int;
|
||||
|
||||
// Type for functions that read/write blocks when loading/dumping Lua chunks
|
||||
pub type lua_Reader = unsafe extern "C" fn(L: *mut lua_State, ud: *mut c_void, sz: *mut size_t) -> *const c_char;
|
||||
pub type lua_Writer = unsafe extern "C" fn(L: *mut lua_State, p: *const c_void, sz: size_t, ud: *mut c_void) -> c_int;
|
||||
pub type lua_Reader =
|
||||
unsafe extern "C" fn(L: *mut lua_State, ud: *mut c_void, sz: *mut size_t) -> *const c_char;
|
||||
pub type lua_Writer =
|
||||
unsafe extern "C" fn(L: *mut lua_State, p: *const c_void, sz: size_t, ud: *mut c_void) -> c_int;
|
||||
|
||||
/// Type for memory-allocation functions.
|
||||
pub type lua_Alloc = unsafe extern "C" fn(ud: *mut c_void, ptr: *mut c_void, osize: size_t, nsize: size_t) -> *mut c_void;
|
||||
pub type lua_Alloc = unsafe extern "C" fn(
|
||||
ud: *mut c_void,
|
||||
ptr: *mut c_void,
|
||||
osize: size_t,
|
||||
nsize: size_t,
|
||||
) -> *mut c_void;
|
||||
|
||||
extern "C" {
|
||||
// state manipulation
|
||||
pub fn lua_newstate(f: lua_Alloc, ud: *mut c_void) -> *mut lua_State;
|
||||
pub fn lua_close(L: *mut lua_State);
|
||||
pub fn lua_newthread(L: *mut lua_State) -> *mut lua_State;
|
||||
// state manipulation
|
||||
pub fn lua_newstate(f: lua_Alloc, ud: *mut c_void) -> *mut lua_State;
|
||||
pub fn lua_close(L: *mut lua_State);
|
||||
pub fn lua_newthread(L: *mut lua_State) -> *mut lua_State;
|
||||
|
||||
pub fn lua_atpanic(L: *mut lua_State, panicf: lua_CFunction) -> lua_CFunction;
|
||||
pub fn lua_atpanic(L: *mut lua_State, panicf: lua_CFunction) -> lua_CFunction;
|
||||
|
||||
pub fn lua_version(L: *mut lua_State) -> *const lua_Number;
|
||||
pub fn lua_version(L: *mut lua_State) -> *const lua_Number;
|
||||
|
||||
// basic stack manipulation
|
||||
pub fn lua_absindex(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_gettop(L: *mut lua_State) -> c_int;
|
||||
pub fn lua_settop(L: *mut lua_State, idx: c_int);
|
||||
pub fn lua_pushvalue(L: *mut lua_State, idx: c_int);
|
||||
pub fn lua_rotate(L: *mut lua_State, idx: c_int, n: c_int);
|
||||
pub fn lua_copy(L: *mut lua_State, fromidx: c_int, toidx: c_int);
|
||||
pub fn lua_checkstack(L: *mut lua_State, sz: c_int) -> c_int;
|
||||
// basic stack manipulation
|
||||
pub fn lua_absindex(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_gettop(L: *mut lua_State) -> c_int;
|
||||
pub fn lua_settop(L: *mut lua_State, idx: c_int);
|
||||
pub fn lua_pushvalue(L: *mut lua_State, idx: c_int);
|
||||
pub fn lua_rotate(L: *mut lua_State, idx: c_int, n: c_int);
|
||||
pub fn lua_copy(L: *mut lua_State, fromidx: c_int, toidx: c_int);
|
||||
pub fn lua_checkstack(L: *mut lua_State, sz: c_int) -> c_int;
|
||||
|
||||
pub fn lua_xmove(from: *mut lua_State, to: *mut lua_State, n: c_int);
|
||||
pub fn lua_xmove(from: *mut lua_State, to: *mut lua_State, n: c_int);
|
||||
|
||||
// access functions (stack -> C)
|
||||
pub fn lua_isnumber(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_isstring(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_iscfunction(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_isinteger(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_isuserdata(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_type(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_typename(L: *mut lua_State, tp: c_int) -> *const c_char;
|
||||
// access functions (stack -> C)
|
||||
pub fn lua_isnumber(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_isstring(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_iscfunction(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_isinteger(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_isuserdata(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_type(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_typename(L: *mut lua_State, tp: c_int) -> *const c_char;
|
||||
|
||||
pub fn lua_tonumberx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Number;
|
||||
pub fn lua_tointegerx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Integer;
|
||||
pub fn lua_toboolean(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_tolstring(L: *mut lua_State, idx: c_int, len: *mut size_t) -> *const c_char;
|
||||
pub fn lua_rawlen(L: *mut lua_State, idx: c_int) -> size_t;
|
||||
pub fn lua_tocfunction(L: *mut lua_State, idx: c_int) -> lua_CFunction;
|
||||
pub fn lua_touserdata(L: *mut lua_State, idx: c_int) -> *mut c_void;
|
||||
pub fn lua_tothread(L: *mut lua_State, idx: c_int) -> *mut lua_State;
|
||||
pub fn lua_topointer(L: *mut lua_State, idx: c_int) -> *const c_void;
|
||||
pub fn lua_tonumberx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Number;
|
||||
pub fn lua_tointegerx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Integer;
|
||||
pub fn lua_toboolean(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_tolstring(L: *mut lua_State, idx: c_int, len: *mut size_t) -> *const c_char;
|
||||
pub fn lua_rawlen(L: *mut lua_State, idx: c_int) -> size_t;
|
||||
pub fn lua_tocfunction(L: *mut lua_State, idx: c_int) -> lua_CFunction;
|
||||
pub fn lua_touserdata(L: *mut lua_State, idx: c_int) -> *mut c_void;
|
||||
pub fn lua_tothread(L: *mut lua_State, idx: c_int) -> *mut lua_State;
|
||||
pub fn lua_topointer(L: *mut lua_State, idx: c_int) -> *const c_void;
|
||||
}
|
||||
|
||||
// Comparison and arithmetic functions
|
||||
|
@ -158,7 +166,7 @@ pub const LUA_OPUNM: c_int = 12;
|
|||
pub const LUA_OPBNOT: c_int = 13;
|
||||
|
||||
extern "C" {
|
||||
pub fn lua_arith(L: *mut lua_State, op: c_int);
|
||||
pub fn lua_arith(L: *mut lua_State, op: c_int);
|
||||
}
|
||||
|
||||
pub const LUA_OPEQ: c_int = 0;
|
||||
|
@ -166,84 +174,113 @@ pub const LUA_OPLT: c_int = 1;
|
|||
pub const LUA_OPLE: c_int = 2;
|
||||
|
||||
extern "C" {
|
||||
pub fn lua_rawequal(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int;
|
||||
pub fn lua_compare(L: *mut lua_State, idx1: c_int, idx2: c_int, op: c_int) -> c_int;
|
||||
pub fn lua_rawequal(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int;
|
||||
pub fn lua_compare(L: *mut lua_State, idx1: c_int, idx2: c_int, op: c_int) -> c_int;
|
||||
}
|
||||
|
||||
// push functions (C -> stack)
|
||||
extern "C" {
|
||||
pub fn lua_pushnil(L: *mut lua_State);
|
||||
pub fn lua_pushnumber(L: *mut lua_State, n: lua_Number);
|
||||
pub fn lua_pushinteger(L: *mut lua_State, n: lua_Integer);
|
||||
pub fn lua_pushlstring(L: *mut lua_State, s: *const c_char, l: size_t) -> *const c_char;
|
||||
pub fn lua_pushstring(L: *mut lua_State, s: *const c_char) -> *const c_char;
|
||||
// TODO: omitted:
|
||||
// lua_pushvfstring
|
||||
pub fn lua_pushfstring(L: *mut lua_State, fmt: *const c_char, ...) -> *const c_char;
|
||||
pub fn lua_pushcclosure(L: *mut lua_State, f: lua_CFunction, n: c_int);
|
||||
pub fn lua_pushboolean(L: *mut lua_State, b: c_int);
|
||||
pub fn lua_pushlightuserdata(L: *mut lua_State, p: *mut c_void);
|
||||
pub fn lua_pushthread(L: *mut lua_State) -> c_int;
|
||||
pub fn lua_pushnil(L: *mut lua_State);
|
||||
pub fn lua_pushnumber(L: *mut lua_State, n: lua_Number);
|
||||
pub fn lua_pushinteger(L: *mut lua_State, n: lua_Integer);
|
||||
pub fn lua_pushlstring(L: *mut lua_State, s: *const c_char, l: size_t) -> *const c_char;
|
||||
pub fn lua_pushstring(L: *mut lua_State, s: *const c_char) -> *const c_char;
|
||||
// TODO: omitted:
|
||||
// lua_pushvfstring
|
||||
pub fn lua_pushfstring(L: *mut lua_State, fmt: *const c_char, ...) -> *const c_char;
|
||||
pub fn lua_pushcclosure(L: *mut lua_State, f: lua_CFunction, n: c_int);
|
||||
pub fn lua_pushboolean(L: *mut lua_State, b: c_int);
|
||||
pub fn lua_pushlightuserdata(L: *mut lua_State, p: *mut c_void);
|
||||
pub fn lua_pushthread(L: *mut lua_State) -> c_int;
|
||||
}
|
||||
|
||||
// get functions (Lua -> stack)
|
||||
extern "C" {
|
||||
pub fn lua_getglobal(L: *mut lua_State, var: *const c_char) -> c_int;
|
||||
pub fn lua_gettable(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_getfield(L: *mut lua_State, idx: c_int, k: *const c_char) -> c_int;
|
||||
pub fn lua_geti(L: *mut lua_State, idx: c_int, n: lua_Integer) -> c_int;
|
||||
pub fn lua_rawget(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_rawgeti(L: *mut lua_State, idx: c_int, n: lua_Integer) -> c_int;
|
||||
pub fn lua_rawgetp(L: *mut lua_State, idx: c_int, p: *const c_void) -> c_int;
|
||||
pub fn lua_getglobal(L: *mut lua_State, var: *const c_char) -> c_int;
|
||||
pub fn lua_gettable(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_getfield(L: *mut lua_State, idx: c_int, k: *const c_char) -> c_int;
|
||||
pub fn lua_geti(L: *mut lua_State, idx: c_int, n: lua_Integer) -> c_int;
|
||||
pub fn lua_rawget(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_rawgeti(L: *mut lua_State, idx: c_int, n: lua_Integer) -> c_int;
|
||||
pub fn lua_rawgetp(L: *mut lua_State, idx: c_int, p: *const c_void) -> c_int;
|
||||
|
||||
pub fn lua_createtable(L: *mut lua_State, narr: c_int, nrec: c_int);
|
||||
pub fn lua_newuserdata(L: *mut lua_State, sz: size_t) -> *mut c_void;
|
||||
pub fn lua_getmetatable(L: *mut lua_State, objindex: c_int) -> c_int;
|
||||
pub fn lua_getuservalue(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_createtable(L: *mut lua_State, narr: c_int, nrec: c_int);
|
||||
pub fn lua_newuserdata(L: *mut lua_State, sz: size_t) -> *mut c_void;
|
||||
pub fn lua_getmetatable(L: *mut lua_State, objindex: c_int) -> c_int;
|
||||
pub fn lua_getuservalue(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
}
|
||||
|
||||
// set functions (stack -> Lua)
|
||||
extern "C" {
|
||||
pub fn lua_setglobal(L: *mut lua_State, var: *const c_char);
|
||||
pub fn lua_settable(L: *mut lua_State, idx: c_int);
|
||||
pub fn lua_setfield(L: *mut lua_State, idx: c_int, k: *const c_char);
|
||||
pub fn lua_seti(L: *mut lua_State, idx: c_int, n: lua_Integer);
|
||||
pub fn lua_rawset(L: *mut lua_State, idx: c_int);
|
||||
pub fn lua_rawseti(L: *mut lua_State, idx: c_int, n: lua_Integer);
|
||||
pub fn lua_rawsetp(L: *mut lua_State, idx: c_int, p: *const c_void);
|
||||
pub fn lua_setmetatable(L: *mut lua_State, objindex: c_int) -> c_int;
|
||||
pub fn lua_setuservalue(L: *mut lua_State, idx: c_int);
|
||||
pub fn lua_setglobal(L: *mut lua_State, var: *const c_char);
|
||||
pub fn lua_settable(L: *mut lua_State, idx: c_int);
|
||||
pub fn lua_setfield(L: *mut lua_State, idx: c_int, k: *const c_char);
|
||||
pub fn lua_seti(L: *mut lua_State, idx: c_int, n: lua_Integer);
|
||||
pub fn lua_rawset(L: *mut lua_State, idx: c_int);
|
||||
pub fn lua_rawseti(L: *mut lua_State, idx: c_int, n: lua_Integer);
|
||||
pub fn lua_rawsetp(L: *mut lua_State, idx: c_int, p: *const c_void);
|
||||
pub fn lua_setmetatable(L: *mut lua_State, objindex: c_int) -> c_int;
|
||||
pub fn lua_setuservalue(L: *mut lua_State, idx: c_int);
|
||||
}
|
||||
|
||||
// 'load' and 'call' functions (load and run Lua code)
|
||||
extern "C" {
|
||||
pub fn lua_callk(L: *mut lua_State, nargs: c_int, nresults: c_int, ctx: lua_KContext, k: Option<lua_KFunction>);
|
||||
pub fn lua_pcallk(L: *mut lua_State, nargs: c_int, nresults: c_int, errfunc: c_int, ctx: lua_KContext, k: Option<lua_KFunction>) -> c_int;
|
||||
pub fn lua_load(L: *mut lua_State, reader: lua_Reader, dt: *mut c_void, chunkname: *const c_char, mode: *const c_char) -> c_int;
|
||||
pub fn lua_dump(L: *mut lua_State, writer: lua_Writer, data: *mut c_void, strip: c_int) -> c_int;
|
||||
pub fn lua_callk(
|
||||
L: *mut lua_State,
|
||||
nargs: c_int,
|
||||
nresults: c_int,
|
||||
ctx: lua_KContext,
|
||||
k: Option<lua_KFunction>,
|
||||
);
|
||||
pub fn lua_pcallk(
|
||||
L: *mut lua_State,
|
||||
nargs: c_int,
|
||||
nresults: c_int,
|
||||
errfunc: c_int,
|
||||
ctx: lua_KContext,
|
||||
k: Option<lua_KFunction>,
|
||||
) -> c_int;
|
||||
pub fn lua_load(
|
||||
L: *mut lua_State,
|
||||
reader: lua_Reader,
|
||||
dt: *mut c_void,
|
||||
chunkname: *const c_char,
|
||||
mode: *const c_char,
|
||||
) -> c_int;
|
||||
pub fn lua_dump(
|
||||
L: *mut lua_State,
|
||||
writer: lua_Writer,
|
||||
data: *mut c_void,
|
||||
strip: c_int,
|
||||
) -> c_int;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_call(L: *mut lua_State, n: c_int, r: c_int) {
|
||||
lua_callk(L, n, r, 0, None)
|
||||
lua_callk(L, n, r, 0, None)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_pcall(L: *mut lua_State, n: c_int, r: c_int, f: c_int) -> c_int {
|
||||
lua_pcallk(L, n, r, f, 0, None)
|
||||
lua_pcallk(L, n, r, f, 0, None)
|
||||
}
|
||||
|
||||
// coroutine functions
|
||||
extern "C" {
|
||||
pub fn lua_yieldk(L: *mut lua_State, nresults: c_int, ctx: lua_KContext, k: Option<lua_KFunction>) -> c_int;
|
||||
pub fn lua_resume(L: *mut lua_State, from: *mut lua_State, narg: c_int) -> c_int;
|
||||
pub fn lua_status(L: *mut lua_State) -> c_int;
|
||||
pub fn lua_isyieldable(L: *mut lua_State) -> c_int;
|
||||
pub fn lua_yieldk(
|
||||
L: *mut lua_State,
|
||||
nresults: c_int,
|
||||
ctx: lua_KContext,
|
||||
k: Option<lua_KFunction>,
|
||||
) -> c_int;
|
||||
pub fn lua_resume(L: *mut lua_State, from: *mut lua_State, narg: c_int) -> c_int;
|
||||
pub fn lua_status(L: *mut lua_State) -> c_int;
|
||||
pub fn lua_isyieldable(L: *mut lua_State) -> c_int;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_yield(L: *mut lua_State, n: c_int) -> c_int {
|
||||
lua_yieldk(L, n, 0, None)
|
||||
lua_yieldk(L, n, 0, None)
|
||||
}
|
||||
|
||||
// garbage-collection function and options
|
||||
|
@ -257,132 +294,132 @@ pub const LUA_GCSETPAUSE: c_int = 6;
|
|||
pub const LUA_GCSETSTEPMUL: c_int = 7;
|
||||
pub const LUA_GCISRUNNING: c_int = 9;
|
||||
|
||||
extern {
|
||||
pub fn lua_gc(L: *mut lua_State, what: c_int, data: c_int) -> c_int;
|
||||
extern "C" {
|
||||
pub fn lua_gc(L: *mut lua_State, what: c_int, data: c_int) -> c_int;
|
||||
}
|
||||
|
||||
// miscellaneous functions
|
||||
extern {
|
||||
pub fn lua_error(L: *mut lua_State) -> !;
|
||||
pub fn lua_next(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_concat(L: *mut lua_State, n: c_int);
|
||||
pub fn lua_len(L: *mut lua_State, idx: c_int);
|
||||
pub fn lua_stringtonumber(L: *mut lua_State, s: *const c_char) -> size_t;
|
||||
pub fn lua_getallocf(L: *mut lua_State, ud: *mut *mut c_void) -> lua_Alloc;
|
||||
pub fn lua_setallocf(L: *mut lua_State, f: lua_Alloc, ud: *mut c_void);
|
||||
extern "C" {
|
||||
pub fn lua_error(L: *mut lua_State) -> !;
|
||||
pub fn lua_next(L: *mut lua_State, idx: c_int) -> c_int;
|
||||
pub fn lua_concat(L: *mut lua_State, n: c_int);
|
||||
pub fn lua_len(L: *mut lua_State, idx: c_int);
|
||||
pub fn lua_stringtonumber(L: *mut lua_State, s: *const c_char) -> size_t;
|
||||
pub fn lua_getallocf(L: *mut lua_State, ud: *mut *mut c_void) -> lua_Alloc;
|
||||
pub fn lua_setallocf(L: *mut lua_State, f: lua_Alloc, ud: *mut c_void);
|
||||
}
|
||||
|
||||
// some useful macros
|
||||
// here, implemented as Rust functions
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_getextraspace(L: *mut lua_State) -> *mut c_void {
|
||||
L.offset(-super::glue::LUA_EXTRASPACE as isize) as *mut c_void
|
||||
L.offset(-super::glue::LUA_EXTRASPACE as isize) as *mut c_void
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_tonumber(L: *mut lua_State, i: c_int) -> lua_Number {
|
||||
lua_tonumberx(L, i, ptr::null_mut())
|
||||
lua_tonumberx(L, i, ptr::null_mut())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_tointeger(L: *mut lua_State, i: c_int) -> lua_Integer {
|
||||
lua_tointegerx(L, i, ptr::null_mut())
|
||||
lua_tointegerx(L, i, ptr::null_mut())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_pop(L: *mut lua_State, n: c_int) {
|
||||
lua_settop(L, -n - 1)
|
||||
lua_settop(L, -n - 1)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_newtable(L: *mut lua_State) {
|
||||
lua_createtable(L, 0, 0)
|
||||
lua_createtable(L, 0, 0)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_register(L: *mut lua_State, n: *const c_char, f: lua_CFunction) {
|
||||
lua_pushcfunction(L, f);
|
||||
lua_setglobal(L, n)
|
||||
lua_pushcfunction(L, f);
|
||||
lua_setglobal(L, n)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_pushcfunction(L: *mut lua_State, f: lua_CFunction) {
|
||||
lua_pushcclosure(L, f, 0)
|
||||
lua_pushcclosure(L, f, 0)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_isfunction(L: *mut lua_State, n: c_int) -> c_int {
|
||||
(lua_type(L, n) == LUA_TFUNCTION) as c_int
|
||||
(lua_type(L, n) == LUA_TFUNCTION) as c_int
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_istable(L: *mut lua_State, n: c_int) -> c_int {
|
||||
(lua_type(L, n) == LUA_TTABLE) as c_int
|
||||
(lua_type(L, n) == LUA_TTABLE) as c_int
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_islightuserdata(L: *mut lua_State, n: c_int) -> c_int {
|
||||
(lua_type(L, n) == LUA_TLIGHTUSERDATA) as c_int
|
||||
(lua_type(L, n) == LUA_TLIGHTUSERDATA) as c_int
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_isnil(L: *mut lua_State, n: c_int) -> c_int {
|
||||
(lua_type(L, n) == LUA_TNIL) as c_int
|
||||
(lua_type(L, n) == LUA_TNIL) as c_int
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_isboolean(L: *mut lua_State, n: c_int) -> c_int {
|
||||
(lua_type(L, n) == LUA_TBOOLEAN) as c_int
|
||||
(lua_type(L, n) == LUA_TBOOLEAN) as c_int
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_isthread(L: *mut lua_State, n: c_int) -> c_int {
|
||||
(lua_type(L, n) == LUA_TTHREAD) as c_int
|
||||
(lua_type(L, n) == LUA_TTHREAD) as c_int
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_isnone(L: *mut lua_State, n: c_int) -> c_int {
|
||||
(lua_type(L, n) == LUA_TNONE) as c_int
|
||||
(lua_type(L, n) == LUA_TNONE) as c_int
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_isnoneornil(L: *mut lua_State, n: c_int) -> c_int {
|
||||
(lua_type(L, n) <= 0) as c_int
|
||||
(lua_type(L, n) <= 0) as c_int
|
||||
}
|
||||
|
||||
// TODO: Test
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_pushliteral(L: *mut lua_State, s: &'static str) -> *const c_char {
|
||||
use std::ffi::CString;
|
||||
let c_str = CString::new(s).unwrap();
|
||||
lua_pushlstring(L, c_str.as_ptr(), c_str.as_bytes().len() as size_t)
|
||||
use std::ffi::CString;
|
||||
let c_str = CString::new(s).unwrap();
|
||||
lua_pushlstring(L, c_str.as_ptr(), c_str.as_bytes().len() as size_t)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_pushglobaltable(L: *mut lua_State) -> c_int {
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_tostring(L: *mut lua_State, i: c_int) -> *const c_char {
|
||||
lua_tolstring(L, i, ptr::null_mut())
|
||||
lua_tolstring(L, i, ptr::null_mut())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_insert(L: *mut lua_State, idx: c_int) {
|
||||
lua_rotate(L, idx, 1)
|
||||
lua_rotate(L, idx, 1)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_remove(L: *mut lua_State, idx: c_int) {
|
||||
lua_rotate(L, idx, -1);
|
||||
lua_pop(L, 1)
|
||||
lua_rotate(L, idx, -1);
|
||||
lua_pop(L, 1)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_replace(L: *mut lua_State, idx: c_int) {
|
||||
lua_copy(L, -1, idx);
|
||||
lua_pop(L, 1)
|
||||
lua_copy(L, -1, idx);
|
||||
lua_pop(L, 1)
|
||||
}
|
||||
|
||||
// Debug API
|
||||
|
@ -403,38 +440,37 @@ pub const LUA_MASKCOUNT: c_int = 1 << (LUA_HOOKCOUNT as usize);
|
|||
pub type lua_Hook = Option<extern "C" fn(L: *mut lua_State, ar: *mut lua_Debug)>;
|
||||
|
||||
extern "C" {
|
||||
pub fn lua_getstack(L: *mut lua_State, level: c_int, ar: *mut lua_Debug) -> c_int;
|
||||
pub fn lua_getinfo(L: *mut lua_State, what: *const c_char, ar: *mut lua_Debug) -> c_int;
|
||||
pub fn lua_getlocal(L: *mut lua_State, ar: *const lua_Debug, n: c_int) -> *const c_char;
|
||||
pub fn lua_setlocal(L: *mut lua_State, ar: *const lua_Debug, n: c_int) -> *const c_char;
|
||||
pub fn lua_getupvalue(L: *mut lua_State, funcindex: c_int, n: c_int) -> *const c_char;
|
||||
pub fn lua_setupvalue(L: *mut lua_State, funcindex: c_int, n: c_int) -> *const c_char;
|
||||
pub fn lua_getstack(L: *mut lua_State, level: c_int, ar: *mut lua_Debug) -> c_int;
|
||||
pub fn lua_getinfo(L: *mut lua_State, what: *const c_char, ar: *mut lua_Debug) -> c_int;
|
||||
pub fn lua_getlocal(L: *mut lua_State, ar: *const lua_Debug, n: c_int) -> *const c_char;
|
||||
pub fn lua_setlocal(L: *mut lua_State, ar: *const lua_Debug, n: c_int) -> *const c_char;
|
||||
pub fn lua_getupvalue(L: *mut lua_State, funcindex: c_int, n: c_int) -> *const c_char;
|
||||
pub fn lua_setupvalue(L: *mut lua_State, funcindex: c_int, n: c_int) -> *const c_char;
|
||||
|
||||
pub fn lua_upvalueid(L: *mut lua_State, fidx: c_int, n: c_int) -> *mut c_void;
|
||||
pub fn lua_upvaluejoin(L: *mut lua_State, fidx1: c_int, n1: c_int, fidx2: c_int, n2: c_int);
|
||||
pub fn lua_upvalueid(L: *mut lua_State, fidx: c_int, n: c_int) -> *mut c_void;
|
||||
pub fn lua_upvaluejoin(L: *mut lua_State, fidx1: c_int, n1: c_int, fidx2: c_int, n2: c_int);
|
||||
|
||||
pub fn lua_sethook(L: *mut lua_State, func: lua_Hook, mask: c_int, count: c_int);
|
||||
pub fn lua_gethook(L: *mut lua_State) -> lua_Hook;
|
||||
pub fn lua_gethookmask(L: *mut lua_State) -> c_int;
|
||||
pub fn lua_gethookcount(L: *mut lua_State) -> c_int;
|
||||
pub fn lua_sethook(L: *mut lua_State, func: lua_Hook, mask: c_int, count: c_int);
|
||||
pub fn lua_gethook(L: *mut lua_State) -> lua_Hook;
|
||||
pub fn lua_gethookmask(L: *mut lua_State) -> c_int;
|
||||
pub fn lua_gethookcount(L: *mut lua_State) -> c_int;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct lua_Debug {
|
||||
pub event: c_int,
|
||||
pub name: *const c_char,
|
||||
pub namewhat: *const c_char,
|
||||
pub what: *const c_char,
|
||||
pub source: *const c_char,
|
||||
pub currentline: c_int,
|
||||
pub linedefined: c_int,
|
||||
pub lastlinedefined: c_int,
|
||||
pub nups: c_uchar,
|
||||
pub nparams: c_uchar,
|
||||
pub isvararg: c_char,
|
||||
pub istailcall: c_char,
|
||||
pub short_src: [c_char; luaconf::LUA_IDSIZE as usize],
|
||||
// lua.h mentions this is for private use
|
||||
i_ci: *mut c_void,
|
||||
pub event: c_int,
|
||||
pub name: *const c_char,
|
||||
pub namewhat: *const c_char,
|
||||
pub what: *const c_char,
|
||||
pub source: *const c_char,
|
||||
pub currentline: c_int,
|
||||
pub linedefined: c_int,
|
||||
pub lastlinedefined: c_int,
|
||||
pub nups: c_uchar,
|
||||
pub nparams: c_uchar,
|
||||
pub isvararg: c_char,
|
||||
pub istailcall: c_char,
|
||||
pub short_src: [c_char; luaconf::LUA_IDSIZE as usize],
|
||||
// lua.h mentions this is for private use
|
||||
i_ci: *mut c_void,
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,12 @@
|
|||
//! Contains definitions from `luaconf.h`.
|
||||
|
||||
pub use super::glue::LUAL_BUFFERSIZE;
|
||||
pub use super::glue::LUA_NUMBER;
|
||||
pub use super::glue::LUA_INTEGER;
|
||||
pub use super::glue::LUA_NUMBER;
|
||||
pub use super::glue::LUA_UNSIGNED;
|
||||
|
||||
pub use super::glue::{LUA_IDSIZE};
|
||||
pub use super::glue::{LUA_MININTEGER, LUA_MAXINTEGER};
|
||||
pub use super::glue::LUA_IDSIZE;
|
||||
pub use super::glue::{LUA_MAXINTEGER, LUA_MININTEGER};
|
||||
|
||||
pub use super::glue::LUAI_MAXSTACK;
|
||||
pub use super::glue::LUAL_NUMSIZES;
|
||||
|
@ -39,11 +39,10 @@ use libc::c_int;
|
|||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_numtointeger(n: LUA_NUMBER, p: *mut LUA_INTEGER) -> c_int {
|
||||
if n >= (LUA_MININTEGER as LUA_NUMBER) && n < -(LUA_MININTEGER as LUA_NUMBER) {
|
||||
*p = n as LUA_INTEGER;
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if n >= (LUA_MININTEGER as LUA_NUMBER) && n < -(LUA_MININTEGER as LUA_NUMBER) {
|
||||
*p = n as LUA_INTEGER;
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,22 +27,22 @@ use libc::c_int;
|
|||
use super::lua::lua_State;
|
||||
|
||||
pub use super::glue::{
|
||||
LUA_COLIBNAME, LUA_TABLIBNAME, LUA_IOLIBNAME, LUA_OSLIBNAME, LUA_STRLIBNAME,
|
||||
LUA_UTF8LIBNAME, LUA_BITLIBNAME, LUA_MATHLIBNAME, LUA_DBLIBNAME, LUA_LOADLIBNAME
|
||||
LUA_BITLIBNAME, LUA_COLIBNAME, LUA_DBLIBNAME, LUA_IOLIBNAME, LUA_LOADLIBNAME, LUA_MATHLIBNAME,
|
||||
LUA_OSLIBNAME, LUA_STRLIBNAME, LUA_TABLIBNAME, LUA_UTF8LIBNAME,
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
pub fn luaopen_base(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_coroutine(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_table(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_io(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_os(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_string(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_utf8(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_bit32(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_math(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_debug(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_package(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_base(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_coroutine(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_table(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_io(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_os(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_string(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_utf8(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_bit32(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_math(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_debug(L: *mut lua_State) -> c_int;
|
||||
pub fn luaopen_package(L: *mut lua_State) -> c_int;
|
||||
|
||||
pub fn luaL_openlibs(L: *mut lua_State);
|
||||
pub fn luaL_openlibs(L: *mut lua_State);
|
||||
}
|
||||
|
|
384
src/ffi/mod.rs
384
src/ffi/mod.rs
|
@ -34,266 +34,174 @@ pub use self::luaconf::lua_numtointeger;
|
|||
|
||||
// C API types
|
||||
pub use self::lua::{
|
||||
lua_Alloc,
|
||||
lua_CFunction,
|
||||
lua_KContext,
|
||||
lua_Debug,
|
||||
lua_Hook,
|
||||
lua_Integer,
|
||||
lua_KFunction,
|
||||
lua_Number,
|
||||
lua_Reader,
|
||||
lua_State,
|
||||
lua_Unsigned,
|
||||
lua_Writer
|
||||
lua_Alloc, lua_CFunction, lua_Debug, lua_Hook, lua_Integer, lua_KContext, lua_KFunction,
|
||||
lua_Number, lua_Reader, lua_State, lua_Unsigned, lua_Writer,
|
||||
};
|
||||
|
||||
// C API functions
|
||||
pub use self::lua::{
|
||||
lua_absindex,
|
||||
lua_arith,
|
||||
lua_atpanic,
|
||||
lua_call,
|
||||
lua_callk,
|
||||
lua_checkstack,
|
||||
lua_close,
|
||||
lua_compare,
|
||||
lua_concat,
|
||||
lua_copy,
|
||||
lua_createtable,
|
||||
lua_dump,
|
||||
lua_error,
|
||||
lua_gc,
|
||||
lua_getallocf,
|
||||
lua_getextraspace,
|
||||
lua_getfield,
|
||||
lua_getglobal,
|
||||
lua_gethook,
|
||||
lua_gethookcount,
|
||||
lua_gethookmask,
|
||||
lua_geti,
|
||||
lua_getinfo,
|
||||
lua_getlocal,
|
||||
lua_getmetatable,
|
||||
lua_getstack,
|
||||
lua_gettable,
|
||||
lua_gettop,
|
||||
lua_getupvalue,
|
||||
lua_getuservalue,
|
||||
lua_insert,
|
||||
lua_isboolean,
|
||||
lua_iscfunction,
|
||||
lua_isfunction,
|
||||
lua_isinteger,
|
||||
lua_islightuserdata,
|
||||
lua_isnil,
|
||||
lua_isnone,
|
||||
lua_isnoneornil,
|
||||
lua_isnumber,
|
||||
lua_isstring,
|
||||
lua_istable,
|
||||
lua_isthread,
|
||||
lua_isuserdata,
|
||||
lua_isyieldable,
|
||||
lua_len,
|
||||
lua_load,
|
||||
lua_newstate,
|
||||
lua_newtable,
|
||||
lua_newthread,
|
||||
lua_newuserdata,
|
||||
lua_next,
|
||||
lua_pcall,
|
||||
lua_pcallk,
|
||||
lua_pop,
|
||||
lua_pushboolean,
|
||||
lua_pushcclosure,
|
||||
lua_pushcfunction,
|
||||
lua_pushfstring,
|
||||
lua_pushglobaltable,
|
||||
lua_pushinteger,
|
||||
lua_pushlightuserdata,
|
||||
lua_pushliteral,
|
||||
lua_pushlstring,
|
||||
lua_pushnil,
|
||||
lua_pushnumber,
|
||||
lua_pushstring,
|
||||
lua_pushthread,
|
||||
lua_pushvalue,
|
||||
// omitted: lua_pushvfstring
|
||||
lua_rawequal,
|
||||
lua_rawget,
|
||||
lua_rawgeti,
|
||||
lua_rawgetp,
|
||||
lua_rawlen,
|
||||
lua_rawset,
|
||||
lua_rawseti,
|
||||
lua_rawsetp,
|
||||
lua_register,
|
||||
lua_remove,
|
||||
lua_replace,
|
||||
lua_resume,
|
||||
lua_rotate,
|
||||
lua_setallocf,
|
||||
lua_setfield,
|
||||
lua_setglobal,
|
||||
lua_sethook,
|
||||
lua_seti,
|
||||
lua_setlocal,
|
||||
lua_setmetatable,
|
||||
lua_settable,
|
||||
lua_settop,
|
||||
lua_setupvalue,
|
||||
lua_setuservalue,
|
||||
lua_status,
|
||||
lua_stringtonumber,
|
||||
lua_toboolean,
|
||||
lua_tocfunction,
|
||||
lua_tointeger,
|
||||
lua_tointegerx,
|
||||
lua_tolstring,
|
||||
lua_tonumber,
|
||||
lua_tonumberx,
|
||||
lua_topointer,
|
||||
lua_tostring,
|
||||
lua_tothread,
|
||||
lua_touserdata,
|
||||
lua_type,
|
||||
lua_typename,
|
||||
lua_upvalueid,
|
||||
lua_upvalueindex,
|
||||
lua_upvaluejoin,
|
||||
lua_version,
|
||||
lua_xmove,
|
||||
lua_yield,
|
||||
lua_yieldk
|
||||
lua_absindex,
|
||||
lua_arith,
|
||||
lua_atpanic,
|
||||
lua_call,
|
||||
lua_callk,
|
||||
lua_checkstack,
|
||||
lua_close,
|
||||
lua_compare,
|
||||
lua_concat,
|
||||
lua_copy,
|
||||
lua_createtable,
|
||||
lua_dump,
|
||||
lua_error,
|
||||
lua_gc,
|
||||
lua_getallocf,
|
||||
lua_getextraspace,
|
||||
lua_getfield,
|
||||
lua_getglobal,
|
||||
lua_gethook,
|
||||
lua_gethookcount,
|
||||
lua_gethookmask,
|
||||
lua_geti,
|
||||
lua_getinfo,
|
||||
lua_getlocal,
|
||||
lua_getmetatable,
|
||||
lua_getstack,
|
||||
lua_gettable,
|
||||
lua_gettop,
|
||||
lua_getupvalue,
|
||||
lua_getuservalue,
|
||||
lua_insert,
|
||||
lua_isboolean,
|
||||
lua_iscfunction,
|
||||
lua_isfunction,
|
||||
lua_isinteger,
|
||||
lua_islightuserdata,
|
||||
lua_isnil,
|
||||
lua_isnone,
|
||||
lua_isnoneornil,
|
||||
lua_isnumber,
|
||||
lua_isstring,
|
||||
lua_istable,
|
||||
lua_isthread,
|
||||
lua_isuserdata,
|
||||
lua_isyieldable,
|
||||
lua_len,
|
||||
lua_load,
|
||||
lua_newstate,
|
||||
lua_newtable,
|
||||
lua_newthread,
|
||||
lua_newuserdata,
|
||||
lua_next,
|
||||
lua_pcall,
|
||||
lua_pcallk,
|
||||
lua_pop,
|
||||
lua_pushboolean,
|
||||
lua_pushcclosure,
|
||||
lua_pushcfunction,
|
||||
lua_pushfstring,
|
||||
lua_pushglobaltable,
|
||||
lua_pushinteger,
|
||||
lua_pushlightuserdata,
|
||||
lua_pushliteral,
|
||||
lua_pushlstring,
|
||||
lua_pushnil,
|
||||
lua_pushnumber,
|
||||
lua_pushstring,
|
||||
lua_pushthread,
|
||||
lua_pushvalue,
|
||||
// omitted: lua_pushvfstring
|
||||
lua_rawequal,
|
||||
lua_rawget,
|
||||
lua_rawgeti,
|
||||
lua_rawgetp,
|
||||
lua_rawlen,
|
||||
lua_rawset,
|
||||
lua_rawseti,
|
||||
lua_rawsetp,
|
||||
lua_register,
|
||||
lua_remove,
|
||||
lua_replace,
|
||||
lua_resume,
|
||||
lua_rotate,
|
||||
lua_setallocf,
|
||||
lua_setfield,
|
||||
lua_setglobal,
|
||||
lua_sethook,
|
||||
lua_seti,
|
||||
lua_setlocal,
|
||||
lua_setmetatable,
|
||||
lua_settable,
|
||||
lua_settop,
|
||||
lua_setupvalue,
|
||||
lua_setuservalue,
|
||||
lua_status,
|
||||
lua_stringtonumber,
|
||||
lua_toboolean,
|
||||
lua_tocfunction,
|
||||
lua_tointeger,
|
||||
lua_tointegerx,
|
||||
lua_tolstring,
|
||||
lua_tonumber,
|
||||
lua_tonumberx,
|
||||
lua_topointer,
|
||||
lua_tostring,
|
||||
lua_tothread,
|
||||
lua_touserdata,
|
||||
lua_type,
|
||||
lua_typename,
|
||||
lua_upvalueid,
|
||||
lua_upvalueindex,
|
||||
lua_upvaluejoin,
|
||||
lua_version,
|
||||
lua_xmove,
|
||||
lua_yield,
|
||||
lua_yieldk,
|
||||
};
|
||||
|
||||
// auxiliary library types
|
||||
pub use self::lauxlib::{
|
||||
luaL_Buffer,
|
||||
luaL_Reg,
|
||||
luaL_Stream
|
||||
};
|
||||
pub use self::lauxlib::{luaL_Buffer, luaL_Reg, luaL_Stream};
|
||||
|
||||
// auxiliary library functions
|
||||
pub use self::lauxlib::{
|
||||
luaL_addchar,
|
||||
luaL_addlstring,
|
||||
luaL_addsize,
|
||||
luaL_addstring,
|
||||
luaL_addvalue,
|
||||
luaL_argcheck,
|
||||
luaL_argerror,
|
||||
luaL_buffinit,
|
||||
luaL_buffinitsize,
|
||||
luaL_callmeta,
|
||||
luaL_checkany,
|
||||
luaL_checkint,
|
||||
luaL_checkinteger,
|
||||
luaL_checklong,
|
||||
luaL_checklstring,
|
||||
luaL_checknumber,
|
||||
luaL_checkoption,
|
||||
luaL_checkstack,
|
||||
luaL_checkstring,
|
||||
luaL_checktype,
|
||||
luaL_checkudata,
|
||||
luaL_checkversion,
|
||||
luaL_dofile,
|
||||
luaL_dostring,
|
||||
luaL_error,
|
||||
luaL_execresult,
|
||||
luaL_fileresult,
|
||||
luaL_getmetafield,
|
||||
luaL_getmetatable,
|
||||
luaL_getsubtable,
|
||||
luaL_gsub,
|
||||
luaL_len,
|
||||
luaL_loadbuffer,
|
||||
luaL_loadbufferx,
|
||||
luaL_loadfile,
|
||||
luaL_loadfilex,
|
||||
luaL_loadstring,
|
||||
luaL_newlib,
|
||||
luaL_newlibtable,
|
||||
luaL_newmetatable,
|
||||
luaL_newstate,
|
||||
luaL_optint,
|
||||
luaL_optinteger,
|
||||
luaL_optlong,
|
||||
luaL_optlstring,
|
||||
luaL_optnumber,
|
||||
luaL_optstring,
|
||||
luaL_prepbuffer,
|
||||
luaL_prepbuffsize,
|
||||
luaL_pushresult,
|
||||
luaL_pushresultsize,
|
||||
luaL_ref,
|
||||
luaL_requiref,
|
||||
luaL_setfuncs,
|
||||
luaL_setmetatable,
|
||||
luaL_testudata,
|
||||
luaL_tolstring,
|
||||
luaL_traceback,
|
||||
luaL_typename,
|
||||
luaL_unref,
|
||||
luaL_where
|
||||
luaL_addchar, luaL_addlstring, luaL_addsize, luaL_addstring, luaL_addvalue, luaL_argcheck,
|
||||
luaL_argerror, luaL_buffinit, luaL_buffinitsize, luaL_callmeta, luaL_checkany, luaL_checkint,
|
||||
luaL_checkinteger, luaL_checklong, luaL_checklstring, luaL_checknumber, luaL_checkoption,
|
||||
luaL_checkstack, luaL_checkstring, luaL_checktype, luaL_checkudata, luaL_checkversion,
|
||||
luaL_dofile, luaL_dostring, luaL_error, luaL_execresult, luaL_fileresult, luaL_getmetafield,
|
||||
luaL_getmetatable, luaL_getsubtable, luaL_gsub, luaL_len, luaL_loadbuffer, luaL_loadbufferx,
|
||||
luaL_loadfile, luaL_loadfilex, luaL_loadstring, luaL_newlib, luaL_newlibtable,
|
||||
luaL_newmetatable, luaL_newstate, luaL_optint, luaL_optinteger, luaL_optlong, luaL_optlstring,
|
||||
luaL_optnumber, luaL_optstring, luaL_prepbuffer, luaL_prepbuffsize, luaL_pushresult,
|
||||
luaL_pushresultsize, luaL_ref, luaL_requiref, luaL_setfuncs, luaL_setmetatable, luaL_testudata,
|
||||
luaL_tolstring, luaL_traceback, luaL_typename, luaL_unref, luaL_where,
|
||||
};
|
||||
|
||||
// lualib.h functions
|
||||
pub use self::lualib::{
|
||||
luaopen_base,
|
||||
luaopen_coroutine,
|
||||
luaopen_table,
|
||||
luaopen_io,
|
||||
luaopen_os,
|
||||
luaopen_string,
|
||||
luaopen_utf8,
|
||||
luaopen_bit32,
|
||||
luaopen_math,
|
||||
luaopen_debug,
|
||||
luaopen_package,
|
||||
|
||||
luaL_openlibs
|
||||
luaL_openlibs, luaopen_base, luaopen_bit32, luaopen_coroutine, luaopen_debug, luaopen_io,
|
||||
luaopen_math, luaopen_os, luaopen_package, luaopen_string, luaopen_table, luaopen_utf8,
|
||||
};
|
||||
|
||||
// constants from lua.h
|
||||
pub use self::lua::{
|
||||
LUA_MULTRET,
|
||||
LUA_REGISTRYINDEX,
|
||||
|
||||
LUA_RIDX_MAINTHREAD, LUA_RIDX_GLOBALS,
|
||||
|
||||
LUA_OPADD, LUA_OPSUB, LUA_OPMUL, LUA_OPDIV, LUA_OPIDIV,
|
||||
LUA_OPMOD, LUA_OPPOW, LUA_OPUNM,
|
||||
LUA_OPBNOT, LUA_OPBAND, LUA_OPBOR, LUA_OPBXOR, LUA_OPSHL, LUA_OPSHR,
|
||||
LUA_OPEQ, LUA_OPLT, LUA_OPLE,
|
||||
|
||||
LUA_OK, LUA_YIELD, LUA_ERRRUN, LUA_ERRSYNTAX, LUA_ERRMEM, LUA_ERRGCMM, LUA_ERRERR,
|
||||
|
||||
LUA_TNONE, LUA_TNIL, LUA_TNUMBER, LUA_TBOOLEAN, LUA_TSTRING, LUA_TTABLE,
|
||||
LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD, LUA_TLIGHTUSERDATA,
|
||||
|
||||
LUA_HOOKCALL, LUA_HOOKRET, LUA_HOOKTAILCALL, LUA_HOOKLINE, LUA_HOOKCOUNT,
|
||||
LUA_MASKCALL, LUA_MASKRET, LUA_MASKLINE, LUA_MASKCOUNT,
|
||||
|
||||
LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, LUA_GCCOUNT, LUA_GCCOUNTB,
|
||||
LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL, LUA_GCISRUNNING,
|
||||
|
||||
LUA_MINSTACK
|
||||
LUA_ERRERR, LUA_ERRGCMM, LUA_ERRMEM, LUA_ERRRUN, LUA_ERRSYNTAX, LUA_GCCOLLECT, LUA_GCCOUNT,
|
||||
LUA_GCCOUNTB, LUA_GCISRUNNING, LUA_GCRESTART, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL, LUA_GCSTEP,
|
||||
LUA_GCSTOP, LUA_HOOKCALL, LUA_HOOKCOUNT, LUA_HOOKLINE, LUA_HOOKRET, LUA_HOOKTAILCALL,
|
||||
LUA_MASKCALL, LUA_MASKCOUNT, LUA_MASKLINE, LUA_MASKRET, LUA_MINSTACK, LUA_MULTRET, LUA_OK,
|
||||
LUA_OPADD, LUA_OPBAND, LUA_OPBNOT, LUA_OPBOR, LUA_OPBXOR, LUA_OPDIV, LUA_OPEQ, LUA_OPIDIV,
|
||||
LUA_OPLE, LUA_OPLT, LUA_OPMOD, LUA_OPMUL, LUA_OPPOW, LUA_OPSHL, LUA_OPSHR, LUA_OPSUB,
|
||||
LUA_OPUNM, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS, LUA_RIDX_MAINTHREAD, LUA_TBOOLEAN,
|
||||
LUA_TFUNCTION, LUA_TLIGHTUSERDATA, LUA_TNIL, LUA_TNONE, LUA_TNUMBER, LUA_TSTRING, LUA_TTABLE,
|
||||
LUA_TTHREAD, LUA_TUSERDATA, LUA_YIELD,
|
||||
};
|
||||
|
||||
// constants from lauxlib.h
|
||||
pub use self::lauxlib::{
|
||||
LUA_REFNIL, LUA_NOREF,
|
||||
LUA_ERRFILE,
|
||||
LUA_FILEHANDLE
|
||||
};
|
||||
pub use self::lauxlib::{LUA_ERRFILE, LUA_FILEHANDLE, LUA_NOREF, LUA_REFNIL};
|
||||
|
||||
// constants from lualib.h
|
||||
pub use self::lualib::{
|
||||
LUA_COLIBNAME, LUA_TABLIBNAME, LUA_IOLIBNAME, LUA_OSLIBNAME, LUA_STRLIBNAME,
|
||||
LUA_UTF8LIBNAME, LUA_BITLIBNAME, LUA_MATHLIBNAME, LUA_DBLIBNAME, LUA_LOADLIBNAME
|
||||
LUA_BITLIBNAME, LUA_COLIBNAME, LUA_DBLIBNAME, LUA_IOLIBNAME, LUA_LOADLIBNAME, LUA_MATHLIBNAME,
|
||||
LUA_OSLIBNAME, LUA_STRLIBNAME, LUA_TABLIBNAME, LUA_UTF8LIBNAME,
|
||||
};
|
||||
|
||||
// Not actually defined in lua.h / luaconf.h
|
||||
|
@ -304,7 +212,7 @@ mod glue {
|
|||
include!(concat!(env!("OUT_DIR"), "/glue.rs"));
|
||||
}
|
||||
|
||||
mod luaconf;
|
||||
mod lua;
|
||||
mod lauxlib;
|
||||
mod lua;
|
||||
mod luaconf;
|
||||
mod lualib;
|
||||
|
|
|
@ -62,7 +62,7 @@ pub use crate::ffi::lua_State;
|
|||
|
||||
pub use crate::error::{Error, ExternalError, ExternalResult, Result};
|
||||
pub use crate::function::Function;
|
||||
pub use crate::lua::{Lua, Chunk};
|
||||
pub use crate::lua::{Chunk, Lua};
|
||||
pub use crate::multi::Variadic;
|
||||
pub use crate::scope::Scope;
|
||||
pub use crate::string::String;
|
||||
|
|
28
src/lua.rs
28
src/lua.rs
|
@ -18,10 +18,9 @@ use crate::types::{Callback, Integer, LightUserData, LuaRef, Number, RegistryKey
|
|||
use crate::userdata::{AnyUserData, MetaMethod, UserData, UserDataMethods};
|
||||
use crate::util::{
|
||||
assert_stack, callback_error, check_stack, get_userdata, get_wrapped_error,
|
||||
init_error_registry, init_userdata_metatable, main_state, pop_error,
|
||||
protect_lua, protect_lua_closure, safe_pcall, safe_xpcall,
|
||||
push_string, push_userdata, push_wrapped_error, StackGuard,
|
||||
userdata_destructor,
|
||||
init_error_registry, init_userdata_metatable, main_state, pop_error, protect_lua,
|
||||
protect_lua_closure, push_string, push_userdata, push_wrapped_error, safe_pcall, safe_xpcall,
|
||||
userdata_destructor, StackGuard,
|
||||
};
|
||||
use crate::value::{FromLua, FromLuaMulti, MultiValue, Nil, ToLua, ToLuaMulti, Value};
|
||||
|
||||
|
@ -101,7 +100,10 @@ impl Lua {
|
|||
ref_free: Vec::new(),
|
||||
}));
|
||||
|
||||
rlua_debug_assert!(ffi::lua_gettop(state) == state_top, "stack leak during creation");
|
||||
rlua_debug_assert!(
|
||||
ffi::lua_gettop(state) == state_top,
|
||||
"stack leak during creation"
|
||||
);
|
||||
assert_stack(state, ffi::LUA_MINSTACK);
|
||||
|
||||
// Place pointer to ExtraData in the lua_State "extra space"
|
||||
|
@ -207,7 +209,7 @@ impl Lua {
|
|||
&'lua self,
|
||||
source: &[u8],
|
||||
name: Option<&CString>,
|
||||
env: Option<Value<'lua>>
|
||||
env: Option<Value<'lua>>,
|
||||
) -> Result<Function<'lua>> {
|
||||
unsafe {
|
||||
let _sg = StackGuard::new(self.state);
|
||||
|
@ -564,11 +566,7 @@ impl Lua {
|
|||
///
|
||||
/// This value will be available to rust from all `Lua` instances which share the same main
|
||||
/// state.
|
||||
pub fn set_named_registry_value<'lua, S, T>(
|
||||
&'lua self,
|
||||
name: &S,
|
||||
t: T,
|
||||
) -> Result<()>
|
||||
pub fn set_named_registry_value<'lua, S, T>(&'lua self, name: &S, t: T) -> Result<()>
|
||||
where
|
||||
S: ?Sized + AsRef<[u8]>,
|
||||
T: ToLua<'lua>,
|
||||
|
@ -957,7 +955,7 @@ impl Lua {
|
|||
) -> Result<Function<'lua>> {
|
||||
unsafe extern "C" fn call_callback(state: *mut ffi::lua_State) -> c_int {
|
||||
callback_error(state, |nargs| {
|
||||
if ffi::lua_type(state, ffi::lua_upvalueindex(1)) == ffi::LUA_TNIL {
|
||||
if ffi::lua_type(state, ffi::lua_upvalueindex(1)) == ffi::LUA_TNIL {
|
||||
return Err(Error::CallbackDestructed);
|
||||
}
|
||||
|
||||
|
@ -1109,7 +1107,8 @@ impl<'lua, 'a> Chunk<'lua, 'a> {
|
|||
let mut expression_source = b"return ".to_vec();
|
||||
expression_source.extend(self.source);
|
||||
if let Ok(function) =
|
||||
self.lua.load_chunk(&expression_source, self.name.as_ref(), self.env.clone())
|
||||
self.lua
|
||||
.load_chunk(&expression_source, self.name.as_ref(), self.env.clone())
|
||||
{
|
||||
function.call(())
|
||||
} else {
|
||||
|
@ -1128,7 +1127,8 @@ impl<'lua, 'a> Chunk<'lua, 'a> {
|
|||
///
|
||||
/// This simply compiles the chunk without actually executing it.
|
||||
pub fn into_function(self) -> Result<Function<'lua>> {
|
||||
self.lua.load_chunk(self.source, self.name.as_ref(), self.env)
|
||||
self.lua
|
||||
.load_chunk(self.source, self.name.as_ref(), self.env)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
//! Re-exports most types with an extra `Lua*` prefix to prevent name clashes.
|
||||
|
||||
pub use crate::{
|
||||
AnyUserData as LuaAnyUserData, Chunk as LuaChunk,
|
||||
Error as LuaError, ExternalError as LuaExternalError, ExternalResult as LuaExternalResult,
|
||||
FromLua, FromLuaMulti, Function as LuaFunction,
|
||||
Integer as LuaInteger, LightUserData as LuaLightUserData, Lua, MetaMethod as LuaMetaMethod,
|
||||
MultiValue as LuaMultiValue, Nil as LuaNil, Number as LuaNumber, RegistryKey as LuaRegistryKey,
|
||||
Result as LuaResult, Scope as LuaScope, String as LuaString, Table as LuaTable,
|
||||
TablePairs as LuaTablePairs, TableSequence as LuaTableSequence, Thread as LuaThread,
|
||||
ThreadStatus as LuaThreadStatus, ToLua, ToLuaMulti, UserData as LuaUserData,
|
||||
UserDataMethods as LuaUserDataMethods, Value as LuaValue,
|
||||
AnyUserData as LuaAnyUserData, Chunk as LuaChunk, Error as LuaError,
|
||||
ExternalError as LuaExternalError, ExternalResult as LuaExternalResult, FromLua, FromLuaMulti,
|
||||
Function as LuaFunction, Integer as LuaInteger, LightUserData as LuaLightUserData, Lua,
|
||||
MetaMethod as LuaMetaMethod, MultiValue as LuaMultiValue, Nil as LuaNil, Number as LuaNumber,
|
||||
RegistryKey as LuaRegistryKey, Result as LuaResult, Scope as LuaScope, String as LuaString,
|
||||
Table as LuaTable, TablePairs as LuaTablePairs, TableSequence as LuaTableSequence,
|
||||
Thread as LuaThread, ThreadStatus as LuaThreadStatus, ToLua, ToLuaMulti,
|
||||
UserData as LuaUserData, UserDataMethods as LuaUserDataMethods, Value as LuaValue,
|
||||
};
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
use std::any::Any;
|
||||
use std::cell::Cell;
|
||||
use std::cell::RefCell;
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
use std::os::raw::c_void;
|
||||
use std::rc::Rc;
|
||||
use std::cell::Cell;
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use crate::lua::Lua;
|
||||
use crate::ffi;
|
||||
use crate::function::Function;
|
||||
use crate::lua::Lua;
|
||||
use crate::types::{Callback, LuaRef};
|
||||
use crate::userdata::{AnyUserData, MetaMethod, UserData, UserDataMethods};
|
||||
use crate::util::{
|
||||
|
|
|
@ -13,7 +13,8 @@ fn test_function() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let concat = globals.get::<_, Function>("concat").unwrap();
|
||||
assert_eq!(concat.call::<_, String>(("foo", "bar")).unwrap(), "foobar");
|
||||
|
@ -34,7 +35,8 @@ fn test_bind() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut concat = globals.get::<_, Function>("concat").unwrap();
|
||||
concat = concat.bind("foo").unwrap();
|
||||
|
@ -60,7 +62,8 @@ fn test_rust_function() {
|
|||
return 1
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let lua_function = globals.get::<_, Function>("lua_function").unwrap();
|
||||
let rust_function = lua.create_function(|_, ()| Ok("hello")).unwrap();
|
||||
|
|
|
@ -16,7 +16,8 @@ fn scope_func() {
|
|||
.create_function(move |_, ()| {
|
||||
r.set(42);
|
||||
Ok(())
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
lua.globals().set("bad", f.clone()).unwrap();
|
||||
f.call::<_, ()>(()).unwrap();
|
||||
assert_eq!(Rc::strong_count(&rc), 2);
|
||||
|
@ -55,7 +56,8 @@ fn scope_drop() {
|
|||
scope
|
||||
.create_static_userdata(MyUserdata(rc.clone()))
|
||||
.unwrap(),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(Rc::strong_count(&rc), 2);
|
||||
});
|
||||
assert_eq!(Rc::strong_count(&rc), 1);
|
||||
|
@ -76,7 +78,8 @@ fn scope_capture() {
|
|||
.create_function_mut(|_, ()| {
|
||||
i = 42;
|
||||
Ok(())
|
||||
}).unwrap()
|
||||
})
|
||||
.unwrap()
|
||||
.call::<_, ()>(())
|
||||
.unwrap();
|
||||
});
|
||||
|
@ -92,7 +95,8 @@ fn outer_lua_access() {
|
|||
.create_function_mut(|_, ()| {
|
||||
table.set("a", "b").unwrap();
|
||||
Ok(())
|
||||
}).unwrap()
|
||||
})
|
||||
.unwrap()
|
||||
.call::<_, ()>(())
|
||||
.unwrap();
|
||||
});
|
||||
|
@ -132,7 +136,8 @@ fn scope_userdata_methods() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
f.call::<_, ()>(scope.create_nonstatic_userdata(MyUserData(&i)).unwrap())
|
||||
.unwrap();
|
||||
|
@ -172,7 +177,8 @@ fn scope_userdata_functions() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let dummy = 0;
|
||||
lua.scope(|scope| {
|
||||
|
@ -209,7 +215,8 @@ fn scope_userdata_mismatch() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let a = Cell::new(1);
|
||||
let b = Cell::new(1);
|
||||
|
|
|
@ -37,7 +37,8 @@ fn string_views() {
|
|||
empty = ""
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let globals = lua.globals();
|
||||
let ok: String = globals.get("ok").unwrap();
|
||||
|
|
|
@ -34,7 +34,8 @@ fn test_table() {
|
|||
table3 = {1, 2, nil, 4, 5}
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let table1 = globals.get::<_, Table>("table1").unwrap();
|
||||
let table2 = globals.get::<_, Table>("table2").unwrap();
|
||||
|
@ -88,7 +89,8 @@ fn test_table() {
|
|||
.set(
|
||||
"table4",
|
||||
lua.create_sequence_from(vec![1, 2, 3, 4, 5]).unwrap(),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
let table4 = globals.get::<_, Table>("table4").unwrap();
|
||||
assert_eq!(
|
||||
table4.pairs().collect::<Result<Vec<(i64, i64)>>>().unwrap(),
|
||||
|
@ -107,7 +109,8 @@ fn test_table_scope() {
|
|||
}
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Make sure that table gets do not borrow the table, but instead just borrow lua.
|
||||
let tin;
|
||||
|
@ -131,7 +134,8 @@ fn test_metatable() {
|
|||
.set(
|
||||
"__index",
|
||||
lua.create_function(|_, ()| Ok("index_value")).unwrap(),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
table.set_metatable(Some(metatable));
|
||||
assert_eq!(table.get::<_, String>("any_key").unwrap(), "index_value");
|
||||
match table.raw_get::<_, Value>("any_key").unwrap() {
|
||||
|
@ -165,7 +169,8 @@ fn test_table_error() {
|
|||
})
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let bad_table: Table = globals.get("table").unwrap();
|
||||
assert!(bad_table.set(1, 1).is_err());
|
||||
|
|
|
@ -44,7 +44,8 @@ fn test_exec() {
|
|||
res = 'foo'..'bar'
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(globals.get::<_, String>("res").unwrap(), "foobar");
|
||||
|
||||
let module: Table = lua
|
||||
|
@ -59,7 +60,8 @@ fn test_exec() {
|
|||
return module
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
assert!(module.contains_key("func").unwrap());
|
||||
assert_eq!(
|
||||
module
|
||||
|
@ -104,7 +106,8 @@ fn test_lua_multi() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let concat = globals.get::<_, Function>("concat").unwrap();
|
||||
let mreturn = globals.get::<_, Function>("mreturn").unwrap();
|
||||
|
@ -128,7 +131,8 @@ fn test_coercion() {
|
|||
num = 123.0
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(globals.get::<_, String>("int").unwrap(), "123");
|
||||
assert_eq!(globals.get::<_, i32>("str").unwrap(), 123);
|
||||
|
@ -209,7 +213,8 @@ fn test_error() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let rust_error_function = lua
|
||||
.create_function(|_, ()| -> Result<()> { Err(TestError.to_lua_err()) })
|
||||
|
@ -329,7 +334,8 @@ fn test_result_conversions() {
|
|||
Ok(Err::<String, _>(
|
||||
err_msg("only through failure can we succeed").to_lua_err(),
|
||||
))
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
let ok = lua
|
||||
.create_function(|_, ()| Ok(Ok::<_, Error>("!".to_owned())))
|
||||
.unwrap();
|
||||
|
@ -348,7 +354,8 @@ fn test_result_conversions() {
|
|||
assert(e == nil)
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -443,7 +450,8 @@ fn test_pcall_xpcall() {
|
|||
xpcall_status, _ = xpcall(error, function(err) xpcall_error = err end, "testerror")
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(globals.get::<_, bool>("pcall_status").unwrap(), false);
|
||||
assert_eq!(
|
||||
|
@ -465,7 +473,8 @@ fn test_pcall_xpcall() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
let _ = globals
|
||||
.get::<_, Function>("xpcall_recursion")
|
||||
.unwrap()
|
||||
|
@ -521,7 +530,8 @@ fn test_set_metatable_nil() {
|
|||
setmetatable(a, nil)
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -556,7 +566,8 @@ fn test_named_registry_value() {
|
|||
.create_function(move |lua, ()| {
|
||||
assert_eq!(lua.named_registry_value::<i32>("test")?, 42);
|
||||
Ok(())
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
f.call::<_, ()>(()).unwrap();
|
||||
|
||||
|
@ -581,7 +592,8 @@ fn test_registry_value() {
|
|||
panic!();
|
||||
}
|
||||
Ok(())
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
f.call::<_, ()>(()).unwrap();
|
||||
}
|
||||
|
@ -660,13 +672,12 @@ fn too_many_arguments() {
|
|||
let lua = Lua::new();
|
||||
lua.exec::<_, ()>("function test(...) end", None).unwrap();
|
||||
let args = Variadic::from_iter(1..1000000);
|
||||
assert!(
|
||||
lua.globals()
|
||||
.get::<_, Function>("test")
|
||||
.unwrap()
|
||||
.call::<_, ()>(args)
|
||||
.is_err()
|
||||
);
|
||||
assert!(lua
|
||||
.globals()
|
||||
.get::<_, Function>("test")
|
||||
.unwrap()
|
||||
.call::<_, ()>(args)
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -678,13 +689,12 @@ fn too_many_recursions() {
|
|||
.unwrap();
|
||||
lua.globals().set("f", f).unwrap();
|
||||
|
||||
assert!(
|
||||
lua.globals()
|
||||
.get::<_, Function>("f")
|
||||
.unwrap()
|
||||
.call::<_, ()>(())
|
||||
.is_err()
|
||||
);
|
||||
assert!(lua
|
||||
.globals()
|
||||
.get::<_, Function>("f")
|
||||
.unwrap()
|
||||
.call::<_, ()>(())
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -697,15 +707,14 @@ fn too_many_binds() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let concat = globals.get::<_, Function>("f").unwrap();
|
||||
assert!(concat.bind(Variadic::from_iter(1..1000000)).is_err());
|
||||
assert!(
|
||||
concat
|
||||
.call::<_, ()>(Variadic::from_iter(1..1000000))
|
||||
.is_err()
|
||||
);
|
||||
assert!(concat
|
||||
.call::<_, ()>(Variadic::from_iter(1..1000000))
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -723,8 +732,10 @@ fn large_args() {
|
|||
assert_eq!(i, args[i]);
|
||||
}
|
||||
Ok(s)
|
||||
}).unwrap(),
|
||||
).unwrap();
|
||||
})
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let f: Function = lua
|
||||
.eval(
|
||||
|
@ -734,7 +745,8 @@ fn large_args() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
f.call::<_, usize>((0..100).collect::<Variadic<usize>>())
|
||||
|
@ -753,7 +765,8 @@ fn large_args_ref() {
|
|||
assert_eq!(args[i], i.to_string());
|
||||
}
|
||||
Ok(())
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
f.call::<_, ()>((0..100).map(|i| i.to_string()).collect::<Variadic<_>>())
|
||||
.unwrap();
|
||||
|
|
|
@ -20,8 +20,10 @@ fn test_thread() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap(),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(thread.status(), ThreadStatus::Resumable);
|
||||
assert_eq!(thread.resume::<_, i64>(0).unwrap(), 0);
|
||||
|
@ -46,8 +48,10 @@ fn test_thread() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap(),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
for i in 0..4 {
|
||||
accumulate.resume::<_, ()>(i).unwrap();
|
||||
|
@ -67,7 +71,8 @@ fn test_thread() {
|
|||
end)
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(thread.status(), ThreadStatus::Resumable);
|
||||
assert_eq!(thread.resume::<_, i64>(()).unwrap(), 42);
|
||||
|
||||
|
@ -82,7 +87,8 @@ fn test_thread() {
|
|||
end)
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(thread.resume::<_, u32>(42).unwrap(), 123);
|
||||
assert_eq!(thread.resume::<_, u32>(43).unwrap(), 987);
|
||||
|
|
|
@ -15,7 +15,8 @@ fn test_lightuserdata() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
let res = globals
|
||||
.get::<_, Function>("id")
|
||||
.unwrap()
|
||||
|
|
|
@ -57,7 +57,8 @@ fn test_methods() {
|
|||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
let get = globals.get::<_, Function>("get_it").unwrap();
|
||||
let set = globals.get::<_, Function>("set_it").unwrap();
|
||||
assert_eq!(get.call::<_, i64>(()).unwrap(), 42);
|
||||
|
@ -135,8 +136,8 @@ fn test_gc_userdata() {
|
|||
globals.set("userdata", MyUserdata { id: 123 }).unwrap();
|
||||
}
|
||||
|
||||
assert!(
|
||||
lua.eval::<_, ()>(
|
||||
assert!(lua
|
||||
.eval::<_, ()>(
|
||||
r#"
|
||||
local tbl = setmetatable({
|
||||
userdata = userdata
|
||||
|
@ -151,8 +152,8 @@ fn test_gc_userdata() {
|
|||
hatch:access()
|
||||
"#,
|
||||
None
|
||||
).is_err()
|
||||
);
|
||||
)
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue