headers: updates Lua 5.2 workaround to allow 5.3 version
[luaevent.git] / include / luaevent.h
blob478c1daa8d789d1c055c6f5a2cb02e96ab930f49
1 /* LuaEvent
2 Copyright (C) 2007,2012,2013 Thomas Harning <harningt@gmail.com>
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
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
20 THE SOFTWARE.
23 #ifndef LUAEVENT_H
24 #define LUAEVENT_H
26 #include <lua.h>
28 /* Workarounds for Lua 5.2 and Lua 5.3 */
29 #if (LUA_VERSION_NUM >= 502)
31 #undef lua_equal
32 #define lua_equal(L,idx1,idx2) lua_compare(L, (idx1), (idx2), LUA_OPEQ)
34 #undef lua_getfenv
35 #define lua_getfenv lua_getuservalue
36 #undef lua_setfenv
37 #define lua_setfenv lua_setuservalue
39 #undef lua_objlen
40 #define lua_objlen lua_rawlen
42 #undef luaL_register
43 #define luaL_register(L, n, f) \
44 { if ((n) == NULL) luaL_setfuncs(L, f, 0); else luaL_newlib(L, f); }
46 #endif
48 #include <sys/types.h>
49 #ifdef _WIN32
50 #include <winsock2.h>
51 #else
52 #include <sys/time.h>
53 #endif
54 #include <event.h>
56 typedef struct {
57 struct event_base* base;
58 lua_State* loop_L;
59 int errorMessage;
60 } le_base;
62 le_base* event_base_get(lua_State* L, int idx);
63 void load_timeval(double time, struct timeval *tv);
64 int getSocketFd(lua_State* L, int idx);
66 int luaopen_luaevent_core(lua_State* L);
68 #endif