Repository navigation
Expand file tree
/
Copy pathlua_cmsgpack.h
More file actions
50 lines (40 loc) · 1.72 KB
/
Copy pathlua_cmsgpack.h
File metadata and controls
50 lines (40 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef LUA_CMSGPACK_MAIN_HEADER_HPP
#define LUA_CMSGPACK_MAIN_HEADER_HPP
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include "lua.h"
#include "lauxlib.h"
#define LUACMSGPACK_VERSION "lua-cmsgpack 0.3.0"
#define LUACMSGPACK_COPYRIGHT "Copyright (C) 2012, Salvatore Sanfilippo"
#define LUACMSGPACK_DESCRIPTION "MessagePack C implementation for Lua"
/* Allows defining as a preprocessor directive on compilation */
#ifndef LUACMSGPACK_MAX_NESTING
# define LUACMSGPACK_MAX_NESTING 16 /* Max tables nesting. */
#endif
/*
* Allows compilation under Lua 5.1 and 5.2 and avoids use of functions which have been deprecated in 5.2.
*/
#if LUA_VERSION_NUM >= 502 /* If higher than Lua 5.2, hopes for compatibility */
# define LUACOMPAT_REGISTER(L,l) luaL_setfuncs(L,l,0)
# define lua_objlen(L, i) lua_rawlen(L, i)
# define LUACOMPAT_PUSH_GLOBAL_ENVIRONMENT(L) lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
#else /* If lower than Lua 5.1, hopes for compatibility */
# define LUACOMPAT_REGISTER(L,l) luaL_register(L,NULL,l)
# define LUACOMPAT_PUSH_GLOBAL_ENVIRONMENT(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
#endif
/*
* Compatibility wrapper to determine whether a float/double x is finite.
*/
#if _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
# define IS_FINITE(x) isfinite(x)
#else
# define IS_FINITE(x) ((x) == (x) && (x) + 1 > (x))
#endif
/* Checks if a float or double value x can be represented as an integer of type T without loss of precision */
#define IS_INT_TYPE_EQUIVALENT(x, T) (IS_FINITE(x) && (T)(x) == (x))
#define IS_INT64_EQUIVALENT(x) IS_INT_TYPE_EQUIVALENT(x, int64_t)
#define IS_INT_EQUIVALENT(x) IS_INT_TYPE_EQUIVALENT(x, int)
#endif // lua_cmsgpack.h