Lua API global Variable Viewer (gvv)

by Ritn

This is a debugging tool. This mod adds commands /gvv and others and a hotkey(Ctrl+Shift+V) to allow you to check _G and global table of map or each mods. Only admins can use command if it is multiplay game. You have to input some code for temporary accessibility or have to edit "control.lua" of other mod or map to access global table of the mod or map. See "Helper" tab for instructions.

Utilities
2 months ago
1.0 - 2.0
3.72K

b [0.5.13 fixes] 0.5.11: Error when running interface function

2 months ago
(updated 2 months ago)

Sorry, I've accidentally replaced my original bug report with what was meant as a follow-up message. Here is the original text again:

With gvv 0.5.11, gvv errors in remote.call("__autodrive__gvv", "_G") and remote.call("__autodrive__gvv", "storage"). The game doesn't crash, but when clicking on the "autodrive" button in the "storage" tab of gvv's GUI, I only get an error message returned by my mod instead of seeing the contents of my tables.

The crash is caused by the following snippet I've added to my control.lua:

local allowed_vars = {
  data = true,
  game = true,
  mods = true,
}

setmetatable(_ENV, {
  __newindex  = function(self, key, value)    -- locked_global_write
    error('\n\n[ER Global Lock] Forbidden global *write*:\n' ..
          serpent.line({key = key or '<nil>', value = value or '<nil>'})..'\n')
  end,
  __index     = function(self, key)           -- locked_global_read
    if not allowed_vars[key] then
      error('\n\n[ER Global Lock] Forbidden global *read*:\n' ..
          serpent.line({key = key or '<nil>'})..'\n')
    end
  end
})

This is a safeguard against using undeclared variables. I use this in all my mods that act in the control stage. Some modders I've collaborated with have also added the snippet to their mods (e.g., Vehicle Wagon 2 by robot256). According to the error message, function __newindex is called for copy_object, which is not declared in the context of autodrive.

2 months ago

I've sent you a PM on the forum with a screenshot of your GUI that shows the actual error message.

2 months ago

Thank you so much for the detailed report and for sharing your global lock snippet!

This issue occurs because GVV recursively iterates over all keys in _G, and your _ENV metatable forbids access to non-whitelisted globals (like copy_object).

In the next version, I will improve the global inspection to wrap each access in pcall, so that if a key is forbidden, it will be skipped safely without raising an error.

Meanwhile, as a temporary workaround, you could consider temporarily disabling your _ENV lock when using GVV's storage or _G dump, or explicitly allow the needed keys.

Thank you again for helping improve GVV!

2 months ago

I answered you on the forum in PM

2 months ago

Thank you very much! Everything is working as expected again in version 0.5.13!

2 months ago
(updated 2 months ago)

Sorry, I just noticed another bug: If I try to view a Lua object (force, entity etc.) in _G or storage, I now get an error for forbidden read of key exclude_classes.

2 months ago

This should work in version 0.5.14!

2 months ago

It does. Thank you for the quick fix! :-)

New response