diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-14 16:19:54 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-14 16:19:54 +0200 |
commit | 53eef99942ecca7b1dc43ec6b35d09a5fe6b1b1b (patch) | |
tree | 1c76b3d44a184b04647f928645c2872ea0e2b939 /src | |
parent | 7d24fb298abbc517c1c0ca185087fd9233a3b687 (diff) | |
download | lanes-53eef99942ecca7b1dc43ec6b35d09a5fe6b1b1b.tar.gz lanes-53eef99942ecca7b1dc43ec6b35d09a5fe6b1b1b.tar.bz2 lanes-53eef99942ecca7b1dc43ec6b35d09a5fe6b1b1b.zip |
Progressively applying the coding rules
Diffstat (limited to 'src')
-rw-r--r-- | src/intercopycontext.cpp | 12 | ||||
-rw-r--r-- | src/lane.cpp | 6 | ||||
-rw-r--r-- | src/lanes.cpp | 12 | ||||
-rw-r--r-- | src/state.cpp | 4 | ||||
-rw-r--r-- | src/tools.cpp | 12 |
5 files changed, 23 insertions, 23 deletions
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 8dd914c..6e5d1d8 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
@@ -96,8 +96,8 @@ THE SOFTWARE. | |||
96 | lua_rawget(L_, -2); // L_: ... v ... {} "f.q.n" | 96 | lua_rawget(L_, -2); // L_: ... v ... {} "f.q.n" |
97 | } | 97 | } |
98 | char const* _fqn{ lua_tolstring(L_, -1, len_) }; | 98 | char const* _fqn{ lua_tolstring(L_, -1, len_) }; |
99 | DEBUGSPEW_CODE(Universe* const U = universe_get(L_)); | 99 | DEBUGSPEW_CODE(Universe* const _U = universe_get(L_)); |
100 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "function [C] %s \n" INDENT_END(U), _fqn)); | 100 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "function [C] %s \n" INDENT_END(_U), _fqn)); |
101 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database | 101 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database |
102 | lua_pop(L_, (mode_ == LookupMode::FromKeeper) ? 1 : 2); // L_: ... v ... | 102 | lua_pop(L_, (mode_ == LookupMode::FromKeeper) ? 1 : 2); // L_: ... v ... |
103 | STACK_CHECK(L_, 0); | 103 | STACK_CHECK(L_, 0); |
@@ -878,7 +878,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
878 | lua_call(L2, 3, 0); // L2: ... u | 878 | lua_call(L2, 3, 0); // L2: ... u |
879 | } else { // regular function | 879 | } else { // regular function |
880 | DEBUGSPEW_CODE(fprintf(stderr, "FUNCTION %s\n", name)); | 880 | DEBUGSPEW_CODE(fprintf(stderr, "FUNCTION %s\n", name)); |
881 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); | 881 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
882 | copy_cached_func(); // L2: ... f | 882 | copy_cached_func(); // L2: ... f |
883 | } | 883 | } |
884 | STACK_CHECK(L2, 1); | 884 | STACK_CHECK(L2, 1); |
@@ -1080,7 +1080,7 @@ static char const* vt_names[] = { | |||
1080 | STACK_CHECK_START_REL(L2, 0); | 1080 | STACK_CHECK_START_REL(L2, 0); |
1081 | 1081 | ||
1082 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "inter_copy_one()\n" INDENT_END(U))); | 1082 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "inter_copy_one()\n" INDENT_END(U))); |
1083 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); | 1083 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
1084 | 1084 | ||
1085 | LuaType _val_type{ lua_type_as_enum(L1, L1_i) }; | 1085 | LuaType _val_type{ lua_type_as_enum(L1, L1_i) }; |
1086 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s %s: " INDENT_END(U), lua_type_names[static_cast<int>(_val_type)], vt_names[static_cast<int>(vt)])); | 1086 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s %s: " INDENT_END(U), lua_type_names[static_cast<int>(_val_type)], vt_names[static_cast<int>(vt)])); |
@@ -1205,7 +1205,7 @@ static char const* vt_names[] = { | |||
1205 | lua_pop(L1, 1); | 1205 | lua_pop(L1, 1); |
1206 | } else { | 1206 | } else { |
1207 | { | 1207 | { |
1208 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); | 1208 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
1209 | _result = inter_move(1); // moves the entry to L2 | 1209 | _result = inter_move(1); // moves the entry to L2 |
1210 | STACK_CHECK(L1, 0); | 1210 | STACK_CHECK(L1, 0); |
1211 | } | 1211 | } |
@@ -1235,7 +1235,7 @@ static char const* vt_names[] = { | |||
1235 | LUA_ASSERT(L1, vt == VT::NORMAL); | 1235 | LUA_ASSERT(L1, vt == VT::NORMAL); |
1236 | 1236 | ||
1237 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "InterCopyContext::inter_copy()\n" INDENT_END(U))); | 1237 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "InterCopyContext::inter_copy()\n" INDENT_END(U))); |
1238 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); | 1238 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
1239 | 1239 | ||
1240 | int const _top_L1{ lua_gettop(L1) }; | 1240 | int const _top_L1{ lua_gettop(L1) }; |
1241 | if (n_ > _top_L1) { | 1241 | if (n_ > _top_L1) { |
diff --git a/src/lane.cpp b/src/lane.cpp index a03412d..bc82291 100644 --- a/src/lane.cpp +++ b/src/lane.cpp | |||
@@ -630,7 +630,7 @@ static void lane_main(Lane* lane_) | |||
630 | if (lane_->status == Lane::Pending) { // nothing wrong happened during preparation, we can work | 630 | if (lane_->status == Lane::Pending) { // nothing wrong happened during preparation, we can work |
631 | // At this point, the lane function and arguments are on the stack | 631 | // At this point, the lane function and arguments are on the stack |
632 | int const nargs{ lua_gettop(_L) - 1 }; | 632 | int const nargs{ lua_gettop(_L) - 1 }; |
633 | DEBUGSPEW_CODE(Universe* U = universe_get(_L)); | 633 | DEBUGSPEW_CODE(Universe* _U = universe_get(_L)); |
634 | lane_->status = Lane::Running; // Pending -> Running | 634 | lane_->status = Lane::Running; // Pending -> Running |
635 | 635 | ||
636 | // Tie "set_finalizer()" to the state | 636 | // Tie "set_finalizer()" to the state |
@@ -670,11 +670,11 @@ static void lane_main(Lane* lane_) | |||
670 | // in case of error and if it exists, fetch stack trace from registry and push it | 670 | // in case of error and if it exists, fetch stack trace from registry and push it |
671 | push_stack_trace(_L, _rc, 1); // L: retvals|error [trace] | 671 | push_stack_trace(_L, _rc, 1); // L: retvals|error [trace] |
672 | 672 | ||
673 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "Lane %p body: %s (%s)\n" INDENT_END(U), _L, get_errcode_name(_rc), kCancelError.equals(_L, 1) ? "cancelled" : lua_typename(_L, lua_type(_L, 1)))); | 673 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "Lane %p body: %s (%s)\n" INDENT_END(_U), _L, get_errcode_name(_rc), kCancelError.equals(_L, 1) ? "cancelled" : lua_typename(_L, lua_type(_L, 1)))); |
674 | // Call finalizers, if the script has set them up. | 674 | // Call finalizers, if the script has set them up. |
675 | // | 675 | // |
676 | int _rc2{ run_finalizers(_L, _rc) }; | 676 | int _rc2{ run_finalizers(_L, _rc) }; |
677 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "Lane %p finalizer: %s\n" INDENT_END(U), _L, get_errcode_name(_rc2))); | 677 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "Lane %p finalizer: %s\n" INDENT_END(_U), _L, get_errcode_name(_rc2))); |
678 | if (_rc2 != LUA_OK) { // Error within a finalizer! | 678 | if (_rc2 != LUA_OK) { // Error within a finalizer! |
679 | // the finalizer generated an error, and left its own error message [and stack trace] on the stack | 679 | // the finalizer generated an error, and left its own error message [and stack trace] on the stack |
680 | _rc = _rc2; // we're overruling the earlier script error or normal return | 680 | _rc = _rc2; // we're overruling the earlier script error or normal return |
diff --git a/src/lanes.cpp b/src/lanes.cpp index a775895..6a84422 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -193,12 +193,12 @@ LUAG_FUNC(register) | |||
193 | // ignore extra parameters, just in case | 193 | // ignore extra parameters, just in case |
194 | lua_settop(L_, 2); | 194 | lua_settop(L_, 2); |
195 | luaL_argcheck(L_, (_mod_type == LuaType::TABLE) || (_mod_type == LuaType::FUNCTION), 2, "unexpected module type"); | 195 | luaL_argcheck(L_, (_mod_type == LuaType::TABLE) || (_mod_type == LuaType::FUNCTION), 2, "unexpected module type"); |
196 | DEBUGSPEW_CODE(Universe* U = universe_get(L_)); | 196 | DEBUGSPEW_CODE(Universe* _U = universe_get(L_)); |
197 | STACK_CHECK_START_REL(L_, 0); // "name" mod_table | 197 | STACK_CHECK_START_REL(L_, 0); // "name" mod_table |
198 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lanes.register %s BEGIN\n" INDENT_END(U), _name)); | 198 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lanes.register %s BEGIN\n" INDENT_END(_U), _name)); |
199 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); | 199 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); |
200 | populate_func_lookup_table(L_, -1, _name); | 200 | populate_func_lookup_table(L_, -1, _name); |
201 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lanes.register %s END\n" INDENT_END(U), _name)); | 201 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lanes.register %s END\n" INDENT_END(_U), _name)); |
202 | STACK_CHECK(L_, 0); | 202 | STACK_CHECK(L_, 0); |
203 | return 0; | 203 | return 0; |
204 | } | 204 | } |
@@ -375,7 +375,7 @@ LUAG_FUNC(lane_new) | |||
375 | if (_required_idx != 0) { | 375 | if (_required_idx != 0) { |
376 | int _nbRequired{ 1 }; | 376 | int _nbRequired{ 1 }; |
377 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: require 'required' list\n" INDENT_END(_U))); | 377 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: require 'required' list\n" INDENT_END(_U))); |
378 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ _U }); | 378 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); |
379 | // should not happen, was checked in lanes.lua before calling lane_new() | 379 | // should not happen, was checked in lanes.lua before calling lane_new() |
380 | if (lua_type(L_, _required_idx) != LUA_TTABLE) { | 380 | if (lua_type(L_, _required_idx) != LUA_TTABLE) { |
381 | raise_luaL_error(L_, "expected required module list as a table, got %s", luaL_typename(L_, _required_idx)); | 381 | raise_luaL_error(L_, "expected required module list as a table, got %s", luaL_typename(L_, _required_idx)); |
@@ -701,7 +701,7 @@ LUAG_FUNC(configure) | |||
701 | STACK_CHECK_START_ABS(L_, 1); // L_: settings | 701 | STACK_CHECK_START_ABS(L_, 1); // L_: settings |
702 | 702 | ||
703 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%p: lanes.configure() BEGIN\n" INDENT_END(_U), L_)); | 703 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%p: lanes.configure() BEGIN\n" INDENT_END(_U), L_)); |
704 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ _U }); | 704 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); |
705 | 705 | ||
706 | if (_U == nullptr) { | 706 | if (_U == nullptr) { |
707 | _U = universe_create(L_); // L_: settings universe | 707 | _U = universe_create(L_); // L_: settings universe |
diff --git a/src/state.cpp b/src/state.cpp index 7309e50..56ac74b 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -339,7 +339,7 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_) | |||
339 | } | 339 | } |
340 | 340 | ||
341 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "luaG_newstate()\n" INDENT_END(U_))); | 341 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "luaG_newstate()\n" INDENT_END(U_))); |
342 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U_ }); | 342 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U_ }); |
343 | 343 | ||
344 | // copy settings (for example because it may contain a Lua on_state_create function) | 344 | // copy settings (for example because it may contain a Lua on_state_create function) |
345 | copy_one_time_settings(U_, from_, _L); | 345 | copy_one_time_settings(U_, from_, _L); |
@@ -361,7 +361,7 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_) | |||
361 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "opening base library\n" INDENT_END(U_))); | 361 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "opening base library\n" INDENT_END(U_))); |
362 | #if LUA_VERSION_NUM >= 502 | 362 | #if LUA_VERSION_NUM >= 502 |
363 | // open base library the same way as in luaL_openlibs() | 363 | // open base library the same way as in luaL_openlibs() |
364 | luaL_requiref(_L, "_G", luaopen_base, 1); | 364 | luaL_requiref(_L, LUA_GNAME, luaopen_base, 1); |
365 | lua_pop(_L, 1); | 365 | lua_pop(_L, 1); |
366 | #else // LUA_VERSION_NUM | 366 | #else // LUA_VERSION_NUM |
367 | lua_pushcfunction(_L, luaopen_base); | 367 | lua_pushcfunction(_L, luaopen_base); |
diff --git a/src/tools.cpp b/src/tools.cpp index 0cfe1ab..a70fdc9 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -130,7 +130,7 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L | |||
130 | 130 | ||
131 | DEBUGSPEW_CODE(char const* _newName); | 131 | DEBUGSPEW_CODE(char const* _newName); |
132 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "update_lookup_entry()\n" INDENT_END(U_))); | 132 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "update_lookup_entry()\n" INDENT_END(U_))); |
133 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U_ }); | 133 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U_ }); |
134 | 134 | ||
135 | STACK_CHECK_START_REL(L_, 0); | 135 | STACK_CHECK_START_REL(L_, 0); |
136 | // first, raise an error if the function is already known | 136 | // first, raise an error if the function is already known |
@@ -198,7 +198,7 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) | |||
198 | // slot dbIdx_ + 2 contains a cache that stores all already visited tables to avoid infinite recursion loops | 198 | // slot dbIdx_ + 2 contains a cache that stores all already visited tables to avoid infinite recursion loops |
199 | int const _cache{ dbIdx_ + 2 }; | 199 | int const _cache{ dbIdx_ + 2 }; |
200 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "populate_func_lookup_table_recur()\n" INDENT_END(U_))); | 200 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "populate_func_lookup_table_recur()\n" INDENT_END(U_))); |
201 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U_ }); | 201 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U_ }); |
202 | 202 | ||
203 | STACK_GROW(L_, 6); | 203 | STACK_GROW(L_, 6); |
204 | // slot i_ contains a table where we search for functions (or a full userdata with a metatable) | 204 | // slot i_ contains a table where we search for functions (or a full userdata with a metatable) |
@@ -264,9 +264,9 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) | |||
264 | ++depth_; | 264 | ++depth_; |
265 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil | 265 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil |
266 | while (lua_next(L_, breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} | 266 | while (lua_next(L_, breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} |
267 | DEBUGSPEW_CODE(char const* key = (lua_type(L_, -2) == LUA_TSTRING) ? lua_tostring(L_, -2) : "not a string"); | 267 | DEBUGSPEW_CODE(char const* _key = (lua_type(L_, -2) == LUA_TSTRING) ? lua_tostring(L_, -2) : "not a string"); |
268 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "table '%s'\n" INDENT_END(U_), key)); | 268 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "table '%s'\n" INDENT_END(U_), _key)); |
269 | DEBUGSPEW_CODE(DebugSpewIndentScope scope2{ U_ }); | 269 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ U_ }); |
270 | // un-visit this table in case we do need to process it | 270 | // un-visit this table in case we do need to process it |
271 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} | 271 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} |
272 | lua_rawget(L_, _cache); // L_: ... {i_} {bfc} k {} n | 272 | lua_rawget(L_, _cache); // L_: ... {i_} {bfc} k {} n |
@@ -505,7 +505,7 @@ int luaG_nameof(lua_State* L_) | |||
505 | // push a table whose contents are strings that, when concatenated, produce unique name | 505 | // push a table whose contents are strings that, when concatenated, produce unique name |
506 | lua_newtable(L_); // L_: o nil {c} {fqn} | 506 | lua_newtable(L_); // L_: o nil {c} {fqn} |
507 | // {fqn}[1] = "_G" | 507 | // {fqn}[1] = "_G" |
508 | lua_pushliteral(L_, "_G"); // L_: o nil {c} {fqn} "_G" | 508 | lua_pushliteral(L_, LUA_GNAME); // L_: o nil {c} {fqn} "_G" |
509 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} | 509 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} |
510 | // this is where we start the search | 510 | // this is where we start the search |
511 | lua_pushglobaltable(L_); // L_: o nil {c} {fqn} _G | 511 | lua_pushglobaltable(L_); // L_: o nil {c} {fqn} _G |