scripting: update elua, change test lua script

This commit is contained in:
SeanOMik 2024-02-17 19:08:11 -05:00
parent 955ca03587
commit 20a36795dc
Signed by: SeanOMik
GPG Key ID: FEC9E2FC15235964
3 changed files with 13 additions and 39 deletions

View File

@ -12,32 +12,10 @@ function on_pre_update()
print("Lua's pre-update function was called") print("Lua's pre-update function was called")
end ]] end ]]
---
---Recursively dumps a table as a string.
---
---@param obj table
---@return string
---@nodiscard
function dump_table(obj)
if type(obj) == 'table' then
local s = '{ '
for k,v in pairs(obj) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump_table(v) .. ','
end
return s .. '} '
else
return tostring(obj)
end
end
function on_update() function on_update()
--print("Lua's update function was called") --print("Lua's update function was called")
--local v = Vec3:new(50, 10, 20) --[[ world:view(
--print("Vec3 = " .. tostring(v))
world:view(
---@param t Transform ---@param t Transform
function (t) function (t)
print("Found entity at a really cool place: " .. tostring(t)) print("Found entity at a really cool place: " .. tostring(t))
@ -46,17 +24,18 @@ function on_update()
return t return t
end, end,
Transform Transform
) ) ]]
-- local dt = world:resource(DeltaTime) local dt = world:resource(DeltaTime)
-- --print("DeltaTime was " .. tostring(dt) .. "s") --print("DeltaTime was " .. tostring(dt) .. "s")
--
-- world:view(function (t) world:view(function (t)
-- --print("Found entity at a really cool place: " .. tostring(t)) --print("Found entity at a really cool place: " .. tostring(t))
-- t.translation = t.translation + (Vec3.new(0, 0.5, 0) * dt:get()) --t.translation = t.translation + (Vec3.new(0, 0.5, 0) * dt:get())
-- t.translation:move_by(0, 0.5 * dt:get(), 0)
-- return t
-- end, Transform) return t
end, Transform)
end end
--[[ function on_post_update() --[[ function on_post_update()

@ -1 +1 @@
Subproject commit 8b88612890f7d67472b56cd97711bb037198ebf9 Subproject commit 2fe5dca6c4337f1528e4671d1f79464481739c61

View File

@ -54,10 +54,6 @@ impl elua::Userdata for ScriptWorldPtr {
fn build<'a>(state: &elua::State, builder: &mut elua::UserdataBuilder<'a, Self>) -> elua::Result<()> { fn build<'a>(state: &elua::State, builder: &mut elua::UserdataBuilder<'a, Self>) -> elua::Result<()> {
builder builder
.method("test", |_, this, ()| {
println!("hgello world");
Ok(())
})
.method_mut("spawn", |_, this, bundle: ScriptDynamicBundle| { .method_mut("spawn", |_, this, bundle: ScriptDynamicBundle| {
let world = this.as_mut(); let world = this.as_mut();
@ -199,7 +195,6 @@ impl elua::Userdata for ScriptWorldPtr {
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!");
let reg_type = this.as_ref().get_type::<RegisteredType>(reflect.reflect_branch.reflect_type_id()) let reg_type = this.as_ref().get_type::<RegisteredType>(reflect.reflect_branch.reflect_type_id())
.unwrap(); .unwrap();
let proxy = reg_type.get_data::<ReflectLuaProxy>() let proxy = reg_type.get_data::<ReflectLuaProxy>()