aboutsummaryrefslogtreecommitdiff
path: root/src/universe.c
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2018-11-19 09:16:49 +0100
committerBenoit Germain <bnt.germain@gmail.com>2018-11-19 09:16:49 +0100
commit7b4f59c5ebc84e426e2876906b24d7dd73342f07 (patch)
treef05748fc2d75c43c25865be01677271fff5d86e4 /src/universe.c
parent01f83215a2ad235fbf306f591c6c0547b1bb7047 (diff)
downloadlanes-7b4f59c5ebc84e426e2876906b24d7dd73342f07.tar.gz
lanes-7b4f59c5ebc84e426e2876906b24d7dd73342f07.tar.bz2
lanes-7b4f59c5ebc84e426e2876906b24d7dd73342f07.zip
Internal code tweaks
* Registry access code utility macros * CONFIG_REGKEY and LOOKUP_REGKEY are now lightuserdata instead of strings * Stack checking debug macros improvements
Diffstat (limited to 'src/universe.c')
-rw-r--r--src/universe.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/universe.c b/src/universe.c
index 4689a09..d531bf2 100644
--- a/src/universe.c
+++ b/src/universe.c
@@ -29,6 +29,7 @@ THE SOFTWARE.
29*/ 29*/
30 30
31#include <string.h> 31#include <string.h>
32#include <assert.h>
32 33
33#include "universe.h" 34#include "universe.h"
34#include "compat.h" 35#include "compat.h"
@@ -44,9 +45,9 @@ Universe* universe_create( lua_State* L)
44{ 45{
45 Universe* U = (Universe*) lua_newuserdata( L, sizeof(Universe)); // universe 46 Universe* U = (Universe*) lua_newuserdata( L, sizeof(Universe)); // universe
46 memset( U, 0, sizeof( Universe)); 47 memset( U, 0, sizeof( Universe));
47 push_unique_key( L, UNIVERSE_REGKEY); // universe UNIVERSE_REGKEY 48 STACK_CHECK( L, 1);
48 lua_pushvalue( L, -2); // universe UNIVERSE_REGKEY universe 49 REGISTRY_SET( L, UNIVERSE_REGKEY, lua_pushvalue(L, -2)); // universe
49 lua_rawset( L, LUA_REGISTRYINDEX); // universe 50 STACK_END( L, 1);
50 return U; 51 return U;
51} 52}
52 53
@@ -54,17 +55,8 @@ Universe* universe_create( lua_State* L)
54 55
55void universe_store( lua_State* L, Universe* U) 56void universe_store( lua_State* L, Universe* U)
56{ 57{
57 STACK_CHECK( L); 58 STACK_CHECK( L, 0);
58 push_unique_key( L, UNIVERSE_REGKEY); 59 REGISTRY_SET( L, UNIVERSE_REGKEY, (NULL != U) ? lua_pushlightuserdata( L, U) : lua_pushnil( L));
59 if( NULL != U)
60 {
61 lua_pushlightuserdata( L, U);
62 }
63 else
64 {
65 lua_pushnil( L);
66 }
67 lua_rawset( L, LUA_REGISTRYINDEX);
68 STACK_END( L, 0); 60 STACK_END( L, 0);
69} 61}
70 62
@@ -74,9 +66,8 @@ Universe* universe_get( lua_State* L)
74{ 66{
75 Universe* universe; 67 Universe* universe;
76 STACK_GROW( L, 2); 68 STACK_GROW( L, 2);
77 STACK_CHECK( L); 69 STACK_CHECK( L, 0);
78 push_unique_key( L, UNIVERSE_REGKEY); 70 REGISTRY_GET( L, UNIVERSE_REGKEY);
79 lua_rawget( L, LUA_REGISTRYINDEX);
80 universe = lua_touserdata( L, -1); // NULL if nil 71 universe = lua_touserdata( L, -1); // NULL if nil
81 lua_pop( L, 1); 72 lua_pop( L, 1);
82 STACK_END( L, 0); 73 STACK_END( L, 0);