diff options
Diffstat (limited to 'src/deep.c')
-rw-r--r-- | src/deep.c | 36 |
1 files changed, 18 insertions, 18 deletions
@@ -32,11 +32,6 @@ THE SOFTWARE. | |||
32 | =============================================================================== | 32 | =============================================================================== |
33 | */ | 33 | */ |
34 | 34 | ||
35 | #include "compat.h" | ||
36 | #include "tools.h" | ||
37 | #include "universe.h" | ||
38 | #include "deep.h" | ||
39 | |||
40 | #include <stdio.h> | 35 | #include <stdio.h> |
41 | #include <string.h> | 36 | #include <string.h> |
42 | #include <ctype.h> | 37 | #include <ctype.h> |
@@ -45,6 +40,11 @@ THE SOFTWARE. | |||
45 | #include <malloc.h> | 40 | #include <malloc.h> |
46 | #endif | 41 | #endif |
47 | 42 | ||
43 | #include "compat.h" | ||
44 | #include "deep.h" | ||
45 | #include "tools.h" | ||
46 | #include "universe.h" | ||
47 | |||
48 | /*-- Metatable copying --*/ | 48 | /*-- Metatable copying --*/ |
49 | 49 | ||
50 | /* | 50 | /* |
@@ -179,7 +179,7 @@ static inline luaG_IdFunction get_idfunc( lua_State* L, int index, enum eLookupM | |||
179 | // when looking inside a keeper, we are 100% sure the object is a deep userdata | 179 | // when looking inside a keeper, we are 100% sure the object is a deep userdata |
180 | if( mode_ == eLM_FromKeeper) | 180 | if( mode_ == eLM_FromKeeper) |
181 | { | 181 | { |
182 | struct DEEP_PRELUDE** proxy = (struct DEEP_PRELUDE**) lua_touserdata( L, index); | 182 | DeepPrelude** proxy = (DeepPrelude**) lua_touserdata( L, index); |
183 | // we can (and must) cast and fetch the internally stored idfunc | 183 | // we can (and must) cast and fetch the internally stored idfunc |
184 | return (*proxy)->idfunc; | 184 | return (*proxy)->idfunc; |
185 | } | 185 | } |
@@ -208,7 +208,7 @@ static inline luaG_IdFunction get_idfunc( lua_State* L, int index, enum eLookupM | |||
208 | } | 208 | } |
209 | 209 | ||
210 | 210 | ||
211 | void free_deep_prelude( lua_State* L, struct DEEP_PRELUDE* prelude_) | 211 | void free_deep_prelude( lua_State* L, DeepPrelude* prelude_) |
212 | { | 212 | { |
213 | // Call 'idfunc( "delete", deep_ptr )' to make deep cleanup | 213 | // Call 'idfunc( "delete", deep_ptr )' to make deep cleanup |
214 | lua_pushlightuserdata( L, prelude_->deep); | 214 | lua_pushlightuserdata( L, prelude_->deep); |
@@ -226,9 +226,9 @@ void free_deep_prelude( lua_State* L, struct DEEP_PRELUDE* prelude_) | |||
226 | */ | 226 | */ |
227 | static int deep_userdata_gc( lua_State* L) | 227 | static int deep_userdata_gc( lua_State* L) |
228 | { | 228 | { |
229 | struct DEEP_PRELUDE** proxy = (struct DEEP_PRELUDE**) lua_touserdata( L, 1); | 229 | DeepPrelude** proxy = (DeepPrelude**) lua_touserdata( L, 1); |
230 | struct DEEP_PRELUDE* p = *proxy; | 230 | DeepPrelude* p = *proxy; |
231 | struct s_Universe* U = universe_get( L); | 231 | Universe* U = universe_get( L); |
232 | int v; | 232 | int v; |
233 | 233 | ||
234 | // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded | 234 | // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded |
@@ -270,9 +270,9 @@ static int deep_userdata_gc( lua_State* L) | |||
270 | * used in this Lua state (metatable, registring it). Otherwise, increments the | 270 | * used in this Lua state (metatable, registring it). Otherwise, increments the |
271 | * reference count. | 271 | * reference count. |
272 | */ | 272 | */ |
273 | char const* push_deep_proxy( struct s_Universe* U, lua_State* L, struct DEEP_PRELUDE* prelude, enum eLookupMode mode_) | 273 | char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, enum eLookupMode mode_) |
274 | { | 274 | { |
275 | struct DEEP_PRELUDE** proxy; | 275 | DeepPrelude** proxy; |
276 | 276 | ||
277 | // Check if a proxy already exists | 277 | // Check if a proxy already exists |
278 | push_registry_subtable_mode( L, DEEP_PROXY_CACHE_KEY, "v"); // DPC | 278 | push_registry_subtable_mode( L, DEEP_PROXY_CACHE_KEY, "v"); // DPC |
@@ -297,7 +297,7 @@ char const* push_deep_proxy( struct s_Universe* U, lua_State* L, struct DEEP_PRE | |||
297 | STACK_GROW( L, 7); | 297 | STACK_GROW( L, 7); |
298 | STACK_CHECK( L); | 298 | STACK_CHECK( L); |
299 | 299 | ||
300 | proxy = lua_newuserdata( L, sizeof(struct DEEP_PRELUDE*)); // DPC proxy | 300 | proxy = lua_newuserdata( L, sizeof(DeepPrelude*)); // DPC proxy |
301 | ASSERT_L( proxy); | 301 | ASSERT_L( proxy); |
302 | *proxy = prelude; | 302 | *proxy = prelude; |
303 | 303 | ||
@@ -454,7 +454,7 @@ char const* push_deep_proxy( struct s_Universe* U, lua_State* L, struct DEEP_PRE | |||
454 | int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc) | 454 | int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc) |
455 | { | 455 | { |
456 | char const* errmsg; | 456 | char const* errmsg; |
457 | struct DEEP_PRELUDE* prelude = DEEP_MALLOC( sizeof(struct DEEP_PRELUDE)); | 457 | DeepPrelude* prelude = DEEP_MALLOC( sizeof( DeepPrelude)); |
458 | if( prelude == NULL) | 458 | if( prelude == NULL) |
459 | { | 459 | { |
460 | return luaL_error( L, "couldn't not allocate deep prelude: out of memory"); | 460 | return luaL_error( L, "couldn't not allocate deep prelude: out of memory"); |
@@ -496,7 +496,7 @@ int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc) | |||
496 | */ | 496 | */ |
497 | void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index) | 497 | void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index) |
498 | { | 498 | { |
499 | struct DEEP_PRELUDE** proxy; | 499 | DeepPrelude** proxy; |
500 | 500 | ||
501 | STACK_CHECK( L); | 501 | STACK_CHECK( L); |
502 | // ensure it is actually a deep userdata | 502 | // ensure it is actually a deep userdata |
@@ -505,7 +505,7 @@ void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index) | |||
505 | return NULL; // no metatable, or wrong kind | 505 | return NULL; // no metatable, or wrong kind |
506 | } | 506 | } |
507 | 507 | ||
508 | proxy = (struct DEEP_PRELUDE**) lua_touserdata( L, index); | 508 | proxy = (DeepPrelude**) lua_touserdata( L, index); |
509 | STACK_END( L, 0); | 509 | STACK_END( L, 0); |
510 | 510 | ||
511 | return (*proxy)->deep; | 511 | return (*proxy)->deep; |
@@ -519,7 +519,7 @@ void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index) | |||
519 | * the id function of the copied value, or NULL for non-deep userdata | 519 | * the id function of the copied value, or NULL for non-deep userdata |
520 | * (not copied) | 520 | * (not copied) |
521 | */ | 521 | */ |
522 | luaG_IdFunction copydeep( struct s_Universe* U, lua_State* L, lua_State* L2, int index, enum eLookupMode mode_) | 522 | luaG_IdFunction copydeep( Universe* U, lua_State* L, lua_State* L2, int index, enum eLookupMode mode_) |
523 | { | 523 | { |
524 | char const* errmsg; | 524 | char const* errmsg; |
525 | luaG_IdFunction idfunc = get_idfunc( L, index, mode_); | 525 | luaG_IdFunction idfunc = get_idfunc( L, index, mode_); |
@@ -528,7 +528,7 @@ luaG_IdFunction copydeep( struct s_Universe* U, lua_State* L, lua_State* L2, int | |||
528 | return NULL; // not a deep userdata | 528 | return NULL; // not a deep userdata |
529 | } | 529 | } |
530 | 530 | ||
531 | errmsg = push_deep_proxy( U, L2, *(struct DEEP_PRELUDE**) lua_touserdata( L, index), mode_); | 531 | errmsg = push_deep_proxy( U, L2, *(DeepPrelude**) lua_touserdata( L, index), mode_); |
532 | if( errmsg != NULL) | 532 | if( errmsg != NULL) |
533 | { | 533 | { |
534 | // raise the error in the proper state (not the keeper) | 534 | // raise the error in the proper state (not the keeper) |