scripting: implement querying for resources from lua

This commit is contained in:
SeanOMik 2024-02-12 20:04:50 -05:00
parent 6465ed2e0b
commit 747d4dcf19
Signed by: SeanOMik
GPG Key ID: FEC9E2FC15235964
1 changed files with 20 additions and 2 deletions

View File

@ -1,4 +1,4 @@
use std::{sync::Arc, ptr::NonNull, any::Any, ops::Deref}; use std::{sync::{Arc, RwLock}, ptr::NonNull, any::Any, ops::Deref};
use lyra_ecs::query::dynamic::QueryDynamicType; use lyra_ecs::query::dynamic::QueryDynamicType;
use lyra_reflect::{TypeRegistry, ReflectWorldExt, RegisteredType}; use lyra_reflect::{TypeRegistry, ReflectWorldExt, RegisteredType};
@ -6,7 +6,7 @@ use mlua::{AnyUserDataExt, IntoLua, IntoLuaMulti};
use crate::{ScriptWorldPtr, ScriptEntity, ScriptDynamicBundle, ScriptBorrow}; use crate::{ScriptWorldPtr, ScriptEntity, ScriptDynamicBundle, ScriptBorrow};
use super::{ReflectedIterator, DynamicViewIter, FN_NAME_INTERNAL_REFLECT_TYPE, reflect_user_data, ReflectLuaProxy}; use super::{ReflectedIterator, DynamicViewIter, FN_NAME_INTERNAL_REFLECT_TYPE, reflect_user_data, ReflectLuaProxy, FN_NAME_INTERNAL_REFLECT};
impl<'lua> mlua::FromLua<'lua> for ScriptEntity { impl<'lua> mlua::FromLua<'lua> for ScriptEntity {
fn from_lua(value: mlua::Value<'lua>, _lua: &'lua mlua::Lua) -> mlua::Result<Self> { fn from_lua(value: mlua::Value<'lua>, _lua: &'lua mlua::Lua) -> mlua::Result<Self> {
@ -165,6 +165,24 @@ impl mlua::UserData for ScriptWorldPtr {
.call_function::<_, ScriptBorrow>(FN_NAME_INTERNAL_REFLECT_TYPE, ()) .call_function::<_, ScriptBorrow>(FN_NAME_INTERNAL_REFLECT_TYPE, ())
.expect("Type does not implement 'reflect_type' properly"); .expect("Type does not implement 'reflect_type' properly");
//if let Some(data) = reflect.data {
/* let res = reflect.reflect_branch.as_resource_unchecked();
if let Some(res_ptr) = res.reflect_arc(this.as_mut()) {
let reg_type = this.as_ref().get_type::<RegisteredType>(reflect.reflect_branch.reflect_type_id())
.unwrap();
let proxy = reg_type.get_data::<ReflectLuaProxy>()
.expect("Type does not have ReflectLuaProxy as a TypeData");
//let res = Arc::new(RwLock::new(data.as_any_box()))
(proxy.fn_as_uservalue_ref)(lua, res_ptr)
.and_then(|ud| ud.into_lua(lua))
//Ok(mlua::Value::Nil)
} else {
Ok(mlua::Value::Nil)
} */
let res = reflect.reflect_branch.as_resource_unchecked(); let res = reflect.reflect_branch.as_resource_unchecked();
if let Some(res_ptr) = res.reflect_ptr(this.as_mut()) { if let Some(res_ptr) = res.reflect_ptr(this.as_mut()) {
//.expect("Failed to find resource pointer in world!"); //.expect("Failed to find resource pointer in world!");