Skip to content

Commit b05f26a

Browse files
committed
Migrate ltm
1 parent 449bab7 commit b05f26a

File tree

9 files changed

+691
-187
lines changed

9 files changed

+691
-187
lines changed

build/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ fn main() {
2727
.file("build/lstrlib.c")
2828
.file("build/ltable.c")
2929
.file("build/ltablib.c")
30-
.file("build/ltm.c")
3130
.file("build/lua.c")
3231
.file("build/lundump.c")
3332
.file("build/lutf8lib.c")

build/ltm.c

Lines changed: 0 additions & 165 deletions
This file was deleted.

src/ldebug.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use libc::c_char;
2+
3+
use crate::lobject::TValue;
4+
use crate::lstate::lua_State;
5+
6+
extern "C" {
7+
pub fn luaG_concaterror(L: *mut lua_State, p1: *const TValue, p2: *const TValue) -> !;
8+
pub fn luaG_tointerror(L: *mut lua_State, p1: *const TValue, p2: *const TValue) -> !;
9+
pub fn luaG_opinterror(
10+
L: *mut lua_State,
11+
p1: *const TValue,
12+
p2: *const TValue,
13+
msg: *const c_char,
14+
) -> !;
15+
}

src/ldo.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,33 @@
1-
use libc::c_int;
1+
/*
2+
** Stack and Call structure of Lua
3+
*/
4+
5+
use libc::{c_char, c_int, ptrdiff_t};
6+
7+
use crate::lobject::{StkId, TValue};
8+
use crate::lstate::lua_State;
9+
10+
/*
11+
** Macro to check stack size and grow stack if needed. Parameters
12+
** 'pre'/'pos' allow the macro to preserve a pointer into the
13+
** stack across reallocations, doing the work only when needed.
14+
** 'condmovestack' is used in heavy tests to force a stack reallocation
15+
** at every check.
16+
*/
17+
// #define luaD_checkstackaux(L,n,pre,pos) \
18+
// if (L->stack_last - L->top <= (n)) \
19+
// { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); }
20+
21+
/* In general, 'pre'/'pos' are empty (nothing to save) */
22+
// #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0)
23+
24+
pub unsafe fn savestack(L: *mut lua_State, p: *const TValue) -> ptrdiff_t {
25+
(p as *const c_char).offset_from((*L).stack as *const c_char)
26+
}
27+
28+
pub unsafe fn restorestack(L: *mut lua_State, n: ptrdiff_t) -> *mut TValue {
29+
((*L).stack as *mut c_char).offset(n) as *mut TValue
30+
}
231

332
pub type jmp_buf = [libc::c_int; 37];
433

@@ -10,3 +39,8 @@ pub struct lua_longjmp {
1039
pub b: jmp_buf,
1140
pub status: c_int,
1241
}
42+
43+
extern "C" {
44+
pub fn luaD_call(L: *mut lua_State, func: StkId, nResults: c_int);
45+
pub fn luaD_callnoyield(L: *mut lua_State, func: StkId, nResults: c_int);
46+
}

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
non_upper_case_globals
66
)]
77

8+
#[macro_use]
9+
pub(crate) mod lstate;
10+
11+
pub(crate) mod ldebug;
812
pub(crate) mod ldo;
913
pub(crate) mod lfunc;
1014
pub(crate) mod lgc;
1115
pub(crate) mod llimits;
1216
pub(crate) mod lmem;
1317
pub(crate) mod lobject;
1418
pub(crate) mod lopcodes;
15-
pub(crate) mod lstate;
1619
pub(crate) mod ltemp;
1720
pub(crate) mod ltm;
21+
pub(crate) mod lvm;
1822
pub(crate) mod lzio;
1923
pub(crate) mod types;

0 commit comments

Comments
 (0)