summaryrefslogtreecommitdiff
path: root/src/ffi/lauxlib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ffi/lauxlib.rs')
-rw-r--r--src/ffi/lauxlib.rs90
1 files changed, 46 insertions, 44 deletions
diff --git a/src/ffi/lauxlib.rs b/src/ffi/lauxlib.rs
index 5a9c5c8..941755f 100644
--- a/src/ffi/lauxlib.rs
+++ b/src/ffi/lauxlib.rs
@@ -1,5 +1,6 @@
// The MIT License (MIT)
//
+// Copyright (c) 2019 A. Orlenko
// Copyright (c) 2014 J.C. Moyer
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -26,10 +27,16 @@ use std::os::raw::{c_char, c_int, c_long, c_void};
use std::ptr;
use super::lua::{self, lua_CFunction, lua_Integer, lua_Number, lua_State};
-use super::luaconf::LUAL_BUFFERSIZE;
+#[cfg(feature = "lua53")]
pub use super::glue::LUAL_NUMSIZES;
-pub use super::glue::LUA_FILEHANDLE;
+
+#[cfg(not(feature = "lua53"))]
+pub use super::compat53::{
+ luaL_checkversion, luaL_getmetafield, luaL_getsubtable, luaL_len, luaL_loadbufferx,
+ luaL_newmetatable, luaL_requiref, luaL_setfuncs, luaL_setmetatable, luaL_testudata,
+ luaL_tolstring, luaL_traceback,
+};
// extra error code for 'luaL_load'
pub const LUA_ERRFILE: c_int = lua::LUA_ERRERR + 1;
@@ -40,6 +47,7 @@ pub struct luaL_Reg {
pub func: lua_CFunction,
}
+#[cfg(feature = "lua53")]
#[inline(always)]
pub unsafe fn luaL_checkversion(L: *mut lua_State) {
luaL_checkversion_(
@@ -50,10 +58,17 @@ pub unsafe fn luaL_checkversion(L: *mut lua_State) {
}
extern "C" {
+ #[cfg(feature = "lua53")]
pub fn luaL_checkversion_(L: *mut lua_State, ver: lua_Number, sz: usize);
+ #[cfg(feature = "lua53")]
pub fn luaL_getmetafield(L: *mut lua_State, obj: c_int, e: *const c_char) -> c_int;
+ #[cfg(not(feature = "lua53"))]
+ #[link_name = "luaL_getmetafield"]
+ pub fn luaL_getmetafield_51(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;
+ #[cfg(feature = "lua53")]
pub fn luaL_tolstring(L: *mut lua_State, idx: c_int, len: *mut usize) -> *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 usize) -> *const c_char;
@@ -72,13 +87,20 @@ extern "C" {
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);
+ #[cfg(feature = "lua53")]
pub fn luaL_newmetatable(L: *mut lua_State, tname: *const c_char) -> c_int;
+ #[cfg(not(feature = "lua53"))]
+ #[link_name = "luaL_newmetatable"]
+ pub fn luaL_newmetatable_51(L: *mut lua_State, tname: *const c_char) -> c_int;
+
+ #[cfg(feature = "lua53")]
pub fn luaL_setmetatable(L: *mut lua_State, tname: *const c_char);
+ #[cfg(feature = "lua53")]
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_error(L: *mut lua_State, fmt: *const c_char, ...) -> !;
// TODO: test this
pub fn luaL_checkoption(
@@ -88,7 +110,9 @@ extern "C" {
lst: *const *const c_char,
) -> c_int;
+ #[cfg(feature = "lua53")]
pub fn luaL_fileresult(L: *mut lua_State, stat: c_int, fname: *const c_char) -> c_int;
+ #[cfg(feature = "lua53")]
pub fn luaL_execresult(L: *mut lua_State, stat: c_int) -> c_int;
}
@@ -100,16 +124,21 @@ 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);
+ #[cfg(feature = "lua53")]
pub fn luaL_loadfilex(L: *mut lua_State, filename: *const c_char, mode: *const c_char)
-> c_int;
+ #[cfg(not(feature = "lua53"))]
+ pub fn luaL_loadfile(L: *mut lua_State, filename: *const c_char) -> c_int;
}
+#[cfg(feature = "lua53")]
#[inline(always)]
pub unsafe fn luaL_loadfile(L: *mut lua_State, f: *const c_char) -> c_int {
luaL_loadfilex(L, f, ptr::null())
}
extern "C" {
+ #[cfg(feature = "lua53")]
pub fn luaL_loadbufferx(
L: *mut lua_State,
buff: *const c_char,
@@ -117,10 +146,18 @@ extern "C" {
name: *const c_char,
mode: *const c_char,
) -> c_int;
+ #[cfg(not(feature = "lua53"))]
+ pub fn luaL_loadbuffer(
+ L: *mut lua_State,
+ buff: *const c_char,
+ sz: usize,
+ name: *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;
+ #[cfg(feature = "lua53")]
pub fn luaL_len(L: *mut lua_State, idx: c_int) -> lua_Integer;
pub fn luaL_gsub(
@@ -130,12 +167,16 @@ extern "C" {
r: *const c_char,
) -> *const c_char;
+ #[cfg(feature = "lua53")]
pub fn luaL_setfuncs(L: *mut lua_State, l: *const luaL_Reg, nup: c_int);
+ #[cfg(feature = "lua53")]
pub fn luaL_getsubtable(L: *mut lua_State, idx: c_int, fname: *const c_char) -> c_int;
+ #[cfg(feature = "lua53")]
pub fn luaL_traceback(L: *mut lua_State, L1: *mut lua_State, msg: *const c_char, level: c_int);
+ #[cfg(feature = "lua53")]
pub fn luaL_requiref(
L: *mut lua_State,
modname: *const c_char,
@@ -238,6 +279,7 @@ pub unsafe fn luaL_getmetatable(L: *mut lua_State, n: *const c_char) {
// luaL_opt would be implemented here but it is undocumented, so it's omitted
+#[cfg(feature = "lua53")]
#[inline(always)]
pub unsafe fn luaL_loadbuffer(
L: *mut lua_State,
@@ -248,46 +290,6 @@ pub unsafe fn luaL_loadbuffer(
luaL_loadbufferx(L, s, sz, n, ptr::null())
}
-#[repr(C)]
-pub struct luaL_Buffer {
- pub b: *mut c_char,
- pub size: usize,
- pub n: usize,
- 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;
-}
-
-#[inline(always)]
-pub unsafe fn luaL_addsize(B: *mut luaL_Buffer, s: usize) {
- (*B).n += s;
-}
-
-extern "C" {
- pub fn luaL_buffinit(L: *mut lua_State, B: *mut luaL_Buffer);
- pub fn luaL_prepbuffsize(B: *mut luaL_Buffer, sz: usize) -> *mut c_char;
- pub fn luaL_addlstring(B: *mut luaL_Buffer, s: *const c_char, l: usize);
- 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: usize);
- pub fn luaL_buffinitsize(L: *mut lua_State, B: *mut luaL_Buffer, sz: usize) -> *mut c_char;
-}
-
-pub unsafe fn luaL_prepbuffer(B: *mut luaL_Buffer) -> *mut c_char {
- luaL_prepbuffsize(B, LUAL_BUFFERSIZE as usize)
-}
+// TODO: Add buffer API
// omitted: old module system compatibility