From f3c065debdaf9803ff2e2a270fe4a752ee274524 Mon Sep 17 00:00:00 2001 From: meehl <12648828+meehl@users.noreply.github.com> Date: Sat, 17 Oct 2026 16:04:54 +0200 Subject: [PATCH] Add feature for registering bundled Lua modules Enabled by default. --- Cargo.toml | 8 ++++++-- src/pob.rs | 9 ++------- src/pob/modules.rs | 18 ++++++++++++++++++ src/pob/subscript.rs | 9 ++------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e2cc2cc..fcdc129 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ anyhow = "1.0" arboard = { version = "3.6.1", default-features = false } bytemuck = "1.23.2" clap = { version = "4.5.46", features = ["derive"] } -curl = "0.4.51" +curl = { version = "0.4.51", optional = true } dds = "0.2.0" directories = "6.0.0" env_logger = "0.11" @@ -24,7 +24,7 @@ flate2 = "1.1.2" glob = "0.3.3" image = { version = "0.25.8", default-features = false, features = ["rayon", "jpeg", "png", "webp"] } log = "0.4" -luautf8-rs = { git = "https://github.com/meehl/luautf8-rs.git", rev = "dc74b734e5285108068cf2ffb674c1dc840073c1", features = ["luajit"] } +luautf8-rs = { git = "https://github.com/meehl/luautf8-rs.git", rev = "dc74b734e5285108068cf2ffb674c1dc840073c1", features = ["luajit"], optional = true } mlua = { version = "0.12.0", features = ["luajit", "anyhow"] } nohash-hasher = "0.2.0" num-traits = "0.2.19" @@ -47,4 +47,8 @@ zstd = "0.13.3" smithay-clipboard = "0.7.3" [features] +default = ["bundled-lua-modules"] +# Register Rust implementations of the Lua modules required by PoB's Lua code. +# Disable this to use the original C libraries. +bundled-lua-modules = ["dep:curl", "dep:luautf8-rs"] profile-with-puffin = ["profiling/profile-with-puffin", "dep:puffin_http"] diff --git a/src/pob.rs b/src/pob.rs index 0831534..1208f30 100644 --- a/src/pob.rs +++ b/src/pob.rs @@ -10,10 +10,7 @@ use crate::{ draw_commands::DrawCommandRecorder, fonts::Fonts, input::InputState, - pob::{ - modules::{luacurl, luasocket}, - subscript::{NativeMultiValue, SubscriptEvent, SubscriptManager}, - }, + pob::subscript::{NativeMultiValue, SubscriptEvent, SubscriptManager}, renderer::textures::TextureManager, stage::{StageEvent, StageFrameOutput, StageTransition}, util::{append_lua_package_dir, change_working_directory}, @@ -128,9 +125,7 @@ impl PathOfBuilding { api::register_globals(&lua)?; // register modules - lua.register_module("lua-utf8", luautf8::create_module(&lua)?)?; - lua.register_module("socket", luasocket::create_module(&lua)?)?; - lua.register_module("lcurl.safe", luacurl::create_module(&lua)?)?; + modules::register(&lua)?; Ok(lua) } diff --git a/src/pob/modules.rs b/src/pob/modules.rs index 44a7a39..03a313f 100644 --- a/src/pob/modules.rs +++ b/src/pob/modules.rs @@ -1,2 +1,20 @@ +#[cfg(feature = "bundled-lua-modules")] pub mod luacurl; +#[cfg(feature = "bundled-lua-modules")] pub mod luasocket; + +use mlua::{Lua, Result as LuaResult}; + +/// Registers Rust implementations of the Lua modules required by PoB's Lua code. +pub fn register(lua: &Lua) -> LuaResult<()> { + lua.register_module("lua-utf8", luautf8::create_module(lua)?)?; + lua.register_module("socket", luasocket::create_module(lua)?)?; + lua.register_module("lcurl.safe", luacurl::create_module(lua)?)?; + Ok(()) +} + +/// Nothing is registered so Lua resolves the required modules through `package.cpath`. +#[cfg(not(feature = "bundled-lua-modules"))] +pub fn register(_lua: &Lua) -> LuaResult<()> { + Ok(()) +} diff --git a/src/pob/subscript.rs b/src/pob/subscript.rs index e6c426f..66a1e2b 100644 --- a/src/pob/subscript.rs +++ b/src/pob/subscript.rs @@ -1,7 +1,4 @@ -use crate::{ - pob::modules::{luacurl, luasocket}, - util::append_lua_package_dir, -}; +use crate::{pob::modules, util::append_lua_package_dir}; use anyhow::{Result, anyhow}; use mlua::{Integer, IntoLuaMulti, Lua, MultiValue, Number, Value}; use std::{ @@ -145,9 +142,7 @@ impl Subscript { append_lua_package_dir(&lua, &script_dir.join("lua"))?; // register modules - lua.register_module("lua-utf8", luautf8::create_module(&lua)?)?; - lua.register_module("socket", luasocket::create_module(&lua)?)?; - lua.register_module("lcurl.safe", luacurl::create_module(&lua)?)?; + modules::register(&lua)?; // register a proxy for each allowed blocking call. // forwards the call to the main thread and blocks on `reply_rx` until the main thread