aboutsummaryrefslogtreecommitdiff
path: root/src/tools.h
diff options
context:
space:
mode:
authorPeter Drahoš <drahosp@gmail.com>2010-10-01 03:22:32 +0200
committerPeter Drahoš <drahosp@gmail.com>2010-10-01 03:22:32 +0200
commit89d9c98af1ac352ba4d49d660e61b0853d6e1a86 (patch)
tree15c56d2ce66b4ab147171c0f674cdb4a435ff13f /src/tools.h
downloadlanes-89d9c98af1ac352ba4d49d660e61b0853d6e1a86.tar.gz
lanes-89d9c98af1ac352ba4d49d660e61b0853d6e1a86.tar.bz2
lanes-89d9c98af1ac352ba4d49d660e61b0853d6e1a86.zip
Import to git
Diffstat (limited to 'src/tools.h')
-rw-r--r--src/tools.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/tools.h b/src/tools.h
new file mode 100644
index 0000000..d155c65
--- /dev/null
+++ b/src/tools.h
@@ -0,0 +1,72 @@
1/*
2* TOOLS.H
3*/
4#ifndef TOOLS_H
5#define TOOLS_H
6
7#include "lua.h"
8#include "threading.h"
9 // MUTEX_T
10
11#include <assert.h>
12
13// Note: The < -10000 test is to leave registry/global/upvalue indices untouched
14//
15#define /*int*/ STACK_ABS(L,n) \
16 ( ((n) >= 0 || (n) <= -10000) ? (n) : lua_gettop(L) +(n) +1 )
17
18#ifdef NDEBUG
19 #define _ASSERT_L(lua,c) /*nothing*/
20 #define STACK_CHECK(L) /*nothing*/
21 #define STACK_MID(L,c) /*nothing*/
22 #define STACK_END(L,c) /*nothing*/
23 #define STACK_DUMP(L) /*nothing*/
24 #define DEBUG() /*nothing*/
25#else
26 #define _ASSERT_L(lua,c) { if (!(c)) luaL_error( lua, "ASSERT failed: %s:%d '%s'", __FILE__, __LINE__, #c ); }
27 //
28 #define STACK_CHECK(L) { int _oldtop_##L = lua_gettop(L);
29 #define STACK_MID(L,change) { int a= lua_gettop(L)-_oldtop_##L; int b= (change); \
30 if (a != b) luaL_error( L, "STACK ASSERT failed (%d not %d): %s:%d", a, b, __FILE__, __LINE__ ); }
31 #define STACK_END(L,change) STACK_MID(L,change) }
32
33 #define STACK_DUMP(L) luaG_dump(L);
34 #define DEBUG() fprintf( stderr, "<<%s %d>>\n", __FILE__, __LINE__ );
35#endif
36#define ASSERT_L(c) _ASSERT_L(L,c)
37
38#define STACK_GROW(L,n) { if (!lua_checkstack(L,n)) luaL_error( L, "Cannot grow stack!" ); }
39
40#define LUAG_FUNC( func_name ) static int LG_##func_name( lua_State *L )
41
42#define luaG_optunsigned(L,i,d) ((uint_t) luaL_optinteger(L,i,d))
43#define luaG_tounsigned(L,i) ((uint_t) lua_tointeger(L,i))
44
45#define luaG_isany(L,i) (!lua_isnil(L,i))
46
47#define luaG_typename( L, index ) lua_typename( L, lua_type(L,index) )
48
49void luaG_dump( lua_State* L );
50
51const char *luaG_openlibs( lua_State *L, const char *libs );
52
53int luaG_deep_userdata( lua_State *L );
54void *luaG_todeep( lua_State *L, lua_CFunction idfunc, int index );
55
56typedef struct {
57 volatile int refcount;
58 void *deep;
59} DEEP_PRELUDE;
60
61void luaG_push_proxy( lua_State *L, lua_CFunction idfunc, DEEP_PRELUDE *deep_userdata );
62
63void luaG_inter_copy( lua_State *L, lua_State *L2, uint_t n );
64void luaG_inter_move( lua_State *L, lua_State *L2, uint_t n );
65
66// Lock for reference counter inc/dec locks (to be initialized by outside code)
67//
68extern MUTEX_T deep_lock;
69extern MUTEX_T mtid_lock;
70
71#endif
72 // TOOLS_H