0 Replies - 1364 Views - Last Post: 05 June 2010 - 08:27 PM

#1 athlon32   User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 363
  • Joined: 20-August 08

[LUA]Dump Functions

Posted 05 June 2010 - 08:27 PM

Description: Tested on Lua 5.1.4 Please report any problems.Occasionally (in debugging) you just need a quick and dirty listing of what's in a table. Here is that 'quick and dirty' function :D It also has a special function to handle the global table.
-- Simply dumps a table, and is pretty much only a wrapper
-- for a loop. It is useful however, because you can specify
-- a specific type, and only values of that type will be listed
local function dump(x,y)
    if type(x) ~= "table" then
        error("expected table and string, but got " .. type(x) .. " and " ..type(y), 2);

    for k,v in pairs(x) do
        -- if a type is specified, check to see
        -- if current value is of right type.
        if y ~= nil then
            if type(v) == y then 
                print(k, "t", v);
            print(k, "t", v)

-- Once again, just another wrapper. Still useful.
function globaldump(type)
    print("Current Lua Memory Usage: "..collectgarbage("count").." Kilobytesn");
    dump(_G, type);

x,y,z = 3,6,8; -- make some globals...

-- see all global data

-- uncomment to see all global data of type table
-- globaldump("table");

Is This A Good Question/Topic? 0
  • +

Page 1 of 1