luajit2_sys/
lib.rs

1#![no_std]
2#![allow(non_snake_case)]
3#![allow(non_camel_case_types)]
4
5//! # LuaJIT 2.1
6//!
7//! <http://luajit.org>
8//!
9//! <http://www.lua.org/manual/5.1/manual.html>
10//!
11//! ## Performance considerations
12//!
13//! The _Not Yet Implemented_ guide documents which language features will be JIT compiled
14//! into native machine code.
15//!
16//! <http://wiki.luajit.org/NYI>
17
18mod ffi;
19pub use ffi::*;
20
21use core::ptr;
22
23// These are defined as macros
24
25/// <https://www.lua.org/manual/5.1/manual.html#lua_pop>
26#[inline]
27pub unsafe fn lua_pop(L: *mut lua_State, idx: libc::c_int) {
28    lua_settop(L, -(idx) - 1)
29}
30
31/// <https://www.lua.org/manual/5.1/manual.html#lua_newtable>
32#[inline]
33pub unsafe fn lua_newtable(L: *mut lua_State) {
34    lua_createtable(L, 0, 0)
35}
36
37/// <https://www.lua.org/manual/5.1/manual.html#lua_register>
38#[inline]
39pub unsafe fn lua_register(L: *mut lua_State, name: *const libc::c_char, f: lua_CFunction) {
40    lua_pushcfunction(L, f);
41    lua_setglobal(L, name);
42}
43
44/// <https://www.lua.org/manual/5.1/manual.html#lua_pushcfunction>
45#[inline]
46pub unsafe fn lua_pushcfunction(L: *mut lua_State, f: lua_CFunction) {
47    lua_pushcclosure(L, f, 0);
48}
49
50/// <https://www.lua.org/manual/5.1/manual.html#lua_strlen>
51#[inline]
52pub unsafe fn lua_strlen(L: *mut lua_State, idx: libc::c_int) -> usize {
53    lua_objlen(L, idx)
54}
55
56/// <https://www.lua.org/manual/5.1/manual.html#lua_isfunction>
57#[inline]
58pub unsafe fn lua_isfunction(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
59    (lua_type(L, idx) == LUA_TFUNCTION as i32) as i32
60}
61
62/// <https://www.lua.org/manual/5.1/manual.html#lua_istable>
63#[inline]
64pub unsafe fn lua_istable(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
65    (lua_type(L, idx) == LUA_TTABLE as i32) as i32
66}
67
68/// <https://www.lua.org/manual/5.1/manual.html#lua_islightuserdata>
69#[inline]
70pub unsafe fn lua_islightuserdata(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
71    (lua_type(L, idx) == LUA_TLIGHTUSERDATA as i32) as i32
72}
73
74/// <https://www.lua.org/manual/5.1/manual.html#lua_isnil>
75#[inline]
76pub unsafe fn lua_isnil(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
77    (lua_type(L, idx) == LUA_TNIL as i32) as i32
78}
79
80/// <https://www.lua.org/manual/5.1/manual.html#lua_isboolean>
81#[inline]
82pub unsafe fn lua_isboolean(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
83    (lua_type(L, idx) == LUA_TBOOLEAN as i32) as i32
84}
85
86/// <https://www.lua.org/manual/5.1/manual.html#lua_isthread>
87#[inline]
88pub unsafe fn lua_isthread(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
89    (lua_type(L, idx) == LUA_TTHREAD as i32) as i32
90}
91
92/// <https://www.lua.org/manual/5.1/manual.html#lua_isnone>
93#[inline]
94pub unsafe fn lua_isnone(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
95    (lua_type(L, idx) == LUA_TNONE as i32) as i32
96}
97
98/// <https://www.lua.org/manual/5.1/manual.html#lua_isnoneornil>
99#[inline]
100pub unsafe fn lua_isnoneornil(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
101    (lua_type(L, idx) <= 0) as i32
102}
103
104/// <https://www.lua.org/manual/5.1/manual.html#lua_pushliteral>
105#[inline]
106pub unsafe fn lua_pushliteral(L: *mut lua_State, s: &str) {
107    lua_pushlstring(L, s.as_ptr() as _, s.len() as _);
108}
109
110/// <https://www.lua.org/manual/5.1/manual.html#lua_setglobal>
111#[inline]
112pub unsafe fn lua_setglobal(L: *mut lua_State, k: *const libc::c_char) {
113    lua_setfield(L, LUA_GLOBALSINDEX, k);
114}
115
116/// <https://www.lua.org/manual/5.1/manual.html#lua_getglobal>
117#[inline]
118pub unsafe fn lua_getglobal(L: *mut lua_State, k: *const libc::c_char) {
119    lua_getfield(L, LUA_GLOBALSINDEX, k)
120}
121
122/// <https://www.lua.org/manual/5.1/manual.html#lua_tostring>
123#[inline]
124pub unsafe fn lua_tostring(L: *mut lua_State, idx: libc::c_int) -> *const libc::c_char {
125    lua_tolstring(L, idx, ptr::null_mut())
126}
127
128// Additional compatibility items that are defined as macros
129
130/// `luaL_newstate()`
131#[inline]
132#[deprecated(since = "Lua 5.1", note = "replace with `luaL_newstate()`")]
133pub unsafe fn lua_open() -> *mut lua_State {
134    luaL_newstate()
135}
136
137/// `lua_pushvalue(L, LUA_REGISTRYINDEX)`
138#[inline]
139#[deprecated(
140    since = "Lua 5.1",
141    note = "replace with `lua_pushvalue(L, LUA_REGISTRYINDEX)`"
142)]
143pub unsafe fn lua_getregistry(L: *mut lua_State) {
144    lua_pushvalue(L, LUA_REGISTRYINDEX)
145}
146
147/// `lua_gc(L, LUA_GCCOUNT as _, 0)`
148#[inline]
149#[deprecated(
150    since = "Lua 5.1",
151    note = "replace with `lua_gc(L, LUA_GCCOUNT as _, 0)`"
152)]
153pub unsafe fn lua_getgccount(L: *mut lua_State) -> libc::c_int {
154    lua_gc(L, LUA_GCCOUNT as _, 0)
155}
156
157/// `lua_Reader`
158#[deprecated(since = "Lua 5.1", note = "replace with `lua_Reader`")]
159pub type lua_Chunkreader = lua_Reader;
160
161/// `lua_Writer`
162#[deprecated(since = "Lua 5.1", note = "replace with `lua_Writer`")]
163pub type lua_Chunkwriter = lua_Writer;