Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

32
LINES

< > BotCompany Repo | #151 // luaPrintVars

Lua code

local serpent = grab('#158')
local function tableToLua(t)
  return "return "..serpent.block(t)
end

local function isSimpleTable(tbl, seen)
  if seen == nil then seen = {} end
  local seen = {}
  if seen[tbl] then return false end -- has cycles, not simple
  local t = type(tbl)
  if t == 'number' or t == 'string' then return true end
  if t ~= 'table' then return false end
  seen[tbl] = true
  for k, v in pairs(tbl) do
    if not isSimpleTable(k, seen)
      or not isSimpleTable(t, seen) then
        return false
    end
  end
end

local lines = {}
for k, v in pairs(_G) do
  if type(v) == 'number' then
    table.insert(lines, k..'='..tostring(v))
  elseif type(v) == 'string' then
    table.insert(lines, k..'='..('%q'):format(v))
  elseif type(v) == 'table' and isSimpleTable(v) then
    table.insert(lines, k..'='..tableToLua(v))
  end
end
return table.concat(lines, "\n")

Author comment

Special snippet. Used for updating objects.

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Image recognition results

Recognizer Recognition Result Visualize Recalc
#308 913 [visualize]

Snippet ID: #151
Snippet name: luaPrintVars
Eternal ID of this version: #151/1
Text MD5: 71efc65a03bb83a6114d8a1c4eb32277
Author: stefan
Category: internal helpers
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2014-01-13 05:18:29
Source code size: 913 bytes / 32 lines
Pitched / IR pitched: Yes / Yes
Views / Downloads: 772 / 191
Referenced in: [show references]