This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
クデル's profile picture

Checking if Variable/Table is Used

Started by クデル, 08 November 2015 - 11:59 AM
クデル #1
Posted 08 November 2015 - 12:59 PM
I want to essentially be able to tell if a variable or table in _G is being used. I am wanting to create a simple garbage collector, checking data that is stored in _G is simple enough, but is checking if its used by another program possible?
Bomb Bloke #2
Posted 08 November 2015 - 01:11 PM
The only idea that comes to mind would be to wait until no user scripts are running before performing your checks. You may still end up "cleaning" data they intend to use with later executions, mind you.

A simple way of doing that would be to construct a custom environment table, metatable it together with the real _G, then os.run() user scripts with it. If they try to add something, it won't go into the real _G, making it easy to discard when their script completes.
クデル #3
Posted 08 November 2015 - 01:23 PM
It's for an "OS", so I plan to have the program ignore one specific table, which I will be treating as a registry of sorts.

Thanks for helping out :)/>