Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
098c967206 | ||
|
|
1bb0fdf056 | ||
|
|
9a341cfb39 |
No files matched your search
+8
-1
@@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
## [Unreleased] - ReleaseDate
|
## [Unreleased] - ReleaseDate
|
||||||
|
|
||||||
|
## [0.3.3] - 2026-10-23
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix error in built-in updater with new `bundled-lua-modules` feature
|
||||||
|
|
||||||
## [0.3.2] - 2026-10-22
|
## [0.3.2] - 2026-10-22
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
@@ -246,8 +252,9 @@
|
|||||||
- First release
|
- First release
|
||||||
|
|
||||||
<!-- next-url -->
|
<!-- next-url -->
|
||||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.2...HEAD
|
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.3...HEAD
|
||||||
|
|
||||||
|
[0.3.3]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.2...v0.3.3
|
||||||
[0.3.2]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.1...v0.3.2
|
[0.3.2]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.1...v0.3.2
|
||||||
[0.3.1]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.0...v0.3.1
|
[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.3.0]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.18...v0.3.0
|
||||||
|
|||||||
Generated
+1
-1
@@ -3502,7 +3502,7 @@ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rusty-path-of-building"
|
name = "rusty-path-of-building"
|
||||||
version = "0.3.2"
|
version = "0.3.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ authors = ["meehl"]
|
|||||||
description = "Cross-platform runtime for Path of Building"
|
description = "Cross-platform runtime for Path of Building"
|
||||||
repository = "https://github.com/meehl/rusty-path-of-building"
|
repository = "https://github.com/meehl/rusty-path-of-building"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
version = "0.3.2"
|
version = "0.3.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
|||||||
+100
-21
@@ -17,11 +17,59 @@ fn bad_argument(to: impl Into<String>, pos: usize, cause: &'static str) -> LuaEr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A Lua callback set via `setopt_*function`.
|
||||||
|
///
|
||||||
|
/// `context` is set when an object is passed to the callback setter. In that case `function` is
|
||||||
|
/// the object's method and is invoked as `function(context, data)`.
|
||||||
|
struct Callback {
|
||||||
|
function: RegistryKey,
|
||||||
|
context: Option<RegistryKey>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Callback {
|
||||||
|
fn resolve(&self, lua: &Lua) -> LuaResult<(mlua::Function, Option<mlua::Value>)> {
|
||||||
|
let function = lua.registry_value(&self.function)?;
|
||||||
|
let context = self
|
||||||
|
.context
|
||||||
|
.as_ref()
|
||||||
|
.map(|key| lua.registry_value::<mlua::Value>(key))
|
||||||
|
.transpose()?;
|
||||||
|
|
||||||
|
Ok((function, context))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove(self, lua: &Lua) -> LuaResult<()> {
|
||||||
|
lua.remove_registry_value(self.function)?;
|
||||||
|
|
||||||
|
if let Some(key) = self.context {
|
||||||
|
lua.remove_registry_value(key)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Interprets write/header callback return values like Lua-cURL does.
|
||||||
|
fn callback_size(data_len: usize, results: &mlua::MultiValue) -> usize {
|
||||||
|
let Some(value) = results.front() else {
|
||||||
|
return data_len;
|
||||||
|
};
|
||||||
|
|
||||||
|
match value {
|
||||||
|
mlua::Value::Nil => 0,
|
||||||
|
mlua::Value::Integer(n) => (*n).max(0) as usize,
|
||||||
|
mlua::Value::Number(n) if *n >= 0.0 => *n as usize,
|
||||||
|
mlua::Value::Number(_) => 0,
|
||||||
|
mlua::Value::Boolean(false) => 0,
|
||||||
|
_ => data_len,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct EasyHandle {
|
pub struct EasyHandle {
|
||||||
easy: Option<Easy>,
|
easy: Option<Easy>,
|
||||||
write_callback: Option<RegistryKey>,
|
write_callback: Option<Callback>,
|
||||||
header_callback: Option<RegistryKey>,
|
header_callback: Option<Callback>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EasyHandle {
|
impl EasyHandle {
|
||||||
@@ -40,12 +88,12 @@ impl EasyHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn close(&mut self, lua: &Lua) -> LuaResult<()> {
|
pub fn close(&mut self, lua: &Lua) -> LuaResult<()> {
|
||||||
if let Some(key) = self.write_callback.take() {
|
if let Some(callback) = self.write_callback.take() {
|
||||||
lua.remove_registry_value(key)?;
|
callback.remove(lua)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(key) = self.header_callback.take() {
|
if let Some(callback) = self.header_callback.take() {
|
||||||
lua.remove_registry_value(key)?;
|
callback.remove(lua)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.easy = None;
|
self.easy = None;
|
||||||
@@ -160,20 +208,37 @@ impl EasyHandle {
|
|||||||
|
|
||||||
fn set_callback(
|
fn set_callback(
|
||||||
lua: &Lua,
|
lua: &Lua,
|
||||||
slot: &mut Option<RegistryKey>,
|
slot: &mut Option<Callback>,
|
||||||
value: mlua::Value,
|
value: mlua::Value,
|
||||||
|
method: &str,
|
||||||
) -> LuaResult<()> {
|
) -> LuaResult<()> {
|
||||||
let new_key = match value {
|
let new_callback = match value {
|
||||||
mlua::Value::Nil => None,
|
mlua::Value::Nil => None,
|
||||||
mlua::Value::Function(f) => Some(lua.create_registry_value(f)?),
|
mlua::Value::Function(function) => Some(Callback {
|
||||||
|
function: lua.create_registry_value(function)?,
|
||||||
|
context: None,
|
||||||
|
}),
|
||||||
|
// Lua-cURL can also accept objects with a method of the given name,
|
||||||
|
// e.g. a file handle returned by `io.open` with a `write` method.
|
||||||
|
// looks a bit awkwards but it works...
|
||||||
|
value @ (mlua::Value::Table(_) | mlua::Value::UserData(_)) => {
|
||||||
|
let function: mlua::Function = lua
|
||||||
|
.load("local object, key = ...; return object[key]")
|
||||||
|
.call((value.clone(), method))?;
|
||||||
|
|
||||||
|
Some(Callback {
|
||||||
|
function: lua.create_registry_value(function)?,
|
||||||
|
context: Some(lua.create_registry_value(value)?),
|
||||||
|
})
|
||||||
|
}
|
||||||
_ => return Err(LuaError::runtime("invalid object type")),
|
_ => return Err(LuaError::runtime("invalid object type")),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(old_key) = slot.take() {
|
if let Some(old_callback) = slot.take() {
|
||||||
lua.remove_registry_value(old_key)?;
|
old_callback.remove(lua)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
*slot = new_key;
|
*slot = new_callback;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -182,41 +247,55 @@ impl EasyHandle {
|
|||||||
let write_fn = self
|
let write_fn = self
|
||||||
.write_callback
|
.write_callback
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|key| lua.registry_value::<mlua::Function>(key))
|
.map(|callback| callback.resolve(lua))
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
let header_fn = self
|
let header_fn = self
|
||||||
.header_callback
|
.header_callback
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|key| lua.registry_value::<mlua::Function>(key))
|
.map(|callback| callback.resolve(lua))
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
let transfer_result = {
|
let transfer_result = {
|
||||||
let mut transfer = self.curl()?.transfer();
|
let mut transfer = self.curl()?.transfer();
|
||||||
|
|
||||||
if let Some(function) = write_fn {
|
if let Some((function, context)) = write_fn {
|
||||||
transfer
|
transfer
|
||||||
.write_function(move |data| {
|
.write_function(move |data| {
|
||||||
let Ok(argument) = lua.create_string(data) else {
|
let Ok(argument) = lua.create_string(data) else {
|
||||||
return Ok(0);
|
return Ok(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
match function.call::<()>(argument) {
|
let result = match &context {
|
||||||
Ok(()) => Ok(data.len()),
|
Some(context) => {
|
||||||
|
function.call::<mlua::MultiValue>((context.clone(), argument))
|
||||||
|
}
|
||||||
|
None => function.call::<mlua::MultiValue>(argument),
|
||||||
|
};
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(results) => Ok(callback_size(data.len(), &results)),
|
||||||
Err(_) => Ok(0),
|
Err(_) => Ok(0),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map_err(LuaError::external)?;
|
.map_err(LuaError::external)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(function) = header_fn {
|
if let Some((function, context)) = header_fn {
|
||||||
transfer
|
transfer
|
||||||
.header_function(move |data| {
|
.header_function(move |data| {
|
||||||
let Ok(argument) = lua.create_string(data) else {
|
let Ok(argument) = lua.create_string(data) else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
function.call::<bool>(argument).unwrap_or(false)
|
match &context {
|
||||||
|
Some(context) => {
|
||||||
|
function.call::<mlua::MultiValue>((context.clone(), argument))
|
||||||
|
}
|
||||||
|
None => function.call::<mlua::MultiValue>(argument),
|
||||||
|
}
|
||||||
|
.map(|results| callback_size(data.len(), &results) == data.len())
|
||||||
|
.unwrap_or(false)
|
||||||
})
|
})
|
||||||
.map_err(LuaError::external)?;
|
.map_err(LuaError::external)?;
|
||||||
}
|
}
|
||||||
@@ -272,11 +351,11 @@ impl UserData for EasyHandle {
|
|||||||
});
|
});
|
||||||
|
|
||||||
methods.add_method_mut("setopt_writefunction", |lua, this, value: mlua::Value| {
|
methods.add_method_mut("setopt_writefunction", |lua, this, value: mlua::Value| {
|
||||||
Self::set_callback(lua, &mut this.write_callback, value)
|
Self::set_callback(lua, &mut this.write_callback, value, "write")
|
||||||
});
|
});
|
||||||
|
|
||||||
methods.add_method_mut("setopt_headerfunction", |lua, this, value: mlua::Value| {
|
methods.add_method_mut("setopt_headerfunction", |lua, this, value: mlua::Value| {
|
||||||
Self::set_callback(lua, &mut this.header_callback, value)
|
Self::set_callback(lua, &mut this.header_callback, value, "header")
|
||||||
});
|
});
|
||||||
|
|
||||||
methods.add_method_mut("perform", |lua, this, ()| this.perform(lua));
|
methods.add_method_mut("perform", |lua, this, ()| this.perform(lua));
|
||||||
|
|||||||
Reference in new issue
Block a user