mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-12 22:39:09 -05:00
Make use of C++17 features in LuaConsole and filesystem walking
This commit is contained in:
+1
-1
Submodule ext/ghoul updated: 5309bfcb56...9f27e93d41
@@ -52,9 +52,7 @@ namespace {
|
||||
// A high number is chosen since we didn't have a version number before
|
||||
// any small number might also be equal to the console history length
|
||||
|
||||
// @CPP17
|
||||
//const uint64_t CurrentVersion = 0xFEEE'FEEE'0000'0001;
|
||||
const uint64_t CurrentVersion = 0xFEEEFEEE00000001;
|
||||
const uint64_t CurrentVersion = 0xFEEE'FEEE'0000'0001;
|
||||
|
||||
const openspace::Key CommandInputButton = openspace::Key::GraveAccent;
|
||||
|
||||
@@ -750,7 +748,7 @@ void LuaConsole::render() {
|
||||
res.y - HistoryFontSize * 1.5f + _fullHeight - _currentHeight
|
||||
);
|
||||
|
||||
// @CPP17: Replace with array_view
|
||||
// @CPP: Replace with array_view
|
||||
std::vector<std::string> commandSubset;
|
||||
if (_commandsHistory.size() < static_cast<size_t>(_historyLength)) {
|
||||
commandSubset = _commandsHistory;
|
||||
|
||||
@@ -30,16 +30,9 @@ namespace luascriptfunctions {
|
||||
|
||||
namespace {
|
||||
|
||||
using walkFunc = std::vector<std::string>(ghoul::filesystem::Directory::*)(
|
||||
ghoul::filesystem::Directory::Recursive, ghoul::filesystem::Directory::Sort) const;
|
||||
|
||||
// Defining a common walk function that works off a pointer-to-member function (defined
|
||||
// above) allows us to easily reuse this code
|
||||
int walkCommon(lua_State* L, walkFunc func) {
|
||||
// @CPP17 Replace with std::invoke
|
||||
#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember))
|
||||
|
||||
using namespace ghoul::filesystem;
|
||||
// Defining a common walk function that works off a pointer-to-member function
|
||||
template <typename Func>
|
||||
int walkCommon(lua_State* L, Func func) {
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments < 1 || nArguments > 3) {
|
||||
return luaL_error(L, "Expected %i-%i arguments, got %i", 1, 3, nArguments);
|
||||
@@ -49,29 +42,35 @@ int walkCommon(lua_State* L, walkFunc func) {
|
||||
if (nArguments == 1) {
|
||||
// Only the path was passed
|
||||
const std::string path = luaL_checkstring(L, -1);
|
||||
result = CALL_MEMBER_FN(Directory(path), func)(
|
||||
result = std::invoke(
|
||||
func,
|
||||
ghoul::filesystem::Directory(path),
|
||||
ghoul::filesystem::Directory::Recursive::No,
|
||||
ghoul::filesystem::Directory::Sort::No
|
||||
);
|
||||
);
|
||||
}
|
||||
else if (nArguments == 2) {
|
||||
// The path and the recursive value were passed
|
||||
const std::string path = luaL_checkstring(L, -2);
|
||||
const bool recursive = lua_toboolean(L, -1) != 0;
|
||||
result = CALL_MEMBER_FN(Directory(path), func)(
|
||||
result = std::invoke(
|
||||
func,
|
||||
ghoul::filesystem::Directory(path),
|
||||
ghoul::filesystem::Directory::Recursive(recursive),
|
||||
ghoul::filesystem::Directory::Sort::No
|
||||
);
|
||||
);
|
||||
}
|
||||
else if (nArguments == 3) {
|
||||
// All three arguments were passed
|
||||
const std::string path = luaL_checkstring(L, -3);
|
||||
const bool recursive = lua_toboolean(L, -2) != 0;
|
||||
const bool sorted = lua_toboolean(L, -1) != 0;
|
||||
result = CALL_MEMBER_FN(Directory(path), func)(
|
||||
result = std::invoke(
|
||||
func,
|
||||
ghoul::filesystem::Directory(path),
|
||||
ghoul::filesystem::Directory::Recursive(recursive),
|
||||
ghoul::filesystem::Directory::Sort(sorted)
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
// Copy values into the lua_State
|
||||
|
||||
Reference in New Issue
Block a user