diff options
Diffstat (limited to 'src/tools.cpp')
-rw-r--r-- | src/tools.cpp | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/src/tools.cpp b/src/tools.cpp index 88e7e2b..5196e7e 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -61,32 +61,32 @@ DEBUGSPEW_CODE( char const* debugspew_indent = "----+----!----+----!----+----!-- | |||
61 | */ | 61 | */ |
62 | void push_registry_subtable_mode( lua_State* L, UniqueKey key_, const char* mode_) | 62 | void push_registry_subtable_mode( lua_State* L, UniqueKey key_, const char* mode_) |
63 | { | 63 | { |
64 | STACK_GROW( L, 3); | 64 | STACK_GROW(L, 3); |
65 | STACK_CHECK( L, 0); | 65 | STACK_CHECK(L, 0); |
66 | 66 | ||
67 | REGISTRY_GET( L, key_); // {}|nil | 67 | key_.query_registry(L); // {}|nil |
68 | STACK_MID( L, 1); | 68 | STACK_MID(L, 1); |
69 | |||
70 | if( lua_isnil( L, -1)) | ||
71 | { | ||
72 | lua_pop( L, 1); // | ||
73 | lua_newtable( L); // {} | ||
74 | // _R[key_] = {} | ||
75 | REGISTRY_SET( L, key_, lua_pushvalue( L, -2)); // {} | ||
76 | STACK_MID( L, 1); | ||
77 | 69 | ||
78 | // Set its metatable if requested | 70 | if (lua_isnil(L, -1)) |
79 | if( mode_) | ||
80 | { | 71 | { |
81 | lua_newtable( L); // {} mt | 72 | lua_pop(L, 1); // |
82 | lua_pushliteral( L, "__mode"); // {} mt "__mode" | 73 | lua_newtable(L); // {} |
83 | lua_pushstring( L, mode_); // {} mt "__mode" mode | 74 | // _R[key_] = {} |
84 | lua_rawset( L, -3); // {} mt | 75 | key_.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); }); // {} |
85 | lua_setmetatable( L, -2); // {} | 76 | STACK_MID(L, 1); |
77 | |||
78 | // Set its metatable if requested | ||
79 | if (mode_) | ||
80 | { | ||
81 | lua_newtable(L); // {} mt | ||
82 | lua_pushliteral(L, "__mode"); // {} mt "__mode" | ||
83 | lua_pushstring(L, mode_); // {} mt "__mode" mode | ||
84 | lua_rawset(L, -3); // {} mt | ||
85 | lua_setmetatable(L, -2); // {} | ||
86 | } | ||
86 | } | 87 | } |
87 | } | 88 | STACK_END(L, 1); |
88 | STACK_END( L, 1); | 89 | ASSERT_L(lua_istable(L, -1)); |
89 | ASSERT_L( lua_istable( L, -1)); | ||
90 | } | 90 | } |
91 | 91 | ||
92 | // ################################################################################################ | 92 | // ################################################################################################ |
@@ -573,7 +573,7 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_) | |||
573 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | 573 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); |
574 | STACK_GROW( L, 3); | 574 | STACK_GROW( L, 3); |
575 | STACK_CHECK( L, 0); | 575 | STACK_CHECK( L, 0); |
576 | REGISTRY_GET( L, LOOKUP_REGKEY); // {} | 576 | LOOKUP_REGKEY.query_registry(L); // {} |
577 | STACK_MID( L, 1); | 577 | STACK_MID( L, 1); |
578 | ASSERT_L( lua_istable( L, -1)); | 578 | ASSERT_L( lua_istable( L, -1)); |
579 | if( lua_type( L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function | 579 | if( lua_type( L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function |
@@ -603,12 +603,12 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_) | |||
603 | STACK_MID( L, 2); | 603 | STACK_MID( L, 2); |
604 | } | 604 | } |
605 | // retrieve the cache, create it if we haven't done it yet | 605 | // retrieve the cache, create it if we haven't done it yet |
606 | REGISTRY_GET( L, LOOKUPCACHE_REGKEY); // {} {fqn} {cache}? | 606 | LOOKUPCACHE_REGKEY.query_registry(L); // {} {fqn} {cache}? |
607 | if( lua_isnil( L, -1)) | 607 | if( lua_isnil( L, -1)) |
608 | { | 608 | { |
609 | lua_pop( L, 1); // {} {fqn} | 609 | lua_pop( L, 1); // {} {fqn} |
610 | lua_newtable( L); // {} {fqn} {cache} | 610 | lua_newtable( L); // {} {fqn} {cache} |
611 | REGISTRY_SET( L, LOOKUPCACHE_REGKEY, lua_pushvalue( L, -2)); | 611 | LOOKUPCACHE_REGKEY.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); }); |
612 | STACK_MID( L, 3); | 612 | STACK_MID( L, 3); |
613 | } | 613 | } |
614 | // process everything we find in that table, filling in lookup data for all functions and tables we see there | 614 | // process everything we find in that table, filling in lookup data for all functions and tables we see there |
@@ -719,7 +719,7 @@ static char const* find_lookup_name(lua_State* L, int i, LookupMode mode_, char | |||
719 | else | 719 | else |
720 | { | 720 | { |
721 | // fetch the name from the source state's lookup table | 721 | // fetch the name from the source state's lookup table |
722 | REGISTRY_GET( L, LOOKUP_REGKEY); // ... v ... {} | 722 | LOOKUP_REGKEY.query_registry(L); // ... v ... {} |
723 | STACK_MID( L, 1); | 723 | STACK_MID( L, 1); |
724 | ASSERT_L( lua_istable( L, -1)); | 724 | ASSERT_L( lua_istable( L, -1)); |
725 | lua_pushvalue( L, i); // ... v ... {} v | 725 | lua_pushvalue( L, i); // ... v ... {} v |
@@ -792,7 +792,7 @@ static bool lookup_table(lua_State* L2, lua_State* L, int i, LookupMode mode_, c | |||
792 | 792 | ||
793 | case eLM_LaneBody: | 793 | case eLM_LaneBody: |
794 | case eLM_FromKeeper: | 794 | case eLM_FromKeeper: |
795 | REGISTRY_GET( L2, LOOKUP_REGKEY); // {} | 795 | LOOKUP_REGKEY.query_registry(L2); // {} |
796 | STACK_MID( L2, 1); | 796 | STACK_MID( L2, 1); |
797 | ASSERT_L( lua_istable( L2, -1)); | 797 | ASSERT_L( lua_istable( L2, -1)); |
798 | lua_pushlstring( L2, fqn, len); // {} "f.q.n" | 798 | lua_pushlstring( L2, fqn, len); // {} "f.q.n" |
@@ -1093,7 +1093,7 @@ static void lookup_native_func(lua_State* L2, lua_State* L, int i, LookupMode mo | |||
1093 | 1093 | ||
1094 | case eLM_LaneBody: | 1094 | case eLM_LaneBody: |
1095 | case eLM_FromKeeper: | 1095 | case eLM_FromKeeper: |
1096 | REGISTRY_GET( L2, LOOKUP_REGKEY); // {} | 1096 | LOOKUP_REGKEY.query_registry(L2); // {} |
1097 | STACK_MID( L2, 1); | 1097 | STACK_MID( L2, 1); |
1098 | ASSERT_L( lua_istable( L2, -1)); | 1098 | ASSERT_L( lua_istable( L2, -1)); |
1099 | lua_pushlstring( L2, fqn, len); // {} "f.q.n" | 1099 | lua_pushlstring( L2, fqn, len); // {} "f.q.n" |