Wie kann man eine Tabelle auf die Konsole werfen?


108

Ich habe Probleme beim Anzeigen des Inhalts einer Tabelle, die verschachtelte Tabellen enthält (n-tief). Ich möchte es einfach über eine printAnweisung oder etwas schnelles und schmutziges auf den Standard oder auf die Konsole werfen, aber ich kann nicht herausfinden, wie. Ich suche nach dem groben Äquivalent, das ich beim Drucken einer NSDictionarymit GDB erhalten würde.

Antworten:


56

Fühlen Sie sich frei, das Lua-Wiki zur Tabellenserialisierung zu durchsuchen . Es werden verschiedene Möglichkeiten zum Speichern einer Tabelle auf der Konsole aufgeführt.

Sie müssen nur auswählen, welches am besten zu Ihnen passt. Es gibt viele Möglichkeiten, dies zu tun, aber normalerweise verwende ich die von Penlight :

> t = { a = { b = { c = "Hello world!", 1 }, 2, d = { 3 } } }
> require 'pl.pretty'.dump(t)
{
  a = {
    d = {
      3
    },
    b = {
      c = "Hello world!",
      1
    },
    2
  }
}

6
Dumme und noch neuere Frage: Wie installiere ich eine Erweiterung wie pl.pretty? Es ist schön, wenn ich einfach so etwas wie eine Edelsteininstallation machen könnte, ohne mit abrollenden Teerbällen herumzuschnüffeln und den idealen Platz auf meiner HD zu finden, um Dinge zu lokalisieren. Gibt es ein schnelles / schmerzloses "Do-it-this-way"?
Cliff

Dah, ich hätte mir die Homepage ansehen sollen, bevor ich diesen letzten Kommentar gepostet habe! Die Installation ist nicht so schnell / schmerzlos wie ich gehofft hatte, aber nicht schlecht.
Cliff

Die Taschenlampe beleuchtet das, wonach ich gesucht habe!
Cliff

7
@ Cliff Luarocks, zum der Taschenlampe zu installieren
Vagabund

101

Ich weiß, dass diese Frage bereits als beantwortet markiert wurde, aber lassen Sie mich hier meine eigene Bibliothek einbinden. Es heißt inspect.lua und ist hier zu finden:

https://github.com/kikito/inspect.lua

Es ist nur eine einzelne Datei, die Sie von jeder anderen Datei benötigen können. Es gibt eine Funktion zurück, die einen beliebigen Lua-Wert in eine für Menschen lesbare Zeichenfolge umwandelt:

local inspect = require('inspect')

print(inspect({1,2,3})) -- {1, 2, 3}
print(inspect({a=1,b=2})
-- {
--   a = 1
--   b = 2
-- }

Untertabellen werden ordnungsgemäß eingerückt und "rekursive Tabellen" (Tabellen, die Verweise auf sich selbst enthalten) werden korrekt behandelt, sodass keine Endlosschleifen entstehen. Es sortiert Werte auf vernünftige Weise. Es werden auch metatable Informationen gedruckt.

Grüße!


Vielleicht solltest du deine Bibliothek zum Lua Wiki hinzufügen . Ich sehe, dass Ihre Bibliothek auch Metatables druckt, was die anderen Bibliotheken nicht tun.
Michal Kottman

Die Sache ist, dass inspect.lua nicht wirklich in die Kategorie "Serialisierung" passt. Der zurückgegebene Text ist kein gültiger Lua-Code. Es soll zum Debuggen / menschlichen Lesen verwendet werden. Ich nehme an, ich könnte am Ende einen kleinen Link hinzufügen oder so.
Kikito

1
Inspect.lua zum Wiki hinzugefügt.
Kikito

Bitte legen Sie dies auf Luarocks
Hack-R

3
@ Hack-R es ist auf luarocks:luarocks install inspect
kikito

85

Ich fand das nützlich. Denn bei der Rekursion können auch verschachtelte Tabellen gedruckt werden. Es gibt nicht die schönste Formatierung in der Ausgabe, aber für eine so einfache Funktion ist es schwer zu schlagen für das Debuggen.

function dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = '"'..k..'"' end
         s = s .. '['..k..'] = ' .. dump(v) .. ','
      end
      return s .. '} '
   else
      return tostring(o)
   end
end

z.B

local people = {
   {
      name = "Fred",
      address = "16 Long Street",
      phone = "123456"
   },

   {
      name = "Wilma",
      address = "16 Long Street",
      phone = "123456"
   },

   {
      name = "Barney",
      address = "17 Long Street",
      phone = "123457"
   }

}

print("People:", dump(people))

Erzeugt die folgende Ausgabe:

Personen: {[1] = {["Adresse"] = 16 Long Street, ["Telefon"] = 123456, ["Name"] = Fred,}, [2] = {["Adresse"] = 16 Long Street , ["Telefon"] = 123456, ["Name"] = Wilma,}, [3] = {["Adresse"] = 17 Long Street, ["Telefon"] = 123457, ["Name"] = Barney, },}


1
Gut gemacht, um etwas zu teilen, das keine externe Bibliothek benötigt.
Julian Knight

Auf einem wirklich großen Tisch wirft Ihre Funktion einen Stackoverflow-Fehler aus
Herrgott

20

Ich habe es gefunden:

-- Print contents of `tbl`, with indentation.
-- `indent` sets the initial level of indentation.
function tprint (tbl, indent)
  if not indent then indent = 0 end
  for k, v in pairs(tbl) do
    formatting = string.rep("  ", indent) .. k .. ": "
    if type(v) == "table" then
      print(formatting)
      tprint(v, indent+1)
    elseif type(v) == 'boolean' then
      print(formatting .. tostring(v))      
    else
      print(formatting .. v)
    end
  end
end

von hier https://gist.github.com/ripter/4270799

funktioniert ziemlich gut für mich ...


19

Die meisten reinen Lua-Drucktabellenfunktionen, die ich gesehen habe, haben ein Problem mit der tiefen Rekursion und neigen dazu, einen Stapelüberlauf zu verursachen, wenn sie zu tief gehen. Diese Drucktabellenfunktion, die ich geschrieben habe, hat dieses Problem nicht. Aufgrund der Art der Verkettung sollte es auch in der Lage sein, wirklich große Tabellen zu verarbeiten. Bei meiner persönlichen Verwendung dieser Funktion wurden 63.000 Zeilen ausgegeben, um sie in etwa einer Sekunde abzulegen.

Die Ausgabe behält auch die Lua-Syntax bei, und das Skript kann leicht für eine einfache dauerhafte Speicherung geändert werden, indem die Ausgabe in eine Datei geschrieben wird, wenn sie so geändert wird, dass nur Datentypen für Zahlen, Boolesche Werte, Zeichenfolgen und Tabellen formatiert werden können.

function print_table(node)
    local cache, stack, output = {},{},{}
    local depth = 1
    local output_str = "{\n"

    while true do
        local size = 0
        for k,v in pairs(node) do
            size = size + 1
        end

        local cur_index = 1
        for k,v in pairs(node) do
            if (cache[node] == nil) or (cur_index >= cache[node]) then

                if (string.find(output_str,"}",output_str:len())) then
                    output_str = output_str .. ",\n"
                elseif not (string.find(output_str,"\n",output_str:len())) then
                    output_str = output_str .. "\n"
                end

                -- This is necessary for working with HUGE tables otherwise we run out of memory using concat on huge strings
                table.insert(output,output_str)
                output_str = ""

                local key
                if (type(k) == "number" or type(k) == "boolean") then
                    key = "["..tostring(k).."]"
                else
                    key = "['"..tostring(k).."']"
                end

                if (type(v) == "number" or type(v) == "boolean") then
                    output_str = output_str .. string.rep('\t',depth) .. key .. " = "..tostring(v)
                elseif (type(v) == "table") then
                    output_str = output_str .. string.rep('\t',depth) .. key .. " = {\n"
                    table.insert(stack,node)
                    table.insert(stack,v)
                    cache[node] = cur_index+1
                    break
                else
                    output_str = output_str .. string.rep('\t',depth) .. key .. " = '"..tostring(v).."'"
                end

                if (cur_index == size) then
                    output_str = output_str .. "\n" .. string.rep('\t',depth-1) .. "}"
                else
                    output_str = output_str .. ","
                end
            else
                -- close the table
                if (cur_index == size) then
                    output_str = output_str .. "\n" .. string.rep('\t',depth-1) .. "}"
                end
            end

            cur_index = cur_index + 1
        end

        if (size == 0) then
            output_str = output_str .. "\n" .. string.rep('\t',depth-1) .. "}"
        end

        if (#stack > 0) then
            node = stack[#stack]
            stack[#stack] = nil
            depth = cache[node] == nil and depth + 1 or depth - 1
        else
            break
        end
    end

    -- This is necessary for working with HUGE tables otherwise we run out of memory using concat on huge strings
    table.insert(output,output_str)
    output_str = table.concat(output)

    print(output_str)
end

Hier ist ein Beispiel:

local t = {
    ["abe"] = {1,2,3,4,5},
    "string1",
    50,
    ["depth1"] = { ["depth2"] = { ["depth3"] = { ["depth4"] = { ["depth5"] = { ["depth6"] = { ["depth7"]= { ["depth8"] = { ["depth9"] = { ["depth10"] = {1000}, 900}, 800},700},600},500}, 400 }, 300}, 200}, 100},
    ["ted"] = {true,false,"some text"},
    "string2",
    [function() return end] = function() return end,
    75
}

print_table(t)

Ausgabe:

{
    [1] = 'string1',
    [2] = 50,
    [3] = 'string2',
    [4] = 75,
    ['abe'] = {
        [1] = 1,
        [2] = 2,
        [3] = 3,
        [4] = 4,
        [5] = 5
    },
    ['function: 06472B70'] = 'function: 06472A98',
    ['depth1'] = {
        [1] = 100,
        ['depth2'] = {
            [1] = 200,
            ['depth3'] = {
                [1] = 300,
                ['depth4'] = {
                    [1] = 400,
                    ['depth5'] = {
                        [1] = 500,
                        ['depth6'] = {
                            [1] = 600,
                            ['depth7'] = {
                                [1] = 700,
                                ['depth8'] = {
                                    [1] = 800,
                                    ['depth9'] = {
                                        [1] = 900,
                                        ['depth10'] = {
                                            [1] = 1000
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    ['ted'] = {
        [1] = true,
        [2] = false,
        [3] = 'some text'
    }
}

tabFunktion ist überkompliziert. Es ist im Grunde nur, string.repeat('\t', amt)aber weit weniger performant.
Val sagt Reinstate Monica

6

Wie bereits erwähnt, müssen Sie es schreiben. Hier ist meine bescheidene Version: (Super Basic)

function tprint (t, s)
    for k, v in pairs(t) do
        local kfmt = '["' .. tostring(k) ..'"]'
        if type(k) ~= 'string' then
            kfmt = '[' .. k .. ']'
        end
        local vfmt = '"'.. tostring(v) ..'"'
        if type(v) == 'table' then
            tprint(v, (s or '')..kfmt)
        else
            if type(v) ~= 'string' then
                vfmt = tostring(v)
            end
            print(type(t)..(s or '')..kfmt..' = '..vfmt)
        end
    end
end

Beispiel:

local mytbl = { ['1']="a", 2, 3, b="c", t={d=1} }
tprint(mytbl)

Ausgabe (Lua 5.0):

table[1] = 2
table[2] = 3
table["1"] = "a"
table["t"]["d"] = 1
table["b"] = "c"

1
Sehr originell! Ich mag das.
Jack Giffin


2

Dies ist meine Version, die das Ausschließen von Tabellen und Benutzerdaten unterstützt

-- Lua Table View by Elertan
table.print = function(t, exclusions)
    local nests = 0
    if not exclusions then exclusions = {} end
    local recurse = function(t, recurse, exclusions)
        indent = function()
            for i = 1, nests do
                io.write("    ")
            end
        end
        local excluded = function(key)
            for k,v in pairs(exclusions) do
                if v == key then
                    return true
                end
            end
            return false
        end
        local isFirst = true
        for k,v in pairs(t) do
            if isFirst then
                indent()
                print("|")
                isFirst = false
            end
            if type(v) == "table" and not excluded(k) then
                indent()
                print("|-> "..k..": "..type(v))
                nests = nests + 1
                recurse(v, recurse, exclusions)
            elseif excluded(k) then
                indent()
                print("|-> "..k..": "..type(v))
            elseif type(v) == "userdata" or type(v) == "function" then
                indent()
                print("|-> "..k..": "..type(v))
            elseif type(v) == "string" then
                indent()
                print("|-> "..k..": ".."\""..v.."\"")
            else
                indent()
                print("|-> "..k..": "..v)
            end
        end
        nests = nests - 1
    end

    nests = 0
    print("### START TABLE ###")
    for k,v in pairs(t) do
        print("root")
        if type(v) == "table" then
            print("|-> "..k..": "..type(v))
            nests = nests + 1
            recurse(v, recurse, exclusions)
        elseif type(v) == "userdata" or type(v) == "function" then
            print("|-> "..k..": "..type(v))
        elseif type(v) == "string" then
            print("|-> "..k..": ".."\""..v.."\"")
        else
            print("|-> "..k..": "..v)
        end
    end
    print("### END TABLE ###")
end

Dies ist ein Beispiel

t = {
    location = {
       x = 10,
       y = 20
    },
    size = {
      width = 100000000,
      height = 1000,
    },
    name = "Sidney",
    test = {
        hi = "lol",
    },
    anotherone = {
        1, 
        2, 
        3
    }
}

table.print(t, { "test" })

Drucke:

   ### START TABLE ###
root
|-> size: table
    |
    |-> height: 1000
    |-> width: 100000000
root
|-> location: table
    |
    |-> y: 20
    |-> x: 10
root
|-> anotherone: table
    |
    |-> 1: 1
    |-> 2: 2
    |-> 3: 3
root
|-> test: table
    |
    |-> hi: "lol"
root
|-> name: "Sidney"
### END TABLE ###

Beachten Sie, dass der Stamm keine Ausschlüsse entfernt


2

Format als JSON (Sie können es später in der IDE "verschönern"):

local function format_any_value(obj, buffer)
    local _type = type(obj)
    if _type == "table" then
        buffer[#buffer + 1] = '{"'
        for key, value in next, obj, nil do
            buffer[#buffer + 1] = tostring(key) .. '":'
            format_any_value(value, buffer)
            buffer[#buffer + 1] = ',"'
        end
        buffer[#buffer] = '}' -- note the overwrite
    elseif _type == "string" then
        buffer[#buffer + 1] = '"' .. obj .. '"'
    elseif _type == "boolean" or _type == "number" then
        buffer[#buffer + 1] = tostring(obj)
    else
        buffer[#buffer + 1] = '"???' .. _type .. '???"'
    end
end

Verwendung:

local function format_as_json(obj)
    if obj == nil then return "null" else
        local buffer = {}
        format_any_value(obj, buffer)
        return table.concat(buffer)
    end
end

local function print_as_json(obj)
    print(_format_as_json(obj))
end

print_as_json {1, 2, 3}
print_as_json(nil)
print_as_json("string")
print_as_json {[1] = 1, [2] = 2, three = { { true } }, four = "four"}

Übrigens habe ich auch mehrere andere Lösungen geschrieben: eine sehr schnelle und eine mit Sonderzeichen: https://github.com/vn971/fast_json_encode


Dies ist eigentlich das, wonach ich gesucht habe, obwohl es nicht speziell das war, was die Operation verlangte. Vielen Dank für diese einfache Lösung. Erleichtert die Verwendung in Lua-Umgebungen mit beengten Platzverhältnissen wie NodeMCU.
Sawtaytoes

1

Sie müssen es leider selbst codieren. Ich habe das geschrieben, und es kann für Sie von Nutzen sein

function printtable(table, indent)

  indent = indent or 0;

  local keys = {};

  for k in pairs(table) do
    keys[#keys+1] = k;
    table.sort(keys, function(a, b)
      local ta, tb = type(a), type(b);
      if (ta ~= tb) then
        return ta < tb;
      else
        return a < b;
      end
    end);
  end

  print(string.rep('  ', indent)..'{');
  indent = indent + 1;
  for k, v in pairs(table) do

    local key = k;
    if (type(key) == 'string') then
      if not (string.match(key, '^[A-Za-z_][0-9A-Za-z_]*$')) then
        key = "['"..key.."']";
      end
    elseif (type(key) == 'number') then
      key = "["..key.."]";
    end

    if (type(v) == 'table') then
      if (next(v)) then
        printf("%s%s =", string.rep('  ', indent), tostring(key));
        printtable(v, indent);
      else
        printf("%s%s = {},", string.rep('  ', indent), tostring(key));
      end 
    elseif (type(v) == 'string') then
      printf("%s%s = %s,", string.rep('  ', indent), tostring(key), "'"..v.."'");
    else
      printf("%s%s = %s,", string.rep('  ', indent), tostring(key), tostring(v));
    end
  end
  indent = indent - 1;
  print(string.rep('  ', indent)..'}');
end

1
Danke für Ihre Antwort. Ich habe es versucht und ich bekomme: Versuch, global 'sort' (ein Nullwert) aufzurufen
Cliff

Wechseln sortzu table.sort... Es muss local sort = table.sortirgendwo im Code eine Stelle gegeben haben, von der dies stammt.
Michal Kottman

Man muss ein bisschen einfallsreich sein! Es gibt eine Reihe von Symbolen, die der Einfachheit halber aus dem Bibliothekstabellenbereich nach _G kopiert wurden. sortist eine Kopie von table.sort, strrepist string.rep, strmatchist string.matchusw. Lassen Sie mich wissen, wenn es noch mehr gibt und ich werde meine Antwort ändern.
Borodin

Es tut mir leid, ich habe auch ein ziemlich tiefes Netz von Tabellen, da meine eigenen Versuche, die Struktur zu rekursieren, auf einen Stapelüberlauf stießen. (Kein Wortspiel beabsichtigt!) Ich habe meinen Kopf geschlagen, um meine Rekursion abzuwickeln und die richtigen Schwanzrufe zu verwenden, aber ich war frustriert, an welchem ​​Punkt ich hier gepostet habe.
Cliff

Sie können die Rekursion im Allgemeinen nicht aus einer solchen Funktion entfernen, da sie nicht endrekursiv ist. Verwenden Sie entweder eine Lua, die mit einem größeren Stapel erstellt wurde, oder implementieren Sie denselben Algorithmus mithilfe einer Lua-Tabelle, um den Rekursionsstapel zu speichern.
Borodin

1
--~ print a table
function printTable(list, i)

    local listString = ''
--~ begin of the list so write the {
    if not i then
        listString = listString .. '{'
    end

    i = i or 1
    local element = list[i]

--~ it may be the end of the list
    if not element then
        return listString .. '}'
    end
--~ if the element is a list too call it recursively
    if(type(element) == 'table') then
        listString = listString .. printTable(element)
    else
        listString = listString .. element
    end

    return listString .. ', ' .. printTable(list, i + 1)

end


local table = {1, 2, 3, 4, 5, {'a', 'b'}, {'G', 'F'}}
print(printTable(table))

Hallo Mann, ich habe einen Siple-Code geschrieben, der dies in reinem Lua macht. Er hat einen Fehler (schreibe ein Koma nach dem letzten Element der Liste), aber wie ich ihn schnell als Prototyp geschrieben habe, werde ich dir erlauben, ihn an deinen anzupassen Bedürfnisse.


1

Hinzufügen einer anderen Version. Dieser versucht auch , über Benutzerdaten zu iterieren.

function inspect(o,indent)
    if indent == nil then indent = 0 end
    local indent_str = string.rep("    ", indent)
    local output_it = function(str)
        print(indent_str..str)
    end

    local length = 0

    local fu = function(k, v)
        length = length + 1
        if type(v) == "userdata" or type(v) == 'table' then
            output_it(indent_str.."["..k.."]")
            inspect(v, indent+1)
        else
            output_it(indent_str.."["..k.."] "..tostring(v))
        end
    end

    local loop_pairs = function()
        for k,v in pairs(o) do fu(k,v) end
    end

    local loop_metatable_pairs = function()
        for k,v in pairs(getmetatable(o)) do fu(k,v) end
    end

    if not pcall(loop_pairs) and not pcall(loop_metatable_pairs) then
        output_it(indent_str.."[[??]]")
    else
        if length == 0 then
            output_it(indent_str.."{}")
        end
    end
end

1

Ich verwende meine eigene Funktion, um den Inhalt einer Tabelle zu drucken, bin mir aber nicht sicher, wie gut sie in Ihre Umgebung übersetzt wird:

---A helper function to print a table's contents.
---@param tbl table @The table to print.
---@param depth number @The depth of sub-tables to traverse through and print.
---@param n number @Do NOT manually set this. This controls formatting through recursion.
function PrintTable(tbl, depth, n)
  n = n or 0;
  depth = depth or 5;

  if (depth == 0) then
      print(string.rep(' ', n).."...");
      return;
  end

  if (n == 0) then
      print(" ");
  end

  for key, value in pairs(tbl) do
      if (key and type(key) == "number" or type(key) == "string") then
          key = string.format("[\"%s\"]", key);

          if (type(value) == "table") then
              if (next(value)) then
                  print(string.rep(' ', n)..key.." = {");
                  PrintTable(value, depth - 1, n + 4);
                  print(string.rep(' ', n).."},");
              else
                  print(string.rep(' ', n)..key.." = {},");
              end
          else
              if (type(value) == "string") then
                  value = string.format("\"%s\"", value);
              else
                  value = tostring(value);
              end

              print(string.rep(' ', n)..key.." = "..value..",");
          end
      end
  end

  if (n == 0) then
      print(" ");
  end
end

-1

Ich habe demütig ein bisschen Alundaio-Code geändert:

-- by Alundaio
-- KK modified 11/28/2019

function dump_table_to_string(node, tree, indentation)
    local cache, stack, output = {},{},{}
    local depth = 1


    if type(node) ~= "table" then
        return "only table type is supported, got " .. type(node)
    end

    if nil == indentation then indentation = 1 end

    local NEW_LINE = "\n"
    local TAB_CHAR = " "

    if nil == tree then
        NEW_LINE = "\n"
    elseif not tree then
        NEW_LINE = ""
        TAB_CHAR = ""
    end

    local output_str = "{" .. NEW_LINE

    while true do
        local size = 0
        for k,v in pairs(node) do
            size = size + 1
        end

        local cur_index = 1
        for k,v in pairs(node) do
            if (cache[node] == nil) or (cur_index >= cache[node]) then

                if (string.find(output_str,"}",output_str:len())) then
                    output_str = output_str .. "," .. NEW_LINE
                elseif not (string.find(output_str,NEW_LINE,output_str:len())) then
                    output_str = output_str .. NEW_LINE
                end

                -- This is necessary for working with HUGE tables otherwise we run out of memory using concat on huge strings
                table.insert(output,output_str)
                output_str = ""

                local key
                if (type(k) == "number" or type(k) == "boolean") then
                    key = "["..tostring(k).."]"
                else
                    key = "['"..tostring(k).."']"
                end

                if (type(v) == "number" or type(v) == "boolean") then
                    output_str = output_str .. string.rep(TAB_CHAR,depth*indentation) .. key .. " = "..tostring(v)
                elseif (type(v) == "table") then
                    output_str = output_str .. string.rep(TAB_CHAR,depth*indentation) .. key .. " = {" .. NEW_LINE
                    table.insert(stack,node)
                    table.insert(stack,v)
                    cache[node] = cur_index+1
                    break
                else
                    output_str = output_str .. string.rep(TAB_CHAR,depth*indentation) .. key .. " = '"..tostring(v).."'"
                end

                if (cur_index == size) then
                    output_str = output_str .. NEW_LINE .. string.rep(TAB_CHAR,(depth-1)*indentation) .. "}"
                else
                    output_str = output_str .. ","
                end
            else
                -- close the table
                if (cur_index == size) then
                    output_str = output_str .. NEW_LINE .. string.rep(TAB_CHAR,(depth-1)*indentation) .. "}"
                end
            end

            cur_index = cur_index + 1
        end

        if (size == 0) then
            output_str = output_str .. NEW_LINE .. string.rep(TAB_CHAR,(depth-1)*indentation) .. "}"
        end

        if (#stack > 0) then
            node = stack[#stack]
            stack[#stack] = nil
            depth = cache[node] == nil and depth + 1 or depth - 1
        else
            break
        end
    end

    -- This is necessary for working with HUGE tables otherwise we run out of memory using concat on huge strings
    table.insert(output,output_str)
    output_str = table.concat(output)

    return output_str

end

dann:

print(dump_table_to_string("AA", true,3))

print(dump_table_to_string({"AA","BB"}, true,3))

print(dump_table_to_string({"AA","BB"}))

print(dump_table_to_string({"AA","BB"},false))

print(dump_table_to_string({"AA","BB",{22,33}},true,2))

gibt:

only table type is supported, got string

{
   [1] = 'AA',
   [2] = 'BB'
}

{
 [1] = 'AA',
 [2] = 'BB'
}

{[1] = 'AA',[2] = 'BB'}

{
  [1] = 'AA',
  [2] = 'BB',
  [3] = {
    [1] = 22,
    [2] = 33
  }
}
Durch die Nutzung unserer Website bestätigen Sie, dass Sie unsere Cookie-Richtlinie und Datenschutzrichtlinie gelesen und verstanden haben.
Licensed under cc by-sa 3.0 with attribution required.