Compare commits

..

1 commit

Author SHA1 Message Date
nonamie
a38a0c33d7
Merge e8575a0db6 into 02cb4ad7a2 2024-12-21 20:45:30 +03:00

View file

@ -1606,15 +1606,13 @@ World.each = world_each
World.children = world_children World.children = world_children
if _G.__JECS_DEBUG then if _G.__JECS_DEBUG then
local function dbg_info(n: number): any -- taken from https://github.com/centau/ecr/blob/main/src/ecr.luau
return debug.info(n, "s") -- error but stack trace always starts at first callsite outside of this file
end
local function throw(msg: string) local function throw(msg: string)
local s = 1 local s = 1
local root = dbg_info(1)
repeat repeat
s += 1 s += 1
until dbg_info(s) ~= root until debug.info(s, "s") ~= debug.info(1, "s")
if warn then if warn then
error(msg, s) error(msg, s)
else else
@ -1629,18 +1627,15 @@ if _G.__JECS_DEBUG then
throw(msg) throw(msg)
end end
local function get_name(world, id) local function get_name(world, id): string
return world_get_one_inline(world, id, EcsName) local name: string | nil
end
local function bname(world: World, id): string
local name: string
if ECS_IS_PAIR(id) then if ECS_IS_PAIR(id) then
local first = get_name(world, ecs_pair_first(world, id)) name = `pair({get_name(world, ECS_ENTITY_T_HI(id))}, {get_name(world, ECS_ENTITY_T_LO(id))})`
local second = get_name(world, ecs_pair_second(world, id))
name = `pair({first}, {second})`
else else
return get_name(world, id) local _1 = world_get_one_inline(world, id, EcsName)
if _1 then
name = `${_1}`
end
end end
if name then if name then
return name return name
@ -1664,14 +1659,14 @@ if _G.__JECS_DEBUG then
World.set = function(world: World, entity: i53, id: i53, value: any): () World.set = function(world: World, entity: i53, id: i53, value: any): ()
local is_tag = ID_IS_TAG(world, id) local is_tag = ID_IS_TAG(world, id)
if is_tag and value == nil then if is_tag and value == nil then
local _1 = bname(world, entity) local _1 = get_name(world, entity)
local _2 = bname(world, id) local _2 = get_name(world, id)
local why = "cannot set component value to nil" local why = "cannot set component value to nil"
throw(why) throw(why)
return return
elseif value ~= nil and is_tag then elseif value ~= nil and is_tag then
local _1 = bname(world, entity) local _1 = get_name(world, entity)
local _2 = bname(world, id) local _2 = get_name(world, id)
local why = `cannot set a component value because {_2} is a tag` local why = `cannot set a component value because {_2} is a tag`
why ..= `\n[jecs] note: consider using "world:add({_1}, {_2})" instead` why ..= `\n[jecs] note: consider using "world:add({_1}, {_2})" instead`
throw(why) throw(why)
@ -1683,8 +1678,8 @@ if _G.__JECS_DEBUG then
World.add = function(world: World, entity: i53, id: i53, value: any) World.add = function(world: World, entity: i53, id: i53, value: any)
if value ~= nil then if value ~= nil then
local _1 = bname(world, entity) local _1 = get_name(world, entity)
local _2 = bname(world, id) local _2 = get_name(world, id)
throw("You provided a value when none was expected. " .. `Did you mean to use "world:add({_1}, {_2})"`) throw("You provided a value when none was expected. " .. `Did you mean to use "world:add({_1}, {_2})"`)
end end