码迷,mamicode.com
首页 > 其他好文 > 详细

__tostring元方法

时间:2017-09-15 02:03:00      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:end   cti   理解   使用   转化   cal   return   ret   方法   

__tostring,直接理解就是转化为string,把表转化为string,事实上也是这样,不过表转化为string的具体内容是自己定义的

模型:

table = setmetatable({},{__tostring =

  function(table)

    --这里写表变为string的具体内容,必须return出来

    return  

  end

})

 

使用:local str = table

__tostring元方法

标签:end   cti   理解   使用   转化   cal   return   ret   方法   

原文地址:http://www.cnblogs.com/xzxdm/p/7524049.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!