Skip to content

Commit d799513

Browse files
committed
Add debug API to ffi (not used yet, was using experimentally)
Also fix for cstr! macro
1 parent 8824a23 commit d799513

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/ffi.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use std::ptr;
66
use std::mem;
7-
use std::os::raw::{c_char, c_double, c_int, c_longlong, c_void};
7+
use std::os::raw::{c_char, c_double, c_int, c_longlong, c_uchar, c_void};
88

99
pub type lua_Integer = c_longlong;
1010
pub type lua_Number = c_double;
@@ -18,6 +18,24 @@ pub type lua_KFunction =
1818
unsafe extern "C" fn(state: *mut lua_State, status: c_int, ctx: lua_KContext) -> c_int;
1919
pub type lua_CFunction = unsafe extern "C" fn(state: *mut lua_State) -> c_int;
2020

21+
#[repr(C)]
22+
pub struct lua_Debug {
23+
pub event: c_int,
24+
pub name: *const c_char,
25+
pub namewhat: *const c_char,
26+
pub what: *const c_char,
27+
pub source: *const c_char,
28+
pub currentline: c_int,
29+
pub linedefined: c_int,
30+
pub lastlinedefined: c_int,
31+
pub nups: c_uchar,
32+
pub nparams: c_uchar,
33+
pub isvararg: c_char,
34+
pub istailcall: c_char,
35+
pub short_src: [c_char; LUA_IDSIZE as usize],
36+
i_ci: *mut c_void,
37+
}
38+
2139
pub const LUA_OK: c_int = 0;
2240
pub const LUA_YIELD: c_int = 1;
2341
pub const LUA_ERRRUN: c_int = 2;
@@ -34,6 +52,7 @@ pub const LUAI_MAXSTACK: c_int = 1_000_000;
3452
pub const LUA_REGISTRYINDEX: c_int = -LUAI_MAXSTACK - 1000;
3553
pub const LUA_RIDX_MAINTHREAD: lua_Integer = 1;
3654
pub const LUA_RIDX_GLOBALS: lua_Integer = 2;
55+
pub const LUA_IDSIZE: c_int = 60;
3756
// Not actually defined in lua.h / luaconf.h
3857
pub const LUA_MAX_UPVALUES: c_int = 255;
3958

@@ -141,6 +160,7 @@ extern "C" {
141160
pub fn lua_error(state: *mut lua_State) -> !;
142161
pub fn lua_atpanic(state: *mut lua_State, panic: lua_CFunction) -> lua_CFunction;
143162
pub fn lua_gc(state: *mut lua_State, what: c_int, data: c_int) -> c_int;
163+
pub fn lua_getinfo(state: *mut lua_State, what: *const c_char, ar: *mut lua_Debug) -> c_int;
144164

145165
pub fn luaopen_base(state: *mut lua_State) -> c_int;
146166
pub fn luaopen_coroutine(state: *mut lua_State) -> c_int;

src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
macro_rules! cstr {
22
($s:expr) => (
3-
concat!($s, "\0") as *const str as *const [c_char] as *const c_char
3+
concat!($s, "\0") as *const str as *const [::std::os::raw::c_char] as *const ::std::os::raw::c_char
44
);
55
}
66

0 commit comments

Comments
 (0)