aboutsummaryrefslogtreecommitdiff
path: root/src/deep.h
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2018-11-15 11:20:14 +0100
committerBenoit Germain <bnt.germain@gmail.com>2018-11-15 11:20:14 +0100
commit01f83215a2ad235fbf306f591c6c0547b1bb7047 (patch)
tree51d1edff1c3f684bac388c64d91ee30d8f6fbbf2 /src/deep.h
parent55acf8e19728ac39581c35f1324debf9449bd185 (diff)
downloadlanes-01f83215a2ad235fbf306f591c6c0547b1bb7047.tar.gz
lanes-01f83215a2ad235fbf306f591c6c0547b1bb7047.tar.bz2
lanes-01f83215a2ad235fbf306f591c6c0547b1bb7047.zip
Deep userdata must embed DeepPrelude to save an allocation (also changes Deep protocol)
Diffstat (limited to 'src/deep.h')
-rw-r--r--src/deep.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/deep.h b/src/deep.h
index 918de6a..8d06395 100644
--- a/src/deep.h
+++ b/src/deep.h
@@ -8,6 +8,7 @@
8 8
9#include "lua.h" 9#include "lua.h"
10#include "platform.h" 10#include "platform.h"
11#include "uniquekey.h"
11 12
12// forwards 13// forwards
13struct s_Universe; 14struct s_Universe;
@@ -42,13 +43,17 @@ typedef void* (*luaG_IdFunction)( lua_State* L, DeepOp op_);
42 43
43// ################################################################################################ 44// ################################################################################################
44 45
45// this is pointed to by full userdata proxies, and allocated with malloc() to survive any lua_State lifetime 46// crc64/we of string "DEEP_VERSION_1" generated at http://www.nitrxgen.net/hashgen/
47static DECLARE_CONST_UNIQUE_KEY( DEEP_VERSION, 0x4f4eadf0accf6c73);
48
49// should be used as header for full userdata
46struct s_DeepPrelude 50struct s_DeepPrelude
47{ 51{
48 volatile int refcount; 52 DECLARE_UNIQUE_KEY( magic); // must be filled by the Deep userdata idfunc that allocates it on eDO_new operation
49 void* deep;
50 // when stored in a keeper state, the full userdata doesn't have a metatable, so we need direct access to the idfunc 53 // when stored in a keeper state, the full userdata doesn't have a metatable, so we need direct access to the idfunc
51 luaG_IdFunction idfunc; 54 luaG_IdFunction idfunc;
55 // data is destroyed when refcount is 0
56 volatile int refcount;
52}; 57};
53typedef struct s_DeepPrelude DeepPrelude; 58typedef struct s_DeepPrelude DeepPrelude;
54 59
@@ -57,6 +62,5 @@ void free_deep_prelude( lua_State* L, DeepPrelude* prelude_);
57 62
58extern LANES_API int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc); 63extern LANES_API int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc);
59extern LANES_API void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index); 64extern LANES_API void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index);
60extern LANES_API void luaG_pushdeepversion( lua_State* L);
61 65
62#endif // __LANES_DEEP_H__ 66#endif // __LANES_DEEP_H__