mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Support for multiple return values
This commit is contained in:
parent
f10815e903
commit
22aaa9fb18
3 changed files with 126 additions and 8 deletions
|
@ -336,3 +336,113 @@ impl LuaGetValue for Color {
|
|||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T0: LuaGetValue, T1: LuaGetValue> LuaGetValue for (T0, T1) {
|
||||
fn get(lua: LuaState, index: i32) -> eyre::Result<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
Ok((T0::get(lua, index - T1::size())?, T1::get(lua, index)?))
|
||||
}
|
||||
|
||||
fn size() -> i32 {
|
||||
T0::size() + T1::size()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T0: LuaGetValue, T1: LuaGetValue, T2: LuaGetValue> LuaGetValue for (T0, T1, T2) {
|
||||
fn get(lua: LuaState, index: i32) -> eyre::Result<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
Ok((
|
||||
T0::get(lua, index - T1::size() - T2::size())?,
|
||||
T1::get(lua, index - T2::size())?,
|
||||
T2::get(lua, index)?,
|
||||
))
|
||||
}
|
||||
|
||||
fn size() -> i32 {
|
||||
T0::size() + T1::size() + T2::size()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T0: LuaGetValue, T1: LuaGetValue, T2: LuaGetValue, T3: LuaGetValue> LuaGetValue
|
||||
for (T0, T1, T2, T3)
|
||||
{
|
||||
fn get(lua: LuaState, index: i32) -> eyre::Result<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
Ok((
|
||||
T0::get(lua, index - T1::size() - T2::size() - T3::size())?,
|
||||
T1::get(lua, index - T2::size() - T3::size())?,
|
||||
T2::get(lua, index - T3::size())?,
|
||||
T3::get(lua, index)?,
|
||||
))
|
||||
}
|
||||
|
||||
fn size() -> i32 {
|
||||
T0::size() + T1::size() + T2::size() + T3::size()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T0: LuaGetValue, T1: LuaGetValue, T2: LuaGetValue, T3: LuaGetValue, T4: LuaGetValue>
|
||||
LuaGetValue for (T0, T1, T2, T3, T4)
|
||||
{
|
||||
fn get(lua: LuaState, index: i32) -> eyre::Result<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let prev = <(T0, T1, T2, T3)>::get(lua, index - T4::size())?;
|
||||
Ok((prev.0, prev.1, prev.2, prev.3, T4::get(lua, index)?))
|
||||
}
|
||||
|
||||
fn size() -> i32 {
|
||||
<(T0, T1, T2, T3)>::size() + T4::size()
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
T0: LuaGetValue,
|
||||
T1: LuaGetValue,
|
||||
T2: LuaGetValue,
|
||||
T3: LuaGetValue,
|
||||
T4: LuaGetValue,
|
||||
T5: LuaGetValue,
|
||||
> LuaGetValue for (T0, T1, T2, T3, T4, T5)
|
||||
{
|
||||
fn get(lua: LuaState, index: i32) -> eyre::Result<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let prev = <(T0, T1, T2, T3, T4)>::get(lua, index - T5::size())?;
|
||||
Ok((prev.0, prev.1, prev.2, prev.3, prev.4, T5::get(lua, index)?))
|
||||
}
|
||||
|
||||
fn size() -> i32 {
|
||||
<(T0, T1, T2, T3, T4)>::size() + T5::size()
|
||||
}
|
||||
}
|
||||
|
||||
impl LuaGetValue for (bool, bool, bool, f64, f64, f64, f64, f64, f64, f64, f64) {
|
||||
fn get(lua: LuaState, index: i32) -> eyre::Result<Self> {
|
||||
Ok((
|
||||
bool::get(lua, index - 10)?,
|
||||
bool::get(lua, index - 9)?,
|
||||
bool::get(lua, index - 8)?,
|
||||
f64::get(lua, index - 7)?,
|
||||
f64::get(lua, index - 6)?,
|
||||
f64::get(lua, index - 5)?,
|
||||
f64::get(lua, index - 4)?,
|
||||
f64::get(lua, index - 3)?,
|
||||
f64::get(lua, index - 2)?,
|
||||
f64::get(lua, index - 1)?,
|
||||
f64::get(lua, index)?,
|
||||
))
|
||||
}
|
||||
|
||||
fn size() -> i32 {
|
||||
11
|
||||
}
|
||||
}
|
||||
|
|
|
@ -226,13 +226,13 @@ fn generate_code_for_api_fn(api_fn: ApiFn) -> proc_macro2::TokenStream {
|
|||
let ret_type = if api_fn.rets.is_empty() {
|
||||
quote! { () }
|
||||
} else {
|
||||
// TODO support for more than one return value.
|
||||
// if api_fn.rets.len() == 1 {
|
||||
if api_fn.rets.len() == 1 {
|
||||
let ret = api_fn.rets.first().unwrap();
|
||||
ret.typ.as_rust_type_return()
|
||||
// } else {
|
||||
// quote! { ( /* todo */) }
|
||||
// }
|
||||
} else {
|
||||
let ret_types = api_fn.rets.iter().map(|ret| ret.typ.as_rust_type_return());
|
||||
quote! { ( #(#ret_types),* ) }
|
||||
}
|
||||
};
|
||||
|
||||
let fn_name_c = name_to_c_literal(api_fn.fn_name);
|
||||
|
|
|
@ -122,8 +122,16 @@ fn test_fn(_lua: LuaState) -> eyre::Result<()> {
|
|||
);
|
||||
let hp = damage_model.hp()?;
|
||||
|
||||
let transform = noita_api::raw::entity_get_transform(player)?;
|
||||
|
||||
noita_api::raw::game_print(
|
||||
format!("Component: {:?}, Hp: {}", damage_model.0, hp * 25.0).into(),
|
||||
format!(
|
||||
"Component: {:?}, Hp: {}, tranform: {:?}",
|
||||
damage_model.0,
|
||||
hp * 25.0,
|
||||
transform
|
||||
)
|
||||
.into(),
|
||||
)?;
|
||||
|
||||
// noita::api::raw::entity_set_transform(player, 0.0, 0.0, 0.0, 1.0, 1.0)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue