aboutsummaryrefslogtreecommitdiff
path: root/src/deep.h
blob: aeeb828b37b1ccc2ab295c5e2d4ef219b0d70c5a (plain)
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
51
52
53
54
55
#ifndef __LANES_DEEP_H__
#define __LANES_DEEP_H__ 1

/*
 * public 'deep' API to be used by external modules if they want to implement Lanes-aware userdata
 * said modules will have to link against lanes (it is not really possible to separate the 'deep userdata' implementation from the rest of Lanes)
 */

#include "lua.h"
#include "platform.h"

// forwards
struct s_Universe;
typedef struct s_Universe Universe;
enum eLookupMode;
typedef enum eLookupMode LookupMode;

#if !defined LANES_API // when deep is compiled standalone outside Lanes
#if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC)
#define LANES_API __declspec(dllexport)
#else
#define LANES_API
#endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC)
#endif // LANES_API

enum eDeepOp
{
	eDO_new,
	eDO_delete,
	eDO_metatable,
	eDO_module,
};

typedef void* (*luaG_IdFunction)( lua_State* L, enum eDeepOp op_);

// ################################################################################################

// this is pointed to by full userdata proxies, and allocated with malloc() to survive any lua_State lifetime
struct s_DeepPrelude
{
	volatile int refcount;
	void* deep;
	// when stored in a keeper state, the full userdata doesn't have a metatable, so we need direct access to the idfunc
	luaG_IdFunction idfunc;
};
typedef struct s_DeepPrelude DeepPrelude;

char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, LookupMode mode_);
void free_deep_prelude( lua_State* L, DeepPrelude* prelude_);

extern LANES_API int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc);
extern LANES_API void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index);
extern LANES_API void luaG_pushdeepversion( lua_State* L);

#endif // __LANES_DEEP_H__