Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/utility/game_repl.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
commit6352e8e3196f78388b6c771073f9e03eaa612673 (patch)
treee23772f79a7fbc41bc9108951e9e136857484bf4 /source/utility/game_repl.cpp
parent6741a057e5639280d85d0f88ba26f000baa58f61 (diff)
everything everywhere
all at once
Diffstat (limited to 'source/utility/game_repl.cpp')
-rw-r--r--source/utility/game_repl.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/source/utility/game_repl.cpp b/source/utility/game_repl.cpp
new file mode 100644
index 0000000..e52fb07
--- /dev/null
+++ b/source/utility/game_repl.cpp
@@ -0,0 +1,53 @@
+#include "StarRootLoader.hpp"
+#include "StarRootLuaBindings.hpp"
+#include "StarUtilityLuaBindings.hpp"
+#include "StarRootLuaBindings.hpp"
+
+using namespace Star;
+
+int main(int argc, char** argv) {
+ RootLoader rootLoader({{}, {}, {}, LogLevel::Error, false, {}});
+ RootUPtr root;
+ OptionParser::Options options;
+ tie(root, options) = rootLoader.commandInitOrDie(argc, argv);
+
+ auto engine = LuaEngine::create(true);
+ auto context = engine->createContext();
+ context.setCallbacks("sb", LuaBindings::makeUtilityCallbacks());
+ context.setCallbacks("root", LuaBindings::makeRootCallbacks());
+
+ String code;
+ bool continuation = false;
+ while (!std::cin.eof()) {
+ auto getline = [](std::istream& stream) -> String {
+ std::string line;
+ std::getline(stream, line);
+ return String(move(line));
+ };
+
+ if (continuation) {
+ std::cout << ">> ";
+ std::cout.flush();
+ code += getline(std::cin);
+ code += '\n';
+ } else {
+ std::cout << "> ";
+ std::cout.flush();
+ code = getline(std::cin);
+ code += '\n';
+ }
+
+ try {
+ auto result = context.eval<LuaVariadic<LuaValue>>(code);
+ for (auto r : result)
+ coutf("%s\n", r);
+ continuation = false;
+ } catch (LuaIncompleteStatementException const&) {
+ continuation = true;
+ } catch (std::exception const& e) {
+ coutf("Error: %s\n", outputException(e, false));
+ continuation = false;
+ }
+ }
+ return 0;
+}