mlua_sys/lua53/
compat.rs

1//! MLua compatibility layer for Lua 5.3
2
3use std::os::raw::{c_char, c_int};
4
5use super::lauxlib::*;
6use super::lua::*;
7
8#[inline(always)]
9pub unsafe fn lua_resume(L: *mut lua_State, from: *mut lua_State, narg: c_int, nres: *mut c_int) -> c_int {
10    let ret = lua_resume_(L, from, narg);
11    if (ret == LUA_OK || ret == LUA_YIELD) && !(nres.is_null()) {
12        *nres = lua_gettop(L);
13    }
14    ret
15}
16
17pub unsafe fn luaL_loadbufferenv(
18    L: *mut lua_State,
19    data: *const c_char,
20    size: usize,
21    name: *const c_char,
22    mode: *const c_char,
23    mut env: c_int,
24) -> c_int {
25    if env != 0 {
26        env = lua_absindex(L, env);
27    }
28    let status = luaL_loadbufferx(L, data, size, name, mode);
29    if status == LUA_OK && env != 0 {
30        lua_pushvalue(L, env);
31        lua_setupvalue(L, -2, 1);
32    }
33    status
34}