[Lib] _L_U - access locals and upvalues via tables

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
TheZombieKiller
Prole
Posts: 8
Joined: Sun Dec 13, 2015 11:53 am
Location: Gold Coast, Australia
Contact:

[Lib] _L_U - access locals and upvalues via tables

Post by TheZombieKiller »

https://github.com/DaZombieKiller/_L_U

This is another old library of mine, that I decided to completely re-do today.
It adds an _L (locals) and _U (upvalues) table to Lua, similar to _G. It's intended for debugging, but may be useful for other purposes.

Note that _L and _U cannot be used to declare new locals or upvalues, but can be used to modify or access them.
This also allows you to easily add them to the global table, via something like this:

Code: Select all

for k, v in pairs(_L) do _G[k] = v end
for k, v in pairs(_U) do _G[k] = v end
The GitHub page includes an example file with explanations on how it all works.
I dunno if anyone will really find this useful in the long run, but I thought I might as well release it anyway.
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: [Lib] _L_U - access locals and upvalues via tables

Post by ivan »

Cool idea, but it would be nice if you have some practical examples on why/how I would want to use the lib (I assume it's for debugging).

The implementation is OK, but could be improved in the following way:
Every time we access "_L" a new table is constructed, containing every single "local" variable.
This is convenient for the "pairs" function, but it's not very efficient for access/assignment.
Access/assignments use "_L['foo']" so you probably don't need to fetch all "local" vars every time you access "_L['foo']".
Hope this makes sense.

Good work though, it's an interesting idea. :)
User avatar
TheZombieKiller
Prole
Posts: 8
Joined: Sun Dec 13, 2015 11:53 am
Location: Gold Coast, Australia
Contact:

Re: [Lib] _L_U - access locals and upvalues via tables

Post by TheZombieKiller »

Fair point you have there, I'll probably add some optimizations to it later on.
Also yeah, it's intended for debugging, although it has other possible uses I guess.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests