Skip to content

Commit

Permalink
Fix linting errors from debug.info
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio committed Dec 21, 2024
1 parent 02cb4ad commit 7c025a3
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions jecs.luau
Original file line number Diff line number Diff line change
Expand Up @@ -1606,13 +1606,15 @@ World.each = world_each
World.children = world_children

if _G.__JECS_DEBUG then
-- taken from https://github.com/centau/ecr/blob/main/src/ecr.luau
-- error but stack trace always starts at first callsite outside of this file
local function dbg_info(n: number): any
return debug.info(n, "s")
end
local function throw(msg: string)
local s = 1
local root = dbg_info(1)
repeat
s += 1
until debug.info(s, "s") ~= debug.info(1, "s")
until dbg_info(s) ~= root
if warn then
error(msg, s)
else
Expand All @@ -1627,15 +1629,18 @@ if _G.__JECS_DEBUG then
throw(msg)
end

local function get_name(world, id): string
local name: string | nil
local function get_name(world, id)
return world_get_one_inline(world, id, EcsName)
end

local function bname(world: World, id): string
local name: string
if ECS_IS_PAIR(id) then
name = `pair({get_name(world, ECS_ENTITY_T_HI(id))}, {get_name(world, ECS_ENTITY_T_LO(id))})`
local first = get_name(world, ecs_pair_first(world, id))
local second = get_name(world, ecs_pair_second(world, id))
name = `pair({first}, {second})`
else
local _1 = world_get_one_inline(world, id, EcsName)
if _1 then
name = `${_1}`
end
return get_name(world, id)
end
if name then
return name
Expand All @@ -1659,14 +1664,14 @@ if _G.__JECS_DEBUG then
World.set = function(world: World, entity: i53, id: i53, value: any): ()
local is_tag = ID_IS_TAG(world, id)
if is_tag and value == nil then
local _1 = get_name(world, entity)
local _2 = get_name(world, id)
local _1 = bname(world, entity)
local _2 = bname(world, id)
local why = "cannot set component value to nil"
throw(why)
return
elseif value ~= nil and is_tag then
local _1 = get_name(world, entity)
local _2 = get_name(world, id)
local _1 = bname(world, entity)
local _2 = bname(world, id)
local why = `cannot set a component value because {_2} is a tag`
why ..= `\n[jecs] note: consider using "world:add({_1}, {_2})" instead`
throw(why)
Expand All @@ -1678,8 +1683,8 @@ if _G.__JECS_DEBUG then

World.add = function(world: World, entity: i53, id: i53, value: any)
if value ~= nil then
local _1 = get_name(world, entity)
local _2 = get_name(world, id)
local _1 = bname(world, entity)
local _2 = bname(world, id)
throw("You provided a value when none was expected. " .. `Did you mean to use "world:add({_1}, {_2})"`)
end

Expand Down

0 comments on commit 7c025a3

Please sign in to comment.