如何将表转储到控制台? [英] How to dump a table to console?

查看:71
本文介绍了如何将表转储到控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法显示包含嵌套表(n-深)的表的内容.我只想通过print语句或其他快速而又肮脏的方法将其转储到std或控制台中,但是我不知道该怎么做.我正在寻找使用gdb打印NSDictionary时得到的大致等效结果.

I'm having trouble displaying the contents of a table which contains nested tables (n-deep). I'd like to just dump it to std out or the console via a print statement or something quick and dirty but I can't figure out how. I'm looking for the rough equivalent that I'd get when printing an NSDictionary using gdb.

推荐答案

随意浏览 Lua Wiki上的内容表序列化.它列出了有关如何将表转储到控制台的几种方法.

Feel free to browse the Lua Wiki on table serialization. It lists several ways on how to dump a table to the console.

您只需要选择最适合您的一个即可.有很多方法可以做到,但是我通常最终使用 Penlight 中的一种:

You just have to choose which one suits you best. There are many ways to do it, but I usually end up using the one from 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
  }
}

这篇关于如何将表转储到控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆