aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lanes.cpp')
-rw-r--r--src/lanes.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp
index acfa0dc..1589240 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -157,7 +157,7 @@ static bool push_registry_table( lua_State* L, UniqueKey key, bool create)
157 STACK_GROW( L, 3); 157 STACK_GROW( L, 3);
158 STACK_CHECK( L, 0); 158 STACK_CHECK( L, 0);
159 159
160 REGISTRY_GET( L, key); // ? 160 key.query_registry(L); // ?
161 if( lua_isnil( L, -1)) // nil? 161 if( lua_isnil( L, -1)) // nil?
162 { 162 {
163 lua_pop( L, 1); // 163 lua_pop( L, 1); //
@@ -168,7 +168,7 @@ static bool push_registry_table( lua_State* L, UniqueKey key, bool create)
168 } 168 }
169 169
170 lua_newtable( L); // t 170 lua_newtable( L); // t
171 REGISTRY_SET( L, key, lua_pushvalue( L, -2)); 171 key.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); });
172 } 172 }
173 STACK_END( L, 1); 173 STACK_END( L, 1);
174 return true; // table pushed 174 return true; // table pushed
@@ -669,7 +669,7 @@ LUAG_FUNC( set_error_reporting)
669 return luaL_error( L, "unsupported error reporting model"); 669 return luaL_error( L, "unsupported error reporting model");
670 } 670 }
671done: 671done:
672 REGISTRY_SET( L, EXTENDED_STACKTRACE_REGKEY, lua_pushboolean( L, equal)); 672 EXTENDED_STACKTRACE_REGKEY.set_registry(L, [equal](lua_State* L) { lua_pushboolean(L, equal); });
673 return 0; 673 return 0;
674} 674}
675 675
@@ -679,7 +679,7 @@ static int lane_error( lua_State* L)
679 int n; 679 int n;
680 680
681 // error message (any type) 681 // error message (any type)
682 STACK_CHECK_ABS( L, 1); // some_error 682 STACK_CHECK_ABS( L, 1); // some_error
683 683
684 // Don't do stack survey for cancelled lanes. 684 // Don't do stack survey for cancelled lanes.
685 // 685 //
@@ -689,11 +689,11 @@ static int lane_error( lua_State* L)
689 } 689 }
690 690
691 STACK_GROW( L, 3); 691 STACK_GROW( L, 3);
692 REGISTRY_GET( L, EXTENDED_STACKTRACE_REGKEY); // some_error basic|extended 692 EXTENDED_STACKTRACE_REGKEY.query_registry(L); // some_error basic|extended
693 bool const extended{ lua_toboolean(L, -1) ? true : false}; 693 bool const extended{ lua_toboolean(L, -1) ? true : false};
694 lua_pop( L, 1); // some_error 694 lua_pop( L, 1); // some_error
695 695
696 // Place stack trace at 'registry[lane_error]' for the 'lua_pcall()' 696 // Place stack trace at 'registry[STACKTRACE_REGKEY]' for the 'lua_pcall()'
697 // caller to fetch. This bypasses the Lua 5.1 limitation of only one 697 // caller to fetch. This bypasses the Lua 5.1 limitation of only one
698 // return value from error handler to 'lua_pcall()' caller. 698 // return value from error handler to 'lua_pcall()' caller.
699 699
@@ -703,7 +703,7 @@ static int lane_error( lua_State* L)
703 // 703 //
704 // table of { "sourcefile.lua:<line>", ... } 704 // table of { "sourcefile.lua:<line>", ... }
705 // 705 //
706 lua_newtable( L); // some_error {} 706 lua_newtable( L); // some_error {}
707 707
708 // Best to start from level 1, but in some cases it might be a C function 708 // Best to start from level 1, but in some cases it might be a C function
709 // and we don't get '.currentline' for that. It's okay - just keep level 709 // and we don't get '.currentline' for that. It's okay - just keep level
@@ -739,10 +739,11 @@ static int lane_error( lua_State* L)
739 { 739 {
740 lua_pushfstring( L, "%s:?", ar.short_src); // some_error {} "blah" 740 lua_pushfstring( L, "%s:?", ar.short_src); // some_error {} "blah"
741 } 741 }
742 lua_rawseti( L, -2, (lua_Integer) n); // some_error {} 742 lua_rawseti( L, -2, (lua_Integer) n); // some_error {}
743 } 743 }
744 744
745 REGISTRY_SET( L, STACKTRACE_REGKEY, lua_insert( L, -2)); // some_error 745 // store the stack trace table in the registry
746 STACKTRACE_REGKEY.set_registry(L, [](lua_State* L) { lua_insert(L, -2); }); // some_error
746 747
747 STACK_END( L, 1); 748 STACK_END( L, 1);
748 return 1; // the untouched error value 749 return 1; // the untouched error value
@@ -764,7 +765,7 @@ static void push_stack_trace( lua_State* L, int rc_, int stk_base_)
764 // fetch the call stack table from the registry where the handler stored it 765 // fetch the call stack table from the registry where the handler stored it
765 STACK_GROW( L, 1); 766 STACK_GROW( L, 1);
766 // yields nil if no stack was generated (in case of cancellation for example) 767 // yields nil if no stack was generated (in case of cancellation for example)
767 REGISTRY_GET( L, STACKTRACE_REGKEY); // err trace|nil 768 STACKTRACE_REGKEY.query_registry(L); // err trace|nil
768 STACK_END( L, 1); 769 STACK_END( L, 1);
769 770
770 // For cancellation the error message is CANCEL_ERROR, and a stack trace isn't placed 771 // For cancellation the error message is CANCEL_ERROR, and a stack trace isn't placed
@@ -794,7 +795,7 @@ LUAG_FUNC( set_debug_threadname)
794 lua_settop( L, 1); 795 lua_settop( L, 1);
795 STACK_CHECK_ABS( L, 1); 796 STACK_CHECK_ABS( L, 1);
796 // store a hidden reference in the registry to make sure the string is kept around even if a lane decides to manually change the "decoda_name" global... 797 // store a hidden reference in the registry to make sure the string is kept around even if a lane decides to manually change the "decoda_name" global...
797 REGISTRY_SET( L, hidden_regkey, lua_pushvalue( L, -2)); 798 hidden_regkey.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); });
798 STACK_MID( L, 1); 799 STACK_MID( L, 1);
799 s->debug_name = lua_tostring( L, -1); 800 s->debug_name = lua_tostring( L, -1);
800 // keep a direct pointer on the string 801 // keep a direct pointer on the string
@@ -1276,7 +1277,7 @@ LUAG_FUNC( lane_new)
1276 lua_setiuservalue( L, -2, 1); // func libs priority globals package required gc_cb lane 1277 lua_setiuservalue( L, -2, 1); // func libs priority globals package required gc_cb lane
1277 1278
1278 // Store 's' in the lane's registry, for 'cancel_test()' (we do cancel tests at pending send/receive). 1279 // Store 's' in the lane's registry, for 'cancel_test()' (we do cancel tests at pending send/receive).
1279 REGISTRY_SET( L2, CANCEL_TEST_KEY, lua_pushlightuserdata( L2, s)); // func [... args ...] 1280 CANCEL_TEST_KEY.set_registry(L2, [s](lua_State* L) { lua_pushlightuserdata(L, s); }); // func [... args ...]
1280 1281
1281 STACK_END( L, 1); 1282 STACK_END( L, 1);
1282 STACK_END( L2, 1 + nargs); 1283 STACK_END( L2, 1 + nargs);
@@ -1993,7 +1994,7 @@ LUAG_FUNC( configure)
1993 1994
1994 STACK_MID( L, 2); // reference stack contains only the function argument 'settings' 1995 STACK_MID( L, 2); // reference stack contains only the function argument 'settings'
1995 // we'll need this every time we transfer some C function from/to this state 1996 // we'll need this every time we transfer some C function from/to this state
1996 REGISTRY_SET( L, LOOKUP_REGKEY, lua_newtable( L)); 1997 LOOKUP_REGKEY.set_registry(L, [](lua_State* L) { lua_newtable(L); }); // settings M
1997 STACK_MID( L, 2); 1998 STACK_MID( L, 2);
1998 1999
1999 // register all native functions found in that module in the transferable functions database 2000 // register all native functions found in that module in the transferable functions database
@@ -2015,8 +2016,8 @@ LUAG_FUNC( configure)
2015 } 2016 }
2016 lua_pop( L, 1); // settings 2017 lua_pop( L, 1); // settings
2017 2018
2018 // set _R[CONFIG_REGKEY] = settings 2019 // set _R[CONFIG_REGKEY] = settings
2019 REGISTRY_SET( L, CONFIG_REGKEY, lua_pushvalue( L, -2)); // -2 because CONFIG_REGKEY is pushed before the value itself 2020 CONFIG_REGKEY.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); });
2020 STACK_END( L, 1); 2021 STACK_END( L, 1);
2021 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() END\n" INDENT_END, L)); 2022 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() END\n" INDENT_END, L));
2022 DEBUGSPEW_CODE( -- U->debugspew_indent_depth); 2023 DEBUGSPEW_CODE( -- U->debugspew_indent_depth);
@@ -2103,7 +2104,7 @@ LANES_API int luaopen_lanes_core( lua_State* L)
2103 lua_pushvalue( L, 1); // M "lanes.core" 2104 lua_pushvalue( L, 1); // M "lanes.core"
2104 lua_pushvalue( L, -2); // M "lanes.core" M 2105 lua_pushvalue( L, -2); // M "lanes.core" M
2105 lua_pushcclosure( L, LG_configure, 2); // M LG_configure() 2106 lua_pushcclosure( L, LG_configure, 2); // M LG_configure()
2106 REGISTRY_GET( L, CONFIG_REGKEY); // M LG_configure() settings 2107 CONFIG_REGKEY.query_registry(L); // M LG_configure() settings
2107 if( !lua_isnil( L, -1)) // this is not the first require "lanes.core": call configure() immediately 2108 if( !lua_isnil( L, -1)) // this is not the first require "lanes.core": call configure() immediately
2108 { 2109 {
2109 lua_pushvalue( L, -1); // M LG_configure() settings settings 2110 lua_pushvalue( L, -1); // M LG_configure() settings settings