From 7b4ae7364703e7217044e705e42ebd356ffe8089 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Mon, 24 Jul 2023 19:17:17 +1000 Subject: [PATCH] add sb.jsonParse also rolled up some rand functions into ternary statements --- .../game/scripting/StarUtilityLuaBindings.cpp | 64 ++++--------------- 1 file changed, 14 insertions(+), 50 deletions(-) diff --git a/source/game/scripting/StarUtilityLuaBindings.cpp b/source/game/scripting/StarUtilityLuaBindings.cpp index 1bec4c9..e2c7472 100644 --- a/source/game/scripting/StarUtilityLuaBindings.cpp +++ b/source/game/scripting/StarUtilityLuaBindings.cpp @@ -18,59 +18,28 @@ struct LuaUserDataMethods { static LuaMethods make() { LuaMethods methods; - methods.registerMethod("init", - [](RandomSource& randomSource, Maybe seed) { - if (seed) - randomSource.init(*seed); - else - randomSource.init(); - }); - - methods.registerMethod("addEntropy", - [](RandomSource& randomSource, Maybe seed) { - if (seed) - randomSource.addEntropy(*seed); - else - randomSource.addEntropy(); - }); + methods.registerMethod("init", [](RandomSource& randomSource, Maybe seed) + { seed ? randomSource.init(*seed) : randomSource.init(); }); + methods.registerMethod("addEntropy", [](RandomSource& randomSource, Maybe seed) + { seed ? randomSource.addEntropy(*seed) : randomSource.addEntropy(); }); methods.registerMethodWithSignature("randu32", mem_fn(&RandomSource::randu32)); methods.registerMethodWithSignature("randu64", mem_fn(&RandomSource::randu64)); methods.registerMethodWithSignature("randi32", mem_fn(&RandomSource::randi32)); methods.registerMethodWithSignature("randi64", mem_fn(&RandomSource::randi64)); - methods.registerMethod("randf", - [](RandomSource& randomSource, Maybe arg1, Maybe arg2) { - if (arg1 && arg2) - return randomSource.randf(*arg1, *arg2); - else - return randomSource.randf(); - }); - methods.registerMethod("randd", - [](RandomSource& randomSource, Maybe arg1, Maybe arg2) { - if (arg1 && arg2) - return randomSource.randd(*arg1, *arg2); - else - return randomSource.randd(); - }); + methods.registerMethod("randf", [](RandomSource& randomSource, Maybe arg1, Maybe arg2) + { return (arg1 && arg2) ? randomSource.randf(*arg1, *arg2) : randomSource.randf(); }); + methods.registerMethod("randd", [](RandomSource& randomSource, Maybe arg1, Maybe arg2) + { return (arg1 && arg2) ? randomSource.randd(*arg1, *arg2) : randomSource.randd(); }); methods.registerMethodWithSignature("randb", mem_fn(&RandomSource::randb)); - methods.registerMethod("randInt", - [](RandomSource& randomSource, int64_t arg1, Maybe arg2) { - if (arg2) - return randomSource.randInt(arg1, *arg2); - else - return randomSource.randInt(arg1); - }); + methods.registerMethod("randInt", [](RandomSource& randomSource, int64_t arg1, Maybe arg2) + { return arg2 ? randomSource.randInt(arg1, *arg2) : randomSource.randInt(arg1); }); - methods.registerMethod("randUInt", - [](RandomSource& randomSource, uint64_t arg1, Maybe arg2) { - if (arg2) - return randomSource.randUInt(arg1, *arg2); - else - return randomSource.randUInt(arg1); - }); + methods.registerMethod("randUInt", [](RandomSource& randomSource, uint64_t arg1, Maybe arg2) + { return arg2 ? randomSource.randUInt(arg1, *arg2) : randomSource.randUInt(arg1); }); return methods; } @@ -148,15 +117,10 @@ LuaCallbacks LuaBindings::makeUtilityCallbacks() { callbacks.registerCallback("print", UtilityCallbacks::print); callbacks.registerCallback("interpolateSinEase", UtilityCallbacks::interpolateSinEase); callbacks.registerCallback("replaceTags", UtilityCallbacks::replaceTags); + callbacks.registerCallback("jsonParse", [](String const& json) { return Json::parse(json); }); callbacks.registerCallback("jsonMerge", [](Json const& a, Json const& b) { return jsonMerge(a, b); }); callbacks.registerCallback("jsonQuery", [](Json const& json, String const& path, Json const& def) { return json.query(path, def); }); - callbacks.registerCallback("makeRandomSource", - [](Maybe seed) { - if (seed) - return RandomSource(*seed); - else - return RandomSource(); - }); + callbacks.registerCallback("makeRandomSource", [](Maybe seed) { return seed ? RandomSource(*seed) : RandomSource(); }); callbacks.registerCallback("makePerlinSource", [](Json const& config) { return PerlinF(config); }); auto hash64LuaValues = [](LuaVariadic const& values) -> uint64_t {