Then attach that function to LuaPlayer, LuaGUI and LuaGuiElement? Below is my working proof-of-concept that such a function is already very much possible.
I'm experimenting with creating a GUI lib for my mods and one such experiment was a Jquery-ish selector for the GUI!
It made things a lot easier (to me) when working on GUI stuff; no more player.gui.top.myframe.some_flow.some_other_flow.my_element. That you have to remember to update in a hundred places anytime you rearrange your GUI. Sure the direct route is always faster but ease-of-use is awesome too.
Initially I tried a non-hack way but ran into issues with Factorio throwing errors no matter what I tried.
-------------------------------------------
gui.get
Now you can just do gui.get() and get back a table of matched elements or the single matched element directly or nil if no matches.All of the following work and return the same LuaGuiElement:
Code: Select all
gui.get(player, "my_element")
gui.get(player.gui, "my_element")
gui.get(player.gui.top, "my_element")
gui.get(player.gui.top.myframe, "my_element")
--Even these will work
gui.get(player.gui.top.myframe, "my_elem*")
gui.get(player.gui.top.myframe, "*_elem*")
gui.get(player.gui.top.myframe, "*_element")
--If you want to get real fancy use Lua Patterns.
Figured out my previous issue with pcall. I forgot the anonymous "wrapper" function. Too much coding and not enough sleep. Updated code block with new snippet