diff options
Diffstat (limited to 'src/lanes.cpp')
-rw-r--r-- | src/lanes.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp index 25f44d9..a36e051 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -170,7 +170,7 @@ LUAG_FUNC(sleep) | |||
170 | lua_pushcfunction(L_, LG_linda_receive); // L_: duration|nil receive() | 170 | lua_pushcfunction(L_, LG_linda_receive); // L_: duration|nil receive() |
171 | STACK_CHECK_START_REL(L_, 0); // we pushed the function we intend to call, now prepare the arguments | 171 | STACK_CHECK_START_REL(L_, 0); // we pushed the function we intend to call, now prepare the arguments |
172 | _U->timerLinda->push(L_); // L_: duration|nil receive() timerLinda | 172 | _U->timerLinda->push(L_); // L_: duration|nil receive() timerLinda |
173 | if (lua_tostringview(L_, 1) == "indefinitely") { | 173 | if (luaG_tostringview(L_, 1) == "indefinitely") { |
174 | lua_pushnil(L_); // L_: duration? receive() timerLinda nil | 174 | lua_pushnil(L_); // L_: duration? receive() timerLinda nil |
175 | } else if (lua_isnoneornil(L_, 1)) { | 175 | } else if (lua_isnoneornil(L_, 1)) { |
176 | lua_pushnumber(L_, 0); // L_: duration? receive() timerLinda 0 | 176 | lua_pushnumber(L_, 0); // L_: duration? receive() timerLinda 0 |
@@ -180,7 +180,7 @@ LUAG_FUNC(sleep) | |||
180 | else { | 180 | else { |
181 | lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration | 181 | lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration |
182 | } | 182 | } |
183 | std::ignore = lua_pushstringview(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key | 183 | std::ignore = luaG_pushstringview(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key |
184 | STACK_CHECK(L_, 3); // 3 arguments ready | 184 | STACK_CHECK(L_, 3); // 3 arguments ready |
185 | lua_call(L_, 3, LUA_MULTRET); // timerLinda:receive(duration,key) // L_: duration? result... | 185 | lua_call(L_, 3, LUA_MULTRET); // timerLinda:receive(duration,key) // L_: duration? result... |
186 | return lua_gettop(L_) - 1; | 186 | return lua_gettop(L_) - 1; |
@@ -194,7 +194,7 @@ LUAG_FUNC(sleep) | |||
194 | // upvalue[1]: _G.require | 194 | // upvalue[1]: _G.require |
195 | LUAG_FUNC(require) | 195 | LUAG_FUNC(require) |
196 | { | 196 | { |
197 | std::string_view const _name{ lua_tostringview(L_, 1) }; // L_: "name" ... | 197 | std::string_view const _name{ luaG_tostringview(L_, 1) }; // L_: "name" ... |
198 | int const _nargs{ lua_gettop(L_) }; | 198 | int const _nargs{ lua_gettop(L_) }; |
199 | DEBUGSPEW_CODE(Universe * _U{ Universe::Get(L_) }); | 199 | DEBUGSPEW_CODE(Universe * _U{ Universe::Get(L_) }); |
200 | STACK_CHECK_START_REL(L_, 0); | 200 | STACK_CHECK_START_REL(L_, 0); |
@@ -216,8 +216,8 @@ LUAG_FUNC(require) | |||
216 | // lanes.register( "modname", module) | 216 | // lanes.register( "modname", module) |
217 | LUAG_FUNC(register) | 217 | LUAG_FUNC(register) |
218 | { | 218 | { |
219 | std::string_view const _name{ luaL_checkstringview(L_, 1) }; | 219 | std::string_view const _name{ luaG_checkstringview(L_, 1) }; |
220 | LuaType const _mod_type{ lua_type_as_enum(L_, 2) }; | 220 | LuaType const _mod_type{ luaG_type(L_, 2) }; |
221 | // ignore extra parameters, just in case | 221 | // ignore extra parameters, just in case |
222 | lua_settop(L_, 2); | 222 | lua_settop(L_, 2); |
223 | luaL_argcheck(L_, (_mod_type == LuaType::TABLE) || (_mod_type == LuaType::FUNCTION), 2, "unexpected module type"); | 223 | luaL_argcheck(L_, (_mod_type == LuaType::TABLE) || (_mod_type == LuaType::FUNCTION), 2, "unexpected module type"); |
@@ -266,7 +266,7 @@ LUAG_FUNC(lane_new) | |||
266 | Universe* const _U{ Universe::Get(L_) }; | 266 | Universe* const _U{ Universe::Get(L_) }; |
267 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: setup" << std::endl); | 267 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: setup" << std::endl); |
268 | 268 | ||
269 | std::optional<std::string_view> _libs_str{ lua_isnil(L_, kLibsIdx) ? std::nullopt : std::make_optional(lua_tostringview(L_, kLibsIdx)) }; | 269 | std::optional<std::string_view> _libs_str{ lua_isnil(L_, kLibsIdx) ? std::nullopt : std::make_optional(luaG_tostringview(L_, kLibsIdx)) }; |
270 | lua_State* const _L2{ state::NewLaneState(_U, SourceState{ L_ }, _libs_str) }; // L_: [fixed] ... L2: | 270 | lua_State* const _L2{ state::NewLaneState(_U, SourceState{ L_ }, _libs_str) }; // L_: [fixed] ... L2: |
271 | STACK_CHECK_START_REL(_L2, 0); | 271 | STACK_CHECK_START_REL(_L2, 0); |
272 | 272 | ||
@@ -345,11 +345,11 @@ LUAG_FUNC(lane_new) | |||
345 | lua_State* _L2{ lane->L }; | 345 | lua_State* _L2{ lane->L }; |
346 | STACK_CHECK_START_REL(_L2, 0); | 346 | STACK_CHECK_START_REL(_L2, 0); |
347 | int const _name_idx{ lua_isnoneornil(L, kNameIdx) ? 0 : kNameIdx }; | 347 | int const _name_idx{ lua_isnoneornil(L, kNameIdx) ? 0 : kNameIdx }; |
348 | std::string_view const _debugName{ (_name_idx > 0) ? lua_tostringview(L, _name_idx) : std::string_view{} }; | 348 | std::string_view const _debugName{ (_name_idx > 0) ? luaG_tostringview(L, _name_idx) : std::string_view{} }; |
349 | if (!_debugName.empty()) | 349 | if (!_debugName.empty()) |
350 | { | 350 | { |
351 | if (_debugName != "auto") { | 351 | if (_debugName != "auto") { |
352 | std::ignore = lua_pushstringview(_L2, _debugName); // L: ... lane L2: "<name>" | 352 | std::ignore = luaG_pushstringview(_L2, _debugName); // L: ... lane L2: "<name>" |
353 | } else { | 353 | } else { |
354 | lua_Debug _ar; | 354 | lua_Debug _ar; |
355 | lua_pushvalue(L, 1); // L: ... lane func | 355 | lua_pushvalue(L, 1); // L: ... lane func |
@@ -413,17 +413,17 @@ LUAG_FUNC(lane_new) | |||
413 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: process 'required' list" << std::endl); | 413 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: process 'required' list" << std::endl); |
414 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); | 414 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); |
415 | // should not happen, was checked in lanes.lua before calling lane_new() | 415 | // should not happen, was checked in lanes.lua before calling lane_new() |
416 | if (lua_type(L_, _required_idx) != LUA_TTABLE) { | 416 | if (luaG_type(L_, _required_idx) != LuaType::TABLE) { |
417 | raise_luaL_error(L_, "expected required module list as a table, got %s", luaL_typename(L_, _required_idx)); | 417 | raise_luaL_error(L_, "expected required module list as a table, got %s", luaL_typename(L_, _required_idx)); |
418 | } | 418 | } |
419 | 419 | ||
420 | lua_pushnil(L_); // L_: [fixed] args... nil L2: | 420 | lua_pushnil(L_); // L_: [fixed] args... nil L2: |
421 | while (lua_next(L_, _required_idx) != 0) { // L_: [fixed] args... n "modname" L2: | 421 | while (lua_next(L_, _required_idx) != 0) { // L_: [fixed] args... n "modname" L2: |
422 | if (lua_type(L_, -1) != LUA_TSTRING || lua_type(L_, -2) != LUA_TNUMBER || lua_tonumber(L_, -2) != _nbRequired) { | 422 | if (luaG_type(L_, -1) != LuaType::STRING || luaG_type(L_, -2) != LuaType::NUMBER || lua_tonumber(L_, -2) != _nbRequired) { |
423 | raise_luaL_error(L_, "required module list should be a list of strings"); | 423 | raise_luaL_error(L_, "required module list should be a list of strings"); |
424 | } else { | 424 | } else { |
425 | // require the module in the target state, and populate the lookup table there too | 425 | // require the module in the target state, and populate the lookup table there too |
426 | std::string_view const _name{ lua_tostringview(L_, -1) }; | 426 | std::string_view const _name{ luaG_tostringview(L_, -1) }; |
427 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: require '" << _name << "'" << std::endl); | 427 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: require '" << _name << "'" << std::endl); |
428 | 428 | ||
429 | // require the module in the target lane | 429 | // require the module in the target lane |
@@ -432,7 +432,7 @@ LUAG_FUNC(lane_new) | |||
432 | lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2: | 432 | lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2: |
433 | raise_luaL_error(L_, "cannot pre-require modules without loading 'package' library first"); | 433 | raise_luaL_error(L_, "cannot pre-require modules without loading 'package' library first"); |
434 | } else { | 434 | } else { |
435 | std::ignore = lua_pushstringview(_L2, _name); // L_: [fixed] args... n "modname" L2: require() name | 435 | std::ignore = luaG_pushstringview(_L2, _name); // L_: [fixed] args... n "modname" L2: require() name |
436 | LuaError const _rc{ lua_pcall(_L2, 1, 1, 0) }; // L_: [fixed] args... n "modname" L2: ret/errcode | 436 | LuaError const _rc{ lua_pcall(_L2, 1, 1, 0) }; // L_: [fixed] args... n "modname" L2: ret/errcode |
437 | if (_rc != LuaError::OK) { | 437 | if (_rc != LuaError::OK) { |
438 | // propagate error to main state if any | 438 | // propagate error to main state if any |
@@ -481,7 +481,7 @@ LUAG_FUNC(lane_new) | |||
481 | 481 | ||
482 | // Lane main function | 482 | // Lane main function |
483 | [[maybe_unused]] int const errorHandlerCount{ _lane->pushErrorHandler() }; // L_: [fixed] args... L2: eh? | 483 | [[maybe_unused]] int const errorHandlerCount{ _lane->pushErrorHandler() }; // L_: [fixed] args... L2: eh? |
484 | LuaType const _func_type{ lua_type_as_enum(L_, kFuncIdx) }; | 484 | LuaType const _func_type{ luaG_type(L_, kFuncIdx) }; |
485 | if (_func_type == LuaType::FUNCTION) { | 485 | if (_func_type == LuaType::FUNCTION) { |
486 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: transfer lane body" << std::endl); | 486 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: transfer lane body" << std::endl); |
487 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); | 487 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); |
@@ -498,7 +498,7 @@ LUAG_FUNC(lane_new) | |||
498 | raise_luaL_error(L_, "error when parsing lane function code"); | 498 | raise_luaL_error(L_, "error when parsing lane function code"); |
499 | } | 499 | } |
500 | } else { | 500 | } else { |
501 | raise_luaL_error(L_, "Expected function, got %s", lua_typename(L_, _func_type)); | 501 | raise_luaL_error(L_, "Expected function, got %s", luaG_typename(L_, _func_type)); |
502 | } | 502 | } |
503 | STACK_CHECK(L_, 0); | 503 | STACK_CHECK(L_, 0); |
504 | STACK_CHECK(_L2, errorHandlerCount + 1); | 504 | STACK_CHECK(_L2, errorHandlerCount + 1); |
@@ -655,8 +655,8 @@ LUAG_FUNC(configure) | |||
655 | 655 | ||
656 | Universe* _U{ Universe::Get(L_) }; | 656 | Universe* _U{ Universe::Get(L_) }; |
657 | bool const _from_master_state{ _U == nullptr }; | 657 | bool const _from_master_state{ _U == nullptr }; |
658 | std::string_view const _name{ luaL_checkstringview(L_, lua_upvalueindex(1)) }; | 658 | std::string_view const _name{ luaG_checkstringview(L_, lua_upvalueindex(1)) }; |
659 | LUA_ASSERT(L_, lua_type(L_, 1) == LUA_TTABLE); | 659 | LUA_ASSERT(L_, luaG_type(L_, 1) == LuaType::TABLE); |
660 | 660 | ||
661 | STACK_GROW(L_, 4); | 661 | STACK_GROW(L_, 4); |
662 | STACK_CHECK_START_ABS(L_, 1); // L_: settings | 662 | STACK_CHECK_START_ABS(L_, 1); // L_: settings |
@@ -666,7 +666,7 @@ LUAG_FUNC(configure) | |||
666 | 666 | ||
667 | if (_U == nullptr) { | 667 | if (_U == nullptr) { |
668 | // 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... | 668 | // 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... |
669 | kLaneNameRegKey.setValue(L_, [](lua_State* L_) { std::ignore = lua_pushstringview(L_, "main"); }); | 669 | kLaneNameRegKey.setValue(L_, [](lua_State* L_) { std::ignore = luaG_pushstringview(L_, "main"); }); |
670 | 670 | ||
671 | // create the universe | 671 | // create the universe |
672 | _U = Universe::Create(L_); // L_: settings universe | 672 | _U = Universe::Create(L_); // L_: settings universe |