diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-07 11:46:25 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-07 11:46:25 +0200 |
commit | ee32d4281a5e59ce81d7f38f86a49fa8ff64d2c3 (patch) | |
tree | 68c0d74ac40c6ee098abf606e3d660a862acf04f /src/lanes.cpp | |
parent | 35d7a6bb691d7e0564cda324b3d724caf4901545 (diff) | |
download | lanes-ee32d4281a5e59ce81d7f38f86a49fa8ff64d2c3.tar.gz lanes-ee32d4281a5e59ce81d7f38f86a49fa8ff64d2c3.tar.bz2 lanes-ee32d4281a5e59ce81d7f38f86a49fa8ff64d2c3.zip |
Boyscouting some luaG_ functions
Diffstat (limited to 'src/lanes.cpp')
-rw-r--r-- | src/lanes.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp index 96d4ecd..a7631bb 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -169,7 +169,7 @@ LUAG_FUNC(sleep) | |||
169 | lua_pushcfunction(L_, LG_linda_receive); // L_: duration|nil receive() | 169 | lua_pushcfunction(L_, LG_linda_receive); // L_: duration|nil receive() |
170 | STACK_CHECK_START_REL(L_, 0); // we pushed the function we intend to call, now prepare the arguments | 170 | STACK_CHECK_START_REL(L_, 0); // we pushed the function we intend to call, now prepare the arguments |
171 | _U->timerLinda->push(L_); // L_: duration|nil receive() timerLinda | 171 | _U->timerLinda->push(L_); // L_: duration|nil receive() timerLinda |
172 | if (luaG_tostringview(L_, 1) == "indefinitely") { | 172 | if (luaG_tostring(L_, 1) == "indefinitely") { |
173 | lua_pushnil(L_); // L_: duration? receive() timerLinda nil | 173 | lua_pushnil(L_); // L_: duration? receive() timerLinda nil |
174 | } else if (lua_isnoneornil(L_, 1)) { | 174 | } else if (lua_isnoneornil(L_, 1)) { |
175 | lua_pushnumber(L_, 0); // L_: duration? receive() timerLinda 0 | 175 | lua_pushnumber(L_, 0); // L_: duration? receive() timerLinda 0 |
@@ -179,7 +179,7 @@ LUAG_FUNC(sleep) | |||
179 | else { | 179 | else { |
180 | lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration | 180 | lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration |
181 | } | 181 | } |
182 | std::ignore = luaG_pushstringview(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key | 182 | std::ignore = luaG_pushstring(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key |
183 | STACK_CHECK(L_, 3); // 3 arguments ready | 183 | STACK_CHECK(L_, 3); // 3 arguments ready |
184 | lua_call(L_, 3, LUA_MULTRET); // timerLinda:receive(duration,key) // L_: duration? result... | 184 | lua_call(L_, 3, LUA_MULTRET); // timerLinda:receive(duration,key) // L_: duration? result... |
185 | return lua_gettop(L_) - 1; | 185 | return lua_gettop(L_) - 1; |
@@ -193,7 +193,7 @@ LUAG_FUNC(sleep) | |||
193 | // upvalue[1]: _G.require | 193 | // upvalue[1]: _G.require |
194 | LUAG_FUNC(require) | 194 | LUAG_FUNC(require) |
195 | { | 195 | { |
196 | std::string_view const _name{ luaG_tostringview(L_, 1) }; // L_: "name" ... | 196 | std::string_view const _name{ luaG_tostring(L_, 1) }; // L_: "name" ... |
197 | int const _nargs{ lua_gettop(L_) }; | 197 | int const _nargs{ lua_gettop(L_) }; |
198 | DEBUGSPEW_CODE(Universe * _U{ Universe::Get(L_) }); | 198 | DEBUGSPEW_CODE(Universe * _U{ Universe::Get(L_) }); |
199 | STACK_CHECK_START_REL(L_, 0); | 199 | STACK_CHECK_START_REL(L_, 0); |
@@ -215,7 +215,7 @@ LUAG_FUNC(require) | |||
215 | // lanes.register( "modname", module) | 215 | // lanes.register( "modname", module) |
216 | LUAG_FUNC(register) | 216 | LUAG_FUNC(register) |
217 | { | 217 | { |
218 | std::string_view const _name{ luaG_checkstringview(L_, 1) }; | 218 | std::string_view const _name{ luaG_checkstring(L_, 1) }; |
219 | LuaType const _mod_type{ luaG_type(L_, 2) }; | 219 | LuaType const _mod_type{ luaG_type(L_, 2) }; |
220 | // ignore extra parameters, just in case | 220 | // ignore extra parameters, just in case |
221 | lua_settop(L_, 2); | 221 | lua_settop(L_, 2); |
@@ -265,7 +265,7 @@ LUAG_FUNC(lane_new) | |||
265 | Universe* const _U{ Universe::Get(L_) }; | 265 | Universe* const _U{ Universe::Get(L_) }; |
266 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: setup" << std::endl); | 266 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: setup" << std::endl); |
267 | 267 | ||
268 | std::optional<std::string_view> _libs_str{ lua_isnil(L_, kLibsIdx) ? std::nullopt : std::make_optional(luaG_tostringview(L_, kLibsIdx)) }; | 268 | std::optional<std::string_view> _libs_str{ lua_isnil(L_, kLibsIdx) ? std::nullopt : std::make_optional(luaG_tostring(L_, kLibsIdx)) }; |
269 | lua_State* const _L2{ state::NewLaneState(_U, SourceState{ L_ }, _libs_str) }; // L_: [fixed] ... L2: | 269 | lua_State* const _L2{ state::NewLaneState(_U, SourceState{ L_ }, _libs_str) }; // L_: [fixed] ... L2: |
270 | STACK_CHECK_START_REL(_L2, 0); | 270 | STACK_CHECK_START_REL(_L2, 0); |
271 | 271 | ||
@@ -318,7 +318,7 @@ LUAG_FUNC(lane_new) | |||
318 | DEBUGSPEW_CODE(DebugSpew(lane->U) << "lane_new: preparing lane userdata" << std::endl); | 318 | DEBUGSPEW_CODE(DebugSpew(lane->U) << "lane_new: preparing lane userdata" << std::endl); |
319 | STACK_CHECK_START_REL(L, 0); | 319 | STACK_CHECK_START_REL(L, 0); |
320 | // a Lane full userdata needs a single uservalue | 320 | // a Lane full userdata needs a single uservalue |
321 | Lane** const _ud{ lua_newuserdatauv<Lane*>(L, 1) }; // L: ... lane | 321 | Lane** const _ud{ luaG_newuserdatauv<Lane*>(L, 1) }; // L: ... lane |
322 | *_ud = lane; // don't forget to store the pointer in the userdata! | 322 | *_ud = lane; // don't forget to store the pointer in the userdata! |
323 | 323 | ||
324 | // Set metatable for the userdata | 324 | // Set metatable for the userdata |
@@ -344,18 +344,16 @@ LUAG_FUNC(lane_new) | |||
344 | lua_State* _L2{ lane->L }; | 344 | lua_State* _L2{ lane->L }; |
345 | STACK_CHECK_START_REL(_L2, 0); | 345 | STACK_CHECK_START_REL(_L2, 0); |
346 | int const _name_idx{ lua_isnoneornil(L, kNameIdx) ? 0 : kNameIdx }; | 346 | int const _name_idx{ lua_isnoneornil(L, kNameIdx) ? 0 : kNameIdx }; |
347 | std::string_view const _debugName{ (_name_idx > 0) ? luaG_tostringview(L, _name_idx) : std::string_view{} }; | 347 | std::string_view const _debugName{ (_name_idx > 0) ? luaG_tostring(L, _name_idx) : std::string_view{} }; |
348 | if (!_debugName.empty()) | 348 | if (!_debugName.empty()) |
349 | { | 349 | { |
350 | if (_debugName != "auto") { | 350 | if (_debugName != "auto") { |
351 | std::ignore = luaG_pushstringview(_L2, _debugName); // L: ... lane L2: "<name>" | 351 | std::ignore = luaG_pushstring(_L2, _debugName); // L: ... lane L2: "<name>" |
352 | } else { | 352 | } else { |
353 | lua_Debug _ar; | 353 | lua_Debug _ar; |
354 | lua_pushvalue(L, 1); // L: ... lane func | 354 | lua_pushvalue(L, 1); // L: ... lane func |
355 | lua_getinfo(L, ">S", &_ar); // L: ... lane | 355 | lua_getinfo(L, ">S", &_ar); // L: ... lane |
356 | std::ignore = luaG_pushstringview( | 356 | std::ignore = luaG_pushstring(_L2, "%s:%d", _ar.short_src, _ar.linedefined); // L: ... lane L2: "<name>" |
357 | _L2, "%s:%d", _ar.short_src, _ar.linedefined | ||
358 | ); // L: ... lane L2: "<name>" | ||
359 | } | 357 | } |
360 | lane->changeDebugName(-1); | 358 | lane->changeDebugName(-1); |
361 | lua_pop(_L2, 1); // L: ... lane L2: | 359 | lua_pop(_L2, 1); // L: ... lane L2: |
@@ -424,7 +422,7 @@ LUAG_FUNC(lane_new) | |||
424 | raise_luaL_error(L_, "required module list should be a list of strings"); | 422 | raise_luaL_error(L_, "required module list should be a list of strings"); |
425 | } else { | 423 | } else { |
426 | // require the module in the target state, and populate the lookup table there too | 424 | // require the module in the target state, and populate the lookup table there too |
427 | std::string_view const _name{ luaG_tostringview(L_, -1) }; | 425 | std::string_view const _name{ luaG_tostring(L_, -1) }; |
428 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: require '" << _name << "'" << std::endl); | 426 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: require '" << _name << "'" << std::endl); |
429 | 427 | ||
430 | // require the module in the target lane | 428 | // require the module in the target lane |
@@ -433,7 +431,7 @@ LUAG_FUNC(lane_new) | |||
433 | lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2: | 431 | lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2: |
434 | raise_luaL_error(L_, "cannot pre-require modules without loading 'package' library first"); | 432 | raise_luaL_error(L_, "cannot pre-require modules without loading 'package' library first"); |
435 | } else { | 433 | } else { |
436 | std::ignore = luaG_pushstringview(_L2, _name); // L_: [fixed] args... n "modname" L2: require() name | 434 | std::ignore = luaG_pushstring(_L2, _name); // L_: [fixed] args... n "modname" L2: require() name |
437 | LuaError const _rc{ lua_pcall(_L2, 1, 1, 0) }; // L_: [fixed] args... n "modname" L2: ret/errcode | 435 | LuaError const _rc{ lua_pcall(_L2, 1, 1, 0) }; // L_: [fixed] args... n "modname" L2: ret/errcode |
438 | if (_rc != LuaError::OK) { | 436 | if (_rc != LuaError::OK) { |
439 | // propagate error to main state if any | 437 | // propagate error to main state if any |
@@ -656,7 +654,7 @@ LUAG_FUNC(configure) | |||
656 | 654 | ||
657 | Universe* _U{ Universe::Get(L_) }; | 655 | Universe* _U{ Universe::Get(L_) }; |
658 | bool const _from_master_state{ _U == nullptr }; | 656 | bool const _from_master_state{ _U == nullptr }; |
659 | std::string_view const _name{ luaG_checkstringview(L_, lua_upvalueindex(1)) }; | 657 | std::string_view const _name{ luaG_checkstring(L_, lua_upvalueindex(1)) }; |
660 | LUA_ASSERT(L_, luaG_type(L_, 1) == LuaType::TABLE); | 658 | LUA_ASSERT(L_, luaG_type(L_, 1) == LuaType::TABLE); |
661 | 659 | ||
662 | STACK_GROW(L_, 4); | 660 | STACK_GROW(L_, 4); |
@@ -667,7 +665,7 @@ LUAG_FUNC(configure) | |||
667 | 665 | ||
668 | if (_U == nullptr) { | 666 | if (_U == nullptr) { |
669 | // 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... | 667 | // 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... |
670 | kLaneNameRegKey.setValue(L_, [](lua_State* L_) { std::ignore = luaG_pushstringview(L_, "main"); }); | 668 | kLaneNameRegKey.setValue(L_, [](lua_State* L_) { std::ignore = luaG_pushstring(L_, "main"); }); |
671 | 669 | ||
672 | // create the universe | 670 | // create the universe |
673 | _U = Universe::Create(L_); // L_: settings universe | 671 | _U = Universe::Create(L_); // L_: settings universe |
@@ -707,7 +705,7 @@ LUAG_FUNC(configure) | |||
707 | lua_pushcclosure(L_, LG_require, 1); // L_: settings M lanes.require | 705 | lua_pushcclosure(L_, LG_require, 1); // L_: settings M lanes.require |
708 | lua_setfield(L_, -2, "require"); // L_: settings M | 706 | lua_setfield(L_, -2, "require"); // L_: settings M |
709 | 707 | ||
710 | std::ignore = luaG_pushstringview( | 708 | std::ignore = luaG_pushstring( |
711 | L_, | 709 | L_, |
712 | "%d.%d.%d", | 710 | "%d.%d.%d", |
713 | LANES_VERSION_MAJOR, | 711 | LANES_VERSION_MAJOR, |