diff --git a/src/SortingTester.cpp b/src/SortingTester.cpp index 65ec7a5..34edabf 100644 --- a/src/SortingTester.cpp +++ b/src/SortingTester.cpp @@ -3,6 +3,8 @@ SortingTester::SortingTester() : list(10) { + std::cout << "Loading lua" << std::endl; + lua.lua.open_libraries(sol::lib::coroutine, sol::lib::table); lua.lua.new_usertype("List", "size", &SortingTester::list_size, @@ -37,6 +39,16 @@ void SortingTester::load_internal() void SortingTester::populate(const populate_function& f) { + std::cout << "[List(" << list.size() << ")] [ "; for (size_t i = 0; i < list.size(); i++) + { f(i, list[i]); + if(i == list.size()-1) + { + std::cout << list[i] << " ]\n"; + break; + } + std::cout << list[i] << ", "; + } + std::flush(std::cout); } diff --git a/src/SortingTester.h b/src/SortingTester.h index d2dff5f..6b4a665 100644 --- a/src/SortingTester.h +++ b/src/SortingTester.h @@ -69,7 +69,7 @@ class SortingTester { if (list.size() <= 1) return true; - for (size_t i = 1; i < list.size(); ++i) + for (size_t i = 1; i < list.size(); i++) { if (list[i - 1] > list[i]) return false; @@ -140,6 +140,18 @@ public: std::terminate(); } + std::cout << "[sorted: List(" << list.size() << ")] [ "; + for (size_t i = 0; i < list.size(); i++) + { + if(i == list.size()-1) + { + std::cout << list[i] << " ]\n"; + break; + } + std::cout << list[i] << ", "; + } + std::flush(std::cout); + result.count_comparisons = result.count_equal + result.count_greater + result.count_less; active_result = nullptr; diff --git a/src/internal_script.hpp b/src/internal_script.hpp index 3814851..6055163 100644 --- a/src/internal_script.hpp +++ b/src/internal_script.hpp @@ -3,10 +3,10 @@ inline const char* std_intern_sorting_script = R"( -- bubble sort function bubble_sort() - isSorted = false - while isSorted == false do - movedElements = 0 - for x=1, list:size(), 1 do + local isSorted = false + while not isSorted do + local movedElements = 0 + for x = 0, list:size() - 2 do if list:greater(x, x+1) then movedElements = movedElements + 1 list:swap(x, x+1) diff --git a/src/lua/safesol.h b/src/lua/safesol.h index cfc23d3..14f6dea 100644 --- a/src/lua/safesol.h +++ b/src/lua/safesol.h @@ -37,12 +37,16 @@ public: template> LuaResultType run_on_caller(const std::string& function_name, const Caller& caller, Args&&... args) { + std::cout << "Looking for function: " << function_name << std::endl; + auto function = lua[function_name]; if (!function.valid()) { std::cout << "Error: function " << function_name << " not found" << std::endl; return LuaResultType::RUN_ERROR; } - + + std::cout << "Found function, attempting to run" << std::endl; + auto result = caller(function, std::forward(args)...); if (!result.valid()) { sol::error err = result; diff --git a/src/main.cpp b/src/main.cpp index 18caba6..dd033f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,19 +79,7 @@ int main(int argc, char** argv) std::cout << "\tCount equal: " << result.count_equal << std::endl; std::cout << "\n\n"; - - - result = tester.run("do_nothing"); - - std::cout << "Time: " << result.timer.seconds << " seconds" << std::endl; - std::cout << "Difftime: " << result.timer.difftime << std::endl; - - std::cout << "Count swaps: " << result.count_swaps << std::endl; - std::cout << "Count comparisons: " << result.count_comparisons << std::endl; - std::cout << "\tCount greater: " << result.count_greater << std::endl; - std::cout << "\tCount less: " << result.count_less << std::endl; - std::cout << "\tCount equal: " << result.count_equal << "\n\n"; std::cout << "\nPress any key to exit..." << std::endl; getchar();