aboutsummaryrefslogtreecommitdiff
path: root/src/macros_and_utils.h
diff options
context:
space:
mode:
authorBenoit Germain <b n t DOT g e r m a i n AT g m a i l DOT c o m>2017-08-01 09:40:44 +0200
committerBenoit Germain <b n t DOT g e r m a i n AT g m a i l DOT c o m>2017-08-01 09:40:44 +0200
commite0dbd33c2d4776d6b2213dd82f344166eafde438 (patch)
treebab4483f9f5b0d802bdbfc8641fe44ff9649382f /src/macros_and_utils.h
parentfcd08030b6b6af81a8aa2672082a55f602006f78 (diff)
downloadlanes-e0dbd33c2d4776d6b2213dd82f344166eafde438.tar.gz
lanes-e0dbd33c2d4776d6b2213dd82f344166eafde438.tar.bz2
lanes-e0dbd33c2d4776d6b2213dd82f344166eafde438.zip
Fix for deep-aware modules
Don't crash when using a module that creates Lanes-compatible deep userdata. Added a sample deep-aware module.
Diffstat (limited to 'src/macros_and_utils.h')
-rw-r--r--src/macros_and_utils.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h
new file mode 100644
index 0000000..d584c2b
--- /dev/null
+++ b/src/macros_and_utils.h
@@ -0,0 +1,71 @@
1/*
2 * MACROS_AND_UTILS.H
3 */
4#ifndef MACROS_AND_UTILS_H
5#define MACROS_AND_UTILS_H
6
7#include "lua.h"
8
9 // M$ compiler doesn't support 'inline' keyword in C files...
10#if defined( _MSC_VER)
11#define inline __inline
12#endif
13
14 // For some reason, LuaJIT 64bits doesn't support lua_newstate()
15#if defined(LUA_JITLIBNAME) && (defined(__x86_64__) || defined(_M_X64))
16 //#pragma message( "LuaJIT 64 bits detected: don't propagate allocf")
17#define PROPAGATE_ALLOCF 0
18#else // LuaJIT x64
19 //#pragma message( "PUC-Lua detected: propagate allocf")
20#define PROPAGATE_ALLOCF 1
21#endif // LuaJIT x64
22#if PROPAGATE_ALLOCF
23#define PROPAGATE_ALLOCF_PREP( L) void* allocUD; lua_Alloc allocF = lua_getallocf( L, &allocUD)
24#define PROPAGATE_ALLOCF_ALLOC() lua_newstate( allocF, allocUD)
25#else // PROPAGATE_ALLOCF
26#define PROPAGATE_ALLOCF_PREP( L)
27#define PROPAGATE_ALLOCF_ALLOC() luaL_newstate()
28#endif // PROPAGATE_ALLOCF
29
30#define USE_DEBUG_SPEW 0
31#if USE_DEBUG_SPEW
32extern char const* debugspew_indent;
33#define INDENT_BEGIN "%.*s "
34#define INDENT_END , (U ? U->debugspew_indent_depth : 0), debugspew_indent
35#define DEBUGSPEW_CODE(_code) _code
36#else // USE_DEBUG_SPEW
37#define DEBUGSPEW_CODE(_code)
38#endif // USE_DEBUG_SPEW
39
40#ifdef NDEBUG
41
42#define _ASSERT_L(lua,c) /*nothing*/
43#define STACK_CHECK(L) /*nothing*/
44#define STACK_MID(L,c) /*nothing*/
45#define STACK_END(L,c) /*nothing*/
46#define STACK_DUMP(L) /*nothing*/
47
48#else // NDEBUG
49
50#define _ASSERT_L( L, cond_) if( (cond_) == 0) { (void) luaL_error( L, "ASSERT failed: %s:%d '%s'", __FILE__, __LINE__, #cond_);}
51
52#define STACK_CHECK(L) { int const _oldtop_##L = lua_gettop( L)
53#define STACK_MID(L,change) \
54 do \
55 { \
56 int a = lua_gettop( L) - _oldtop_##L; \
57 int b = (change); \
58 if( a != b) \
59 luaL_error( L, "STACK ASSERT failed (%d not %d): %s:%d", a, b, __FILE__, __LINE__ ); \
60 } while( 0)
61#define STACK_END(L,change) STACK_MID(L,change); }
62
63#define STACK_DUMP( L) luaG_dump( L)
64
65#endif // NDEBUG
66
67#define ASSERT_L(c) _ASSERT_L(L,c)
68
69#define STACK_GROW( L, n) do { if (!lua_checkstack(L,(int)(n))) luaL_error( L, "Cannot grow stack!" ); } while( 0)
70
71#endif // MACROS_AND_UTILS_H