From cfa2b94dda3d12a0d96fcfe9c57f4e481f2135f9 Mon Sep 17 00:00:00 2001 From: David Avedissian Date: Sun, 28 Apr 2019 18:23:57 +0100 Subject: [PATCH 1/3] Scripting idea. --- script_idea.lua | 22 ++++++++++++++++++++++ src/dawn/script/LuaState.h | 1 + 2 files changed, 23 insertions(+) create mode 100644 script_idea.lua diff --git a/script_idea.lua b/script_idea.lua new file mode 100644 index 00000000..e8e35455 --- /dev/null +++ b/script_idea.lua @@ -0,0 +1,22 @@ +-- Lua API idea +-- -------------------------------------- + +-- Some "game initialisation" script. + +local luaVelocitySystem = dw.world:createEntitySystem( + "VelocitySystem", + {dw.Transform, "velocity"} +) +function luaVelocitySystem:process(view, dt) + for e in view:entities() do + local transform = e:component(dw.Transform) + transform.position = transform.position + e.velocity * dt + end +end + +-- Some level initialisation script. + +local entity = dw.world:createEntity({ + dw.Transform(dw.vec3(1.0, 2.0, 3.0)), + velocity = dw.vec3(0.0, 0.0, 1.0) +}) diff --git a/src/dawn/script/LuaState.h b/src/dawn/script/LuaState.h index 6b2b29a5..4bf22505 100644 --- a/src/dawn/script/LuaState.h +++ b/src/dawn/script/LuaState.h @@ -17,5 +17,6 @@ class DW_API LuaState : public Module { virtual ~LuaState(); private: + sol::state state_; }; } // namespace dw From 60277029a52bff3cf61c3c0fdcaab6f71a6651d0 Mon Sep 17 00:00:00 2001 From: David Avedissian Date: Tue, 7 May 2019 22:22:17 +0100 Subject: [PATCH 2/3] Scripting example. --- src/CMakeLists.txt | 3 + src/dawn/CMakeLists.txt | 6 +- src/dawn/Script.h | 2 +- src/dawn/core/Engine.cpp | 6 +- src/dawn/core/io/InputStream.cpp | 13 +++ src/dawn/core/io/InputStream.h | 12 ++- src/dawn/resource/ResourceCache.cpp | 9 +-- src/dawn/resource/ResourceCache.h | 12 +-- src/dawn/resource/TextResource.cpp | 24 ++++++ src/dawn/resource/TextResource.h | 24 ++++++ src/dawn/script/LuaState.cpp | 30 ------- src/dawn/script/LuaState.h | 22 ----- src/dawn/script/LuaVM.cpp | 60 ++++++++++++++ src/dawn/script/LuaVM.h | 32 ++++++++ src/lua_shooter/CMakeLists.txt | 10 +++ src/lua_shooter/Main.cpp | 80 +++++++++++++++++++ src/lua_shooter/data/dw.lua | 20 +++++ .../lua_shooter/data/script_idea.lua | 4 + tools/format.sh | 6 +- 19 files changed, 296 insertions(+), 79 deletions(-) create mode 100644 src/dawn/resource/TextResource.cpp create mode 100644 src/dawn/resource/TextResource.h delete mode 100644 src/dawn/script/LuaState.cpp delete mode 100644 src/dawn/script/LuaState.h create mode 100644 src/dawn/script/LuaVM.cpp create mode 100644 src/dawn/script/LuaVM.h create mode 100644 src/lua_shooter/CMakeLists.txt create mode 100644 src/lua_shooter/Main.cpp create mode 100644 src/lua_shooter/data/dw.lua rename script_idea.lua => src/lua_shooter/data/script_idea.lua (93%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2c1e74c0..01d110ed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,9 @@ add_subdirectory(dawn) message("========== EXAMPLES ==========") add_subdirectory(examples) +message("========== LUA SHOOTER ==========") +add_subdirectory(lua_shooter) + message("========== SANDBOX ==========") add_subdirectory(sandbox) diff --git a/src/dawn/CMakeLists.txt b/src/dawn/CMakeLists.txt index 812b340e..6ffc183f 100644 --- a/src/dawn/CMakeLists.txt +++ b/src/dawn/CMakeLists.txt @@ -173,6 +173,8 @@ set(SOURCE_FILES resource/Resource.h resource/ResourceCache.cpp resource/ResourceCache.h + resource/TextResource.cpp + resource/TextResource.h scene/BulletDynamics.h scene/CLinearMotion.h scene/CameraController.cpp @@ -189,8 +191,8 @@ set(SOURCE_FILES scene/SLinearMotion.h scene/SceneManager.cpp scene/SceneManager.h - script/LuaState.cpp - script/LuaState.h + script/LuaVM.cpp + script/LuaVM.h script/Sol.h ui/Imgui.h ui/UserInterface.cpp diff --git a/src/dawn/Script.h b/src/dawn/Script.h index c2911e03..a71b5e38 100644 --- a/src/dawn/Script.h +++ b/src/dawn/Script.h @@ -5,4 +5,4 @@ #pragma once #include "Base.h" -#include "script/LuaState.h" +#include "script/LuaVM.h" diff --git a/src/dawn/core/Engine.cpp b/src/dawn/core/Engine.cpp index ef6fec40..21b2db27 100644 --- a/src/dawn/core/Engine.cpp +++ b/src/dawn/core/Engine.cpp @@ -11,7 +11,7 @@ #include "renderer/Renderer.h" #include "resource/ResourceCache.h" #include "scene/SceneManager.h" -#include "script/LuaState.h" +#include "script/LuaVM.h" // Required for getBasePath/getPrefPath. #if DW_PLATFORM == DW_WIN32 @@ -129,10 +129,6 @@ void Engine::setup(const CommandLine& cmdline) { context_->setDefaultConfig(); } - // Initialise the Lua VM first so bindings can be defined in Constructors - context_->addModule(); - // TODO(David): bind engine services to lua? - // Create the engine subsystems. auto* renderer = context_->addModule(); auto renderer_result = Result(); diff --git a/src/dawn/core/io/InputStream.cpp b/src/dawn/core/io/InputStream.cpp index 76d8f25c..4976ed84 100644 --- a/src/dawn/core/io/InputStream.cpp +++ b/src/dawn/core/io/InputStream.cpp @@ -28,6 +28,19 @@ String InputStream::readLine(char delim) { } return out; } +Result> InputStream::readAll() { + if (size_ == 0) { + return makeError("Unable to read entire InputStream. Size is 0."); + } + Vector buffer; + buffer.resize(size_); + auto read = readData(buffer.data(), size_); + if (!eof()) { + return makeError(tinyformat::format( + "Attempted to read %s bytes. Actually read %s bytes and didn't read EOF.", read)); + } + return std::move(buffer); +} bool InputStream::eof() const { return position_ >= size_; diff --git a/src/dawn/core/io/InputStream.h b/src/dawn/core/io/InputStream.h index 7ee40c86..baa58136 100644 --- a/src/dawn/core/io/InputStream.h +++ b/src/dawn/core/io/InputStream.h @@ -18,6 +18,14 @@ class DW_API InputStream { /// @return Number of bytes read virtual usize readData(void* dest, usize size) = 0; + /// Read all bytes from the stream. + /// @return A buffer containing all the bytes in the stream, or an error. + Result> readAll(); + + /// Reads a string up to a certain character + /// @param delim Delimeter character + String readLine(char delim = '\n'); + /// Moves the position of the cursor in the stream. /// @param position Offset from the start of the stream, in bytes virtual void seek(usize position) = 0; @@ -25,10 +33,6 @@ class DW_API InputStream { /// Check if the end of the stream has been reached bool eof() const; - /// Reads a string up to a certain character - /// @param delim Delimeter character - String readLine(char delim = '\n'); - /// Returns the current position in the input stream usize position() const; diff --git a/src/dawn/resource/ResourceCache.cpp b/src/dawn/resource/ResourceCache.cpp index e867025b..4760ab06 100644 --- a/src/dawn/resource/ResourceCache.cpp +++ b/src/dawn/resource/ResourceCache.cpp @@ -19,8 +19,7 @@ Pair parseResourcePath(const ResourcePath& resource_path) { ResourcePackage::ResourcePackage(Context* ctx, const Path& package) : Object(ctx) { } -Result, String> ResourcePackage::getFile( - const ResourcePath& path_within_location) { +Result> ResourcePackage::getFile(const ResourcePath& path_within_location) { return makeError( "ResourcePackage::getFile() - Loading from a ResourcePackage is unimplemented."); } @@ -29,7 +28,7 @@ ResourceFilesystemPath::ResourceFilesystemPath(Context* ctx, const Path& path) : Object(ctx), path_{path} { } -Result, String> ResourceFilesystemPath::getFile( +Result> ResourceFilesystemPath::getFile( const ResourcePath& path_within_location) { Path full_path = path_ + path_within_location; log().info("Loading resource from filesystem at " + full_path); @@ -60,8 +59,8 @@ void ResourceCache::addPackage(const String& package, UniquePtr resource_packages_.emplace(makePair(package, std::move(file))); } -Result, String> ResourceCache::getResourceData( - const ResourcePath& resource_path) { +Result> ResourceCache::loadRaw( + const ResourcePath &resource_path) { // Parse resource path. auto path = parseResourcePath(resource_path); String package = path.first; diff --git a/src/dawn/resource/ResourceCache.h b/src/dawn/resource/ResourceCache.h index 9a635fdc..7df3fcef 100644 --- a/src/dawn/resource/ResourceCache.h +++ b/src/dawn/resource/ResourceCache.h @@ -16,7 +16,7 @@ Pair parseResourcePath(const ResourcePath& resource_path); class DW_API ResourceLocation { public: virtual ~ResourceLocation() = default; - virtual Result, String> getFile( + virtual Result> getFile( const ResourcePath& path_within_location) = 0; }; @@ -26,7 +26,7 @@ class DW_API ResourcePackage : public Object, public ResourceLocation { ResourcePackage(Context* ctx, const Path& package); - Result, String> getFile( + Result> getFile( const ResourcePath& path_within_location) override; }; @@ -36,7 +36,7 @@ class DW_API ResourceFilesystemPath : public Object, public ResourceLocation { ResourceFilesystemPath(Context* ctx, const Path& path); - Result, String> getFile( + Result> getFile( const ResourcePath& path_within_location) override; private: @@ -53,6 +53,9 @@ class DW_API ResourceCache : public Module { void addPath(const String& package, const Path& path); void addPackage(const String& package, UniquePtr file); + // Raw API to read resource data. + Result> loadRaw(const ResourcePath &resource_path); + template SharedPtr addCustomResource(const ResourcePath& resource_path, SharedPtr resource) { String name(resource_path); @@ -80,7 +83,7 @@ class DW_API ResourceCache : public Module { } // Load the file which contains this resource data. - auto resource_data = getResourceData(resource_path); + auto resource_data = loadRaw(resource_path); if (!resource_data) { return makeError(str::format("Cannot find resource %s. Reason: %s", resource_path, resource_data.error())); @@ -97,7 +100,6 @@ class DW_API ResourceCache : public Module { } private: - Result, String> getResourceData(const Path& filename); Map> resource_packages_; HashMap> resource_cache_; diff --git a/src/dawn/resource/TextResource.cpp b/src/dawn/resource/TextResource.cpp new file mode 100644 index 00000000..e02b84d7 --- /dev/null +++ b/src/dawn/resource/TextResource.cpp @@ -0,0 +1,24 @@ +/* + * Dawn Engine + * Written by David Avedissian (c) 2012-2019 (git@dga.me.uk) + */ +#include "Core.h" +#include "resource/TextResource.h" + +namespace dw { +TextResource::TextResource(Context* ctx) : Resource(ctx) { +} + +Result TextResource::beginLoad(const String&, InputStream& src) { + auto result = src.readAll(); + if (!result) { + return makeError(result.error()); + } + data_ = String(static_cast(static_cast(result->data())), result->size()); + return {}; +} + +Result TextResource::save(OutputStream& dest) { + dest.writeData(data_.data(), data_.size()); +} +} // namespace dw \ No newline at end of file diff --git a/src/dawn/resource/TextResource.h b/src/dawn/resource/TextResource.h new file mode 100644 index 00000000..ab530ce6 --- /dev/null +++ b/src/dawn/resource/TextResource.h @@ -0,0 +1,24 @@ +/* + * Dawn Engine + * Written by David Avedissian (c) 2012-2019 (git@dga.me.uk) + */ +#pragma once + +#include "resource/Resource.h" + +namespace dw { + class DW_API TextResource : public Resource { + public: + DW_OBJECT(TextResource); + + TextResource(Context* ctx); + + Result beginLoad(const String& asset_name, InputStream& src) override; + Result save(OutputStream& dest) override; + + String data(); + + private: + String data_; +}; +} // namespace dw \ No newline at end of file diff --git a/src/dawn/script/LuaState.cpp b/src/dawn/script/LuaState.cpp deleted file mode 100644 index 6a6eb2a1..00000000 --- a/src/dawn/script/LuaState.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Dawn Engine - * Written by David Avedissian (c) 2012-2019 (git@dga.me.uk) - */ -#include "Base.h" -#include "LuaState.h" - -namespace dw { - -LuaState::LuaState(Context* context) : Module(context) { - // Redirect Lua printing to the Log - /* - executeString( - "function print(...)\n" - " local arg = {...}\n" - " local str\n" - " str = ''\n" - " for i = 1, #arg do\n" - " if str ~= '' then str = str .. '\t' end\n" - " str = str .. tostring(arg[i])\n" - " end\n" - " str = str .. '\\n'\n" - " _logWrite(str)\n" - "end\n"); - */ -} - -LuaState::~LuaState() { -} -} // namespace dw diff --git a/src/dawn/script/LuaState.h b/src/dawn/script/LuaState.h deleted file mode 100644 index 4bf22505..00000000 --- a/src/dawn/script/LuaState.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Dawn Engine - * Written by David Avedissian (c) 2012-2019 (git@dga.me.uk) - */ -#pragma once - -#include "Sol.h" - -namespace dw { - -// Manages the Lua virtual machine and provides some helper functions -class DW_API LuaState : public Module { -public: - DW_OBJECT(LuaState); - - LuaState(Context* context); - virtual ~LuaState(); - -private: - sol::state state_; -}; -} // namespace dw diff --git a/src/dawn/script/LuaVM.cpp b/src/dawn/script/LuaVM.cpp new file mode 100644 index 00000000..c26cac39 --- /dev/null +++ b/src/dawn/script/LuaVM.cpp @@ -0,0 +1,60 @@ +/* + * Dawn Engine + * Written by David Avedissian (c) 2012-2019 (git@dga.me.uk) + */ +#include "Base.h" +#include "LuaVM.h" + +namespace dw { +namespace { +void redirectLuaPrintToLogger(Context& context, sol::state& state) { + state.script(R"""( +function print(...) + local arg = {...} + local str + str = '' + for i = 1, #arg do + if str ~= '' then str = str .. '\t' end + str = str .. tostring(arg[i]) + end + str = str .. '\n' + __dw_write_log(debug.getinfo(2).short_src, str) +end)"""); +} + +void registerWorldLib(sol::state& state) { +} +} // namespace + +LuaVM::LuaVM(Context* context) : Object(context) { + state_.open_libraries(sol::lib::base, sol::lib::package, sol::lib::coroutine, sol::lib::string, sol::lib::os, sol::lib::math, sol::lib::table, sol::lib::debug, sol::lib::bit32); + state_.set_function("__dw_write_log", + [this](const char* caller, const char* str) { + log().info("%s: %s", caller, str); + }); + redirectLuaPrintToLogger(*context, state_); + registerWorldLib(state_); +} + +sol::state& LuaVM::state() { + return state_; +} + +Result LuaVM::execute(const String& text) { + try { + state_.script(text); + } catch (const sol::error& e) { + return makeError(e.what()); + } + return {}; +} + +Result LuaVM::execute(InputStream& is) { + auto read_result = is.readAll(); + if (!read_result) { + return makeError(read_result.error()); + } + return execute(String(static_cast(static_cast(read_result->data())), + read_result->size())); +} +} // namespace dw diff --git a/src/dawn/script/LuaVM.h b/src/dawn/script/LuaVM.h new file mode 100644 index 00000000..306a8e6b --- /dev/null +++ b/src/dawn/script/LuaVM.h @@ -0,0 +1,32 @@ +/* + * Dawn Engine + * Written by David Avedissian (c) 2012-2019 (git@dga.me.uk) + */ +#pragma once + +#include "Sol.h" +#include "core/io/InputStream.h" + +namespace dw { + +// Manages a Lua virtual machine, with the "dw" library set. +class DW_API LuaVM : public Object { +public: + DW_OBJECT(LuaVM); + + LuaVM(Context* context); + virtual ~LuaVM() = default; + + // Get a reference to the internal state. + sol::state& state(); + + // Execute a file from a string. + Result execute(const String& text); + + // Execute a file from an input stream. + Result execute(InputStream& is); + +private: + sol::state state_; +}; +} // namespace dw diff --git a/src/lua_shooter/CMakeLists.txt b/src/lua_shooter/CMakeLists.txt new file mode 100644 index 00000000..0ddfcf03 --- /dev/null +++ b/src/lua_shooter/CMakeLists.txt @@ -0,0 +1,10 @@ +# Dawn Engine +# Written by David Avedissian (c) 2012-2019 (git@dga.me.uk) + +add_dawn_executable( + DwLuaShooter + SRCS + Main.cpp + RESOURCE_PKGS + ${CMAKE_CURRENT_SOURCE_DIR}/data + ${CMAKE_SOURCE_DIR}/media/examples) diff --git a/src/lua_shooter/Main.cpp b/src/lua_shooter/Main.cpp new file mode 100644 index 00000000..9a983145 --- /dev/null +++ b/src/lua_shooter/Main.cpp @@ -0,0 +1,80 @@ +/* + * Dawn Engine + * Written by David Avedissian (c) 2012-2019 (git@dga.me.uk) + */ +#include "Core.h" +#include "resource/ResourceCache.h" +#include "core/GameSession.h" +#include "renderer/Renderer.h" +#include "script/LuaVM.h" + +using namespace dw; + +class LuaGameSession : public GameSession { +public: + DW_OBJECT(LuaGameSession); + + LuaGameSession(Context* ctx, const ResourcePath& lua_script_file, const GameSessionInfo& gsi) + : GameSession(ctx, gsi), lua_state_(ctx) { + auto* rc = module(); + + // Register inputs if a client. + if (!net_instance_ || net_instance_->netMode() == NetMode::Client) { + module()->registerEventSystem(event_system_.get()); + } + + // Create Lua VM and execute script. + auto script_result = rc->loadRaw(lua_script_file); + auto execute_result = lua_state_.execute(**script_result); + if (!execute_result) { + log().error("Failed to execute %s: %s", lua_script_file, execute_result.error()); + } + } + + ~LuaGameSession() override { + if (!net_instance_ || net_instance_->netMode() == NetMode::Client) { + module()->unregisterEventSystem(event_system_.get()); + } + } + + void update(float dt) override { + GameSession::update(dt); + + module()->rhi()->setViewClear(0, {0.0f, 0.0f, 0.0f, 1.0f}); + + // Display FPS information. + ImGui::SetNextWindowPos({10, 10}); + ImGui::SetNextWindowSize({140, 40}); + if (!ImGui::Begin("FPS", nullptr, + ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | + ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings)) { + ImGui::End(); + return; + } + ImGui::Text("FPS: %f", 1.0f / dt); + ImGui::Text("Frame: %.4f ms", dt); + ImGui::End(); + } + +private: + LuaVM lua_state_; +}; + +class LuaShooter : public App { +public: + DW_OBJECT(LuaShooter); + + LuaShooter() : App("LuaShooter", DW_VERSION_STR) { + } + + void init(const CommandLine&) override { + module()->addPath("shooter", "../src/lua_shooter/data"); + + engine_->addSession(makeUnique(context_, "shooter:script_idea.lua", GameSessionInfo{})); + } + + void shutdown() override { + } +}; + +DW_IMPLEMENT_MAIN(LuaShooter); diff --git a/src/lua_shooter/data/dw.lua b/src/lua_shooter/data/dw.lua new file mode 100644 index 00000000..f6ec3e9f --- /dev/null +++ b/src/lua_shooter/data/dw.lua @@ -0,0 +1,20 @@ +--- Dawn Engine runtime + +dw = {} + +-- __dw_world contains the object that contains ECS functions. Set by the scripting system. +dw.world = __dw_world + +-- Vector functions. +function dw.vec2(x, y) + return {x = x, y = y} +end + +function dw.vec3(x, y, z) + return {x = x, y = y, z = z} +end + +-- Returns an instance to a dw::Transform component. +function dw.Transform(v) + return {v = v} +end \ No newline at end of file diff --git a/script_idea.lua b/src/lua_shooter/data/script_idea.lua similarity index 93% rename from script_idea.lua rename to src/lua_shooter/data/script_idea.lua index e8e35455..23d7d018 100644 --- a/script_idea.lua +++ b/src/lua_shooter/data/script_idea.lua @@ -3,6 +3,10 @@ -- Some "game initialisation" script. +print "HELLO WORLD!" + +dw = require('dw') + local luaVelocitySystem = dw.world:createEntitySystem( "VelocitySystem", {dw.Transform, "velocity"} diff --git a/tools/format.sh b/tools/format.sh index cf812a51..7b710b71 100755 --- a/tools/format.sh +++ b/tools/format.sh @@ -14,10 +14,6 @@ fi # Run clang-format against a set of paths. PATHS=( - src/dawn - src/examples - src/sandbox - src/shooter - src/viewer + src ) find "${PATHS[@]}" -name "*.h" -o -name "*.cpp" -not -path "./src/dawn/external/*" -exec $CLANG_FORMAT -i {} \; From ceb80c601cc74bfedad90554580c1e41b8166d2f Mon Sep 17 00:00:00 2001 From: David Avedissian Date: Fri, 31 May 2019 21:48:20 +0100 Subject: [PATCH 3/3] Formatting. --- src/dawn/resource/ResourceCache.cpp | 3 +-- src/dawn/script/LuaVM.cpp | 11 ++++++----- src/lua_shooter/Main.cpp | 13 +++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/dawn/resource/ResourceCache.cpp b/src/dawn/resource/ResourceCache.cpp index 4760ab06..18a0e147 100644 --- a/src/dawn/resource/ResourceCache.cpp +++ b/src/dawn/resource/ResourceCache.cpp @@ -59,8 +59,7 @@ void ResourceCache::addPackage(const String& package, UniquePtr resource_packages_.emplace(makePair(package, std::move(file))); } -Result> ResourceCache::loadRaw( - const ResourcePath &resource_path) { +Result> ResourceCache::loadRaw(const ResourcePath& resource_path) { // Parse resource path. auto path = parseResourcePath(resource_path); String package = path.first; diff --git a/src/dawn/script/LuaVM.cpp b/src/dawn/script/LuaVM.cpp index c26cac39..c724edc6 100644 --- a/src/dawn/script/LuaVM.cpp +++ b/src/dawn/script/LuaVM.cpp @@ -27,11 +27,12 @@ void registerWorldLib(sol::state& state) { } // namespace LuaVM::LuaVM(Context* context) : Object(context) { - state_.open_libraries(sol::lib::base, sol::lib::package, sol::lib::coroutine, sol::lib::string, sol::lib::os, sol::lib::math, sol::lib::table, sol::lib::debug, sol::lib::bit32); - state_.set_function("__dw_write_log", - [this](const char* caller, const char* str) { - log().info("%s: %s", caller, str); - }); + state_.open_libraries(sol::lib::base, sol::lib::package, sol::lib::coroutine, sol::lib::string, + sol::lib::os, sol::lib::math, sol::lib::table, sol::lib::debug, + sol::lib::bit32); + state_.set_function("__dw_write_log", [this](const char* caller, const char* str) { + log().info("%s: %s", caller, str); + }); redirectLuaPrintToLogger(*context, state_); registerWorldLib(state_); } diff --git a/src/lua_shooter/Main.cpp b/src/lua_shooter/Main.cpp index 9a983145..b691a3f7 100644 --- a/src/lua_shooter/Main.cpp +++ b/src/lua_shooter/Main.cpp @@ -24,11 +24,11 @@ class LuaGameSession : public GameSession { } // Create Lua VM and execute script. - auto script_result = rc->loadRaw(lua_script_file); - auto execute_result = lua_state_.execute(**script_result); - if (!execute_result) { - log().error("Failed to execute %s: %s", lua_script_file, execute_result.error()); - } + auto script_result = rc->loadRaw(lua_script_file); + auto execute_result = lua_state_.execute(**script_result); + if (!execute_result) { + log().error("Failed to execute %s: %s", lua_script_file, execute_result.error()); + } } ~LuaGameSession() override { @@ -70,7 +70,8 @@ class LuaShooter : public App { void init(const CommandLine&) override { module()->addPath("shooter", "../src/lua_shooter/data"); - engine_->addSession(makeUnique(context_, "shooter:script_idea.lua", GameSessionInfo{})); + engine_->addSession( + makeUnique(context_, "shooter:script_idea.lua", GameSessionInfo{})); } void shutdown() override {