Use Lua to implement PHP's Var_dump () function _lua

Source: Internet
Author: User
Tags lua

Accustomed to the Var_dump () function in PHP, and now writing Lua is always used to use the Var_dump () function, so I wrote a similar function of the var_dump () function.

Copy Code code as follows:

function Var_dump (data, max_level, prefix)
If type (prefix) ~= "string" Then
prefix = ""
End
If type (data) ~= "table" then
Print (prefix. ToString (data))
Else
Print (data)
If Max_level ~= 0 Then
Local prefix_next = prefix. "    "
Print (prefix. "{")
For k,v in pairs (data) does
Io.stdout:write (Prefix_next. K..) " = ")
If Type (v) ~= "table" or (type (max_level) = = "Number" and Max_level <= 1) Then
Print (v)
Else
if Max_level = = Nil Then
Var_dump (V, Nil, prefix_next)
Else
Var_dump (V, MAX_LEVEL-1, Prefix_next)
End
End
End
Print (prefix. "}")
End
End
End

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.