Why is undo.GetTable() Local?

I’m pretty sure he means that you can still access the ClientUndos local by using debug.getupvalue on a function stored in the module table, rather than locals.

The only thing that will return is bIsDirty…

Argh, forgot about that.

local ClientUndos = debug.getupvalues(debug.getupvalues(debug.getupvalues(undo.SetupUI).CPanelUpdate).UpdateUI).ClientUndos


Tested it? <:

local ClientUndos = debug.getupvalues(debug.getupvalues(usermessage.Hook).Hooks.Undone).ClientUndos

or that.


Friggen breaking my automerge >:|

No, but in theory…

I use the undo table in my own PropProtection to remove undos from an entity. Just open the undo.lua in lua/included/modules and remove the local in front of the GetTable function. Epic Win. Here an example.
function PropProtection.Removeundo(ent)
local tbl = {}
if !undo.GetTable then return end
tbl = undo.GetTable()
for k,v in pairs(tbl) do
for k2,v2 in pairs(v) do
for k3,v3 in pairs(v2.Entities) do
if v3:IsValid() then
if v3 == ent then
table.remove(tbl[k], k2)
k2 = nil

I don’t think doing that is very effective…
[lua]function undo.GetTable()-- Thanks deco da man
return debug.getupvalues(debug.getupvalues(debug.getupvalues(undo.SetupUI).CPanelUpdate).UpdateUI).ClientUndos

suggestion: Get the table once at the top of your file and just return it. Using the debug funtions regularly is a bad idea, because they’re for debugging.


local CLUndos = debug…
if you mean that, the table won’t update.

It should, as tables in Lua are passed as references.

] lua_run_cl PrintTable(undo.GetTable())
] lua_run_cl PrintTable(undo.GetTable())
] lua_run_cl PrintTable(debug.getupvalues(debug.getupvalues(debug.getupvalues(undo.SetupUI).CPanelUpdate).UpdateUI).ClientUndos)
Key = 2
Name = Prop (models/props_combine/breendesk.mdl)
Key = 1
Name = Prop (models/props_combine/breendesk.mdl)

Well it doesn’t.

Garry didn’t use table.insert, and instead decided to create an entirely new table each time he wanted to add an undo at index 1 (in AddUndo).

Looks like doing it each time is the only way.

I’m curious into why you need this table. Mind splurting a brief description of the project?

It’s a private project.
I haven’t inserted this in it yet as it could work without, but it would be less effective.

I have made a script that automatically spawns a prop when you are about to get fall damage. Spawning this prop is to prevent falldamage. This prop needs to be removed, but if you spawn something before gmod_undo is run by the script, the script will remove the prop you spawned later.

Same is for a prop that spawns in you when you’re standing on the ground (Makes you stuck in prop, so people can’t shoot you)

Or __index it after accessing it.