Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17bb3c6b39 | ||
|
|
ce62fe64e1 | ||
|
|
4b997447b5 |
No files matched your search
+8
-1
@@ -2,6 +2,12 @@
|
||||
|
||||
## [Unreleased] - ReleaseDate
|
||||
|
||||
## [0.3.1] - 2026-10-21
|
||||
|
||||
### Fixed
|
||||
|
||||
- Strip `#@` script headers before loading Lua files to fix syntax error with recent LuaJIT versions
|
||||
|
||||
## [0.3.0] - 2026-10-21
|
||||
|
||||
### Added
|
||||
@@ -230,8 +236,9 @@
|
||||
- First release
|
||||
|
||||
<!-- next-url -->
|
||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.0...HEAD
|
||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.1...HEAD
|
||||
|
||||
[0.3.1]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.0...v0.3.1
|
||||
[0.3.0]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.18...v0.3.0
|
||||
[0.2.18]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.17...v0.2.18
|
||||
[0.2.17]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.16...v0.2.17
|
||||
|
||||
Generated
+1
-1
@@ -3502,7 +3502,7 @@ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
||||
|
||||
[[package]]
|
||||
name = "rusty-path-of-building"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"anyhow",
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ authors = ["meehl"]
|
||||
description = "Cross-platform runtime for Path of Building"
|
||||
repository = "https://github.com/meehl/rusty-path-of-building"
|
||||
license = "MIT"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ use crate::{
|
||||
pob::subscript::{NativeMultiValue, SubscriptEvent, SubscriptManager},
|
||||
renderer::textures::TextureManager,
|
||||
stage::{StageEvent, StageFrameOutput, StageTransition},
|
||||
util::{append_lua_package_dir, change_working_directory},
|
||||
util::{append_lua_package_dir, change_working_directory, load_lua_file},
|
||||
window::WindowState,
|
||||
};
|
||||
use std::{
|
||||
@@ -133,7 +133,7 @@ impl PathOfBuilding {
|
||||
/// Loads and runs `Launch.lua`, then calls PoB's `OnInit` handler.
|
||||
fn launch(lua: &Lua, script_dir: &Path) -> LuaResult<()> {
|
||||
change_working_directory(script_dir)?;
|
||||
lua.load(script_dir.join("Launch.lua")).exec()?;
|
||||
load_lua_file(lua, &script_dir.join("Launch.lua"))?.exec()?;
|
||||
{
|
||||
profiling::scope!("OnInit");
|
||||
api::on_init(lua)?;
|
||||
|
||||
+12
-8
@@ -1,4 +1,7 @@
|
||||
use crate::{pob::Context, util::change_working_directory};
|
||||
use crate::{
|
||||
pob::Context,
|
||||
util::{change_working_directory, load_lua_file},
|
||||
};
|
||||
use mlua::{Function, IntoLuaMulti, Lua, MultiValue, Result as LuaResult, Value};
|
||||
use std::env;
|
||||
|
||||
@@ -23,7 +26,7 @@ pub fn load_module(l: &Lua, (name, args): (String, MultiValue)) -> LuaResult<Mul
|
||||
|
||||
let current_dir = env::current_dir()?;
|
||||
change_working_directory(script_dir.as_path())?;
|
||||
let result = l.load(module_path).call::<MultiValue>(args);
|
||||
let result = load_lua_file(l, &module_path).and_then(|chunk| chunk.call::<MultiValue>(args));
|
||||
change_working_directory(current_dir)?;
|
||||
result
|
||||
}
|
||||
@@ -40,12 +43,13 @@ pub fn protected_load_module(l: &Lua, (name, args): (String, MultiValue)) -> Lua
|
||||
|
||||
let current_dir = env::current_dir()?;
|
||||
change_working_directory(script_dir.as_path())?;
|
||||
let result = match l.load(module_path).call::<MultiValue>(args) {
|
||||
// on success, callers expect a Nil followed by return values
|
||||
Ok(res) => Ok(std::iter::once(Value::Nil).chain(res).collect()),
|
||||
// otherwise it is set to error message.
|
||||
Err(err) => err.to_string().into_lua_multi(l),
|
||||
};
|
||||
let result =
|
||||
match load_lua_file(l, &module_path).and_then(|chunk| chunk.call::<MultiValue>(args)) {
|
||||
// on success, callers expect a Nil followed by return values
|
||||
Ok(res) => Ok(std::iter::once(Value::Nil).chain(res).collect()),
|
||||
// otherwise it is set to error message.
|
||||
Err(err) => err.to_string().into_lua_multi(l),
|
||||
};
|
||||
change_working_directory(current_dir)?;
|
||||
result
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::{pob::modules, util::append_lua_package_dir};
|
||||
use crate::{
|
||||
pob::modules,
|
||||
util::{append_lua_package_dir, fix_script_header},
|
||||
};
|
||||
use anyhow::{Result, anyhow};
|
||||
use mlua::{Integer, IntoLuaMulti, Lua, MultiValue, Number, Value};
|
||||
use std::{
|
||||
@@ -184,6 +187,8 @@ impl Subscript {
|
||||
)?;
|
||||
}
|
||||
|
||||
let mut script_text = script_text.into_bytes();
|
||||
fix_script_header(&mut script_text);
|
||||
let result = lua.load(script_text).call::<MultiValue>(arguments)?;
|
||||
result.try_into()
|
||||
});
|
||||
|
||||
+32
-2
@@ -1,7 +1,7 @@
|
||||
use ahash::AHasher;
|
||||
use mlua::{Lua, Result as LuaResult, Table};
|
||||
use mlua::{Lua, Result as LuaResult, Table, chunk::Chunk};
|
||||
use std::{
|
||||
env,
|
||||
env, fs,
|
||||
hash::{Hash, Hasher},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
@@ -79,3 +79,33 @@ pub fn append_lua_package_dir(lua: &Lua, path: &Path) -> LuaResult<()> {
|
||||
append_lua_package_path(lua, &format!("{path}/?/init.lua"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Rewrites PoB's `#@ <label>` script header into a Lua comment.
|
||||
///
|
||||
/// Some Path of Building scripts start with a line such as `#@ <optional_text>`. Recent LuaJIT
|
||||
/// versions interpret a leading `#` as a line number directive and reject this header so we
|
||||
/// replace them with a comment.
|
||||
///
|
||||
/// commit that introduced changes to the lexer to enable parsing of line number directives:
|
||||
/// <https://github.com/LuaJIT/LuaJIT/commit/c41d727dbffa5ec4f346dd9be0f4c64740f124aa>
|
||||
pub fn fix_script_header(source: &mut [u8]) {
|
||||
// skip utf8-bom
|
||||
let start = if source.starts_with(b"\xEF\xBB\xBF") {
|
||||
3
|
||||
} else {
|
||||
0
|
||||
};
|
||||
if source[start..].starts_with(b"#@") {
|
||||
source[start..start + 2].copy_from_slice(b"--");
|
||||
}
|
||||
}
|
||||
|
||||
/// Loads a Lua script from `path` and applies `fix_script_header`.
|
||||
///
|
||||
/// The chunk name is set to `@<path>` to match `Lua::load`'s behavior for paths, so error messages
|
||||
/// keep referring to the file.
|
||||
pub fn load_lua_file<'lua>(lua: &'lua Lua, path: &Path) -> LuaResult<Chunk<'lua>> {
|
||||
let mut source = fs::read(path)?;
|
||||
fix_script_header(&mut source);
|
||||
Ok(lua.load(source).set_name(format!("@{}", path.display())))
|
||||
}
|
||||
Reference in new issue
Block a user