Skip to content

add SMODS.deepfind and SMODS.deepfindbyindex#360

Merged
WilsontheWolf merged 19 commits into
Steamodded:mainfrom
cg-223:deepfind
Jan 5, 2025
Merged

add SMODS.deepfind and SMODS.deepfindbyindex#360
WilsontheWolf merged 19 commits into
Steamodded:mainfrom
cg-223:deepfind

Conversation

@cg-223
Copy link
Copy Markdown
Contributor

@cg-223 cg-223 commented Dec 28, 2024

this hopefully addresses the issue of nodes[1] chaining
see changes for more info

this hopefully addresses the issue of nodes[1] chaining
@cg-223
Copy link
Copy Markdown
Contributor Author

cg-223 commented Dec 29, 2024

@cg-223
Copy link
Copy Markdown
Contributor Author

cg-223 commented Dec 30, 2024

tested with following commands:
eval SMODS.deepfind(_G, 6)[1].tree

Table:
1: Cryptid
2: obj_buffer
3: Booster
4: 3
5: cost

eval SMODS.deepfind(_G, 6)[1].objtree

Table:
1: Table:
M_jokers: table: 0x2097d4f8
get_food: function: 0x2097d610
food: table: 0x2097d558
....
2: Table:
Atlas: table: 0x215a4580
Seal: table: 0x213bd768
ConsumableType: table: 0x216822d0
...
3: Table:
1: table: 0x2166e5f8
2: table: 0x2166e8c8
3: table: 0x2166eb98
...
4: Table:
alerted: true
weight: 0.48
object_type: Booster
...
5: 6

eval SMODS.deepfind(_G, 6)

Table of 1434, each consisting of:
objtree: table
tree: table
table: table
index: value

eval SMODS.deepfind(_G, _G)

2 results

eval inspect(SMODS.deepfind(_G, _G)[1].tree)

1: _G

eval inspect(SMODS.deepfind(_G, _G)[2].tree)

1: package
2: loaded
3: _G

eval SMODS.deepfindbyindex(_G, "button")

table of 33. all indexes are "button"

eval inspect(SMODS.deepfindbyindex(_G, "button")[12].tree)

1: G
2: MOVEABLES
3: 333
4: config
5: button

eval local t = love.timer.getTime() SMODS.deepfind(_G, "thisvaldoesntexist") print(love.timer.getTime() - t)

0.071321699999999

eval local t = love.timer.getTime() SMODS.deepfind(_G, true) print(love.timer.getTime() - t)

0.082477799999992

eval local t = love.timer.getTime() for i = 1, 10000 do SMODS.deepfind(G.GAME, "thisdoesntexist") end print(love.timer.getTime() - t)

2.6902233

eval local t = love.timer.getTime() for i = 1, 10000 do SMODS.deepfind(G.GAME, true) end print(love.timer.getTime() - t)

oom

@cg-223
Copy link
Copy Markdown
Contributor Author

cg-223 commented Dec 30, 2024

in conclusion everything works as expected. traversing the entire global space takes barely any time at all, and youll never need to do that anyways. it seems that care needs to be taken if the function is to be called a shit ton, but considering its main use is to be called once to find something (where the desired results can then be saved if you'll need it later)

@cg-223 cg-223 changed the title add SMODS.deepfind add SMODS.deepfind and SMODS.deepfindbyindex Dec 30, 2024
@cg-223
Copy link
Copy Markdown
Contributor Author

cg-223 commented Dec 30, 2024

for above commit:
will return immediately if a third argument to deepfind and deepfindbyindex, immediate, is provided. it will return exactly the same way, except youre guaranteed to either get 0 or 1 result inside collector. to get a value you only expect to see once, and wish to error if said value isnt found, do
local res = assert(next(SMODS.deepfind(_G, "this will only appear once", true)))

@cg-223
Copy link
Copy Markdown
Contributor Author

cg-223 commented Dec 30, 2024

why did cg223 try pulling the bottom out of a stack thinking it would be performant ? is he stupid ?

@cg-223
Copy link
Copy Markdown
Contributor Author

cg-223 commented Jan 1, 2025

should be done. im not at my computer, did that commit on my phone, so someone's gonna need to make sure the functions still work (which will be me around noon tomorrow assuming nobody else does it before then)

@cg-223
Copy link
Copy Markdown
Contributor Author

cg-223 commented Jan 2, 2025

okay for some reason after said finalizing, deepfind finds significantly fewer results

@cg-223
Copy link
Copy Markdown
Contributor Author

cg-223 commented Jan 2, 2025

nevermind. not sure what i was seeing. both old commit and latest commit got the exact same amount.

7420f62c3b626358791e4735d5cc50e5955f97b7 (latest):
eval SMODS.deepfind(_G, "Cryptid") -- 13
eval SMODS.deepfindbyindex(_G, "Cryptid") -- 4
eval SMODS.deepfind(_G, "Ace") -- 59
eval SMODS.deepfindbyindex(_G, "Ace") -- 3
eval SMODS.deepfind(_G, 35) -- 54
eval SMODS.deepfindbyindex(_G, 35) --101

9e9bf914ed743ab9f7f8524137fc7be5b88d8ac8 (old):
eval SMODS.deepfind(_G, "Cryptid") -- 13
eval SMODS.deepfindbyindex(_G, "Cryptid") -- 4
eval SMODS.deepfind(_G, "Ace") -- 59
eval SMODS.deepfindbyindex(_G, "Ace") -- 3
eval SMODS.deepfind(_G, 35) -- 54
eval SMODS.deepfindbyindex(_G, 35) --101

so no issues. all those changes were just removing comments anyways lol. nothing couldve changed except for unrelated merges. anyways im not gonna touch this anymore

@WilsontheWolf
Copy link
Copy Markdown
Member

Looks good to me

@WilsontheWolf WilsontheWolf merged commit 74cf5aa into Steamodded:main Jan 5, 2025
@cg-223 cg-223 deleted the deepfind branch January 5, 2025 06:46
WilsontheWolf added a commit to WilsontheWolf/Steamodded that referenced this pull request Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants