CorsixTH engine (the C++ part)
Open source implementation of Theme Hospital
Loading...
Searching...
No Matches
lua.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2009 Peter "Corsix" Cawley
3
4Permission is hereby granted, free of charge, to any person obtaining a copy of
5this software and associated documentation files (the "Software"), to deal in
6the Software without restriction, including without limitation the rights to
7use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8of the Software, and to permit persons to whom the Software is furnished to do
9so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20SOFTWARE.
21*/
22
23#ifndef CORSIX_TH_LUA_HPP_
24#define CORSIX_TH_LUA_HPP_
25
26extern "C" {
27// IWYU pragma: begin_exports
28#include <lauxlib.h>
29#include <lua.h>
30#include <luaconf.h>
31#include <lualib.h>
32// IWYU pragma: end_exports
33}
34
35#if LUA_VERSION_NUM >= 502
36// Quick preprocessor fixes to improve compatibility with Lua 5.2
37// These definitions will already have been made if Lua 5.2 was compiled
38// with LUA_COMPAT_ALL defined, but we have no control over this.
39
40#ifndef lua_objlen
41inline size_t lua_objlen(lua_State* L, int idx) { return lua_rawlen(L, idx); }
42#endif
43
44#ifndef lua_equal
45inline int lua_equal(lua_State* L, int idx1, int idx2) {
46 return lua_compare(L, idx1, idx2, LUA_OPEQ);
47}
48#endif
49
50#ifndef lua_lessthan
51inline int lua_lessthan(lua_State* L, int idx1, int idx2) {
52 return lua_compare(L, idx1, idx2, LUA_OPLT);
53}
54#endif
55
56// Use our own replacements for lua_[sg]etfenv
57#ifndef lua_setfenv
58int luaT_setfenv52(lua_State*, int);
59inline int lua_setfenv(lua_State* L, int n) { return luaT_setfenv52(L, n); }
60#endif
61
62#ifndef lua_getfenv
63void luaT_getfenv52(lua_State*, int);
64inline void lua_getfenv(lua_State* L, int n) { luaT_getfenv52(L, n); }
65#endif
66
67#endif // LUA_VERSION_NUM >= 502
68
69// LUA_OK was added in 5.2, 5.1 just used 0
70#ifndef LUA_OK
71#define LUA_OK 0
72#endif
73
74#endif // CORSIX_TH_LUA_HPP_