Debian Codegraph @

CorsixTH/Src/lua.hpp

raw
1 /*
2 Copyright (c) 2009 Peter "Corsix" Cawley
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23 #ifndef CORSIX_TH_LUA_HPP_
24 #define CORSIX_TH_LUA_HPP_
25
26 extern "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
41 inline size_t lua_objlen(lua_State* L, int idx) { return lua_rawlen(L, idx); }
42 #endif
43
44 #ifndef lua_equal
45 inline 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
51 inline 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
58 int luaT_setfenv52(lua_State*, int);
59 inline int lua_setfenv(lua_State* L, int n) { return luaT_setfenv52(L, n); }
60 #endif
61
62 #ifndef lua_getfenv
63 void luaT_getfenv52(lua_State*, int);
64 inline 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_