diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2018-11-15 11:20:14 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2018-11-15 11:20:14 +0100 |
commit | 01f83215a2ad235fbf306f591c6c0547b1bb7047 (patch) | |
tree | 51d1edff1c3f684bac388c64d91ee30d8f6fbbf2 /src/deep.h | |
parent | 55acf8e19728ac39581c35f1324debf9449bd185 (diff) | |
download | lanes-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.h | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -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 |
13 | struct s_Universe; | 14 | struct 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/ |
47 | static DECLARE_CONST_UNIQUE_KEY( DEEP_VERSION, 0x4f4eadf0accf6c73); | ||
48 | |||
49 | // should be used as header for full userdata | ||
46 | struct s_DeepPrelude | 50 | struct 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 | }; |
53 | typedef struct s_DeepPrelude DeepPrelude; | 58 | typedef struct s_DeepPrelude DeepPrelude; |
54 | 59 | ||
@@ -57,6 +62,5 @@ void free_deep_prelude( lua_State* L, DeepPrelude* prelude_); | |||
57 | 62 | ||
58 | extern LANES_API int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc); | 63 | extern LANES_API int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc); |
59 | extern LANES_API void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index); | 64 | extern LANES_API void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index); |
60 | extern LANES_API void luaG_pushdeepversion( lua_State* L); | ||
61 | 65 | ||
62 | #endif // __LANES_DEEP_H__ | 66 | #endif // __LANES_DEEP_H__ |