quick: iskindof使用注意
quick: iskindof使用注意
--[[--
如果对象是指定类或其子类的实例,返回 true,否则返回 false
~~~ lua
local Animal = class("Animal")
local Duck = class("Duck", Animal)
print(iskindof(Duck.new(), "Animal")) -- 输出 true
~~~
@param mixed obj 要检查的对象
@param string classname 类名
@return boolean
]]
function iskindof(obj, classname)
local t = type(obj)
local mt
if t == "table" then
mt = getmetatable(obj)
elseif t == "userdata" then
-- ** 下面这行是我仿照cocos2d-x-3.11.1新加的,用于判断C++类的继承关系,如cc.Node
if tolua.iskindof(obj, classname) then return true end
mt = tolua.getpeer(obj)
end
while mt do
if mt.__cname == classname then
return true
end
mt = mt.super
end
return false
end
printf("UIListView ==== " .. tostring(iskindof(self.lvGrid, "UIListView")))
printf("UIScrollView ==== " .. tostring(iskindof(self.lvGrid, "UIScrollView")))
printf("cc.Node ==== " .. tostring(iskindof(self.lvGrid, "cc.Node")))
printf("cc.ClippingRegionNode ==== " .. tostring(iskindof(self.lvGrid, "cc.ClippingRegionNode")))
printf("cc.ClippingRectangleNode ==== " .. tostring(iskindof(self.lvGrid, "cc.ClippingRectangleNode")))
printf("__cname ==== " .. tostring(self.lvGrid.__cname))
输出结果:
[LUA-print] UIListView ==== true
[LUA-print] UIScrollView ==== true
[LUA-print] cc.Node ==== true
[LUA-print] cc.ClippingRegionNode ==== false
[LUA-print] cc.ClippingRectangleNode ==== true
[LUA-print] __cname ==== UIListView
注意:
但是因为quick不能判断继承自C++如Node的情况,我实验了cocos2d-x-3.11.1中的class和iskindof方法,发现方法有很大的不同,但是printf("UIListView ==== " .. tostring(iskindof(self.lvGrid, "UIListView")))这种都判断为false的结果,网上有一篇博客修改了,http://m.blog.csdn.net/article/details?id=49799637但是我测试了下还是有问题,不过没有详细测试,最终决定还是使用quick中的class 和 iskindof方法
quick: iskindof使用注意的更多相关文章
- [算法]——快速排序(Quick Sort)
顾名思义,快速排序(quick sort)速度十分快,时间复杂度为O(nlogn).虽然从此角度讲,也有很多排序算法如归并排序.堆排序甚至希尔排序等,都能达到如此快速,但是快速排序使用更加广泛,以至于 ...
- Quick Cocos (2.2.5plus)CoinFlip解析(MenuScene display AdBar二次封装)
转载自:http://cn.cocos2d-x.org/tutorial/show?id=1621 从Samples中找到CoinFlip文件夹,复制其中的 res 和 script 文件夹覆盖新建工 ...
- 《Qt Quick 4小时入门》学习笔记4
http://edu.csdn.net/course/detail/1042/14806?auto_start=1 Qt Quick 4小时入门 第七章:处理鼠标与键盘事件 1.处理鼠标事件 鼠标信号 ...
- 《Qt Quick 4小时入门》学习笔记3
http://edu.csdn.net/course/detail/1042/14807?auto_start=1 Qt Quick 4小时入门 第八章:Qt Quick中的锚(anchors)布局 ...
- 《Qt Quick 4小时入门》学习笔记2
http://edu.csdn.net/course/detail/1042/14805?auto_start=1 Qt Quick 4小时入门 第五章:Qt Quick基本界面元素介绍 1. ...
- spring in action 4th --- quick start
读spring in action. 环境搭建 quick-start依赖注入 面向切面 1.环境搭建 jdk1.8 gradle 2.12 Intelij idea 2016.2.1 1.1创建一个 ...
- A Quick Introduction to Linux Policy Routing
A Quick Introduction to Linux Policy Routing 29 May 2013 In this post, I’m going to introduce you to ...
- Quick Apps for Sharepoint小型BI解决方案
Quick Apps for Sharepoint介绍 Quick Apps for Sharepoint前身是Quest Webpart ,由企业软件开发商QuestSoftware开发,Quest ...
- Sharepoint + Office Infopart + Quick Apps for Sharepoint搭建无纸化工作平台
项目背景: 某大型外企各分部通过互联网专线统一域环境,Exchange邮件系统,Sharepoint平台及依赖环境已经购买并搭建起来,Dell Quick app for Sharepoint已购卖并 ...
随机推荐
- logger.error打印完整的错误堆栈信息
使用Spring Boot项目中的日志打印功能的时候,发现调用Logger.errror()方法的时候不能完全地打印出网站的错误堆栈信息,只能打印出这个错误是一个什么错误. 为什么呢,原因在于这个方法 ...
- 如何将云上的Linux文件自动备份到本地服务器
需求场景: 将云上一台Linux服务器文件备份到本地服务器,一周一备即可. 面对这样一个需求,我们可能面临下列几个问题, 备份方式:是云服务器推文件到本地服务器写入,还是本地服务器从云服务器拉文件?这 ...
- 《 .NET并发编程实战》阅读指南 - 第10章
先发表生成URL以印在书里面.等书籍正式出版销售后会公开内容.
- PHP小程序后端支付代码亲测可用
小程序后端支付代码亲测可用 <?php namespace Home\Controller; use Think\Controller; class WechatpayController ex ...
- 2019年,Golang开始吊打Java性能了!!!
最近要同事debug性能,不经意间发现现在Golang性能开始吊打Java了!!!感觉Go发展神速!! 之前Go和Java基本是平手,甚至还有较大差距,请见https://www.cnblogs.co ...
- 架构师小跟班:推荐一款Java在线诊断工具,arthas入门及使用教程
安装 官方网站: https://alibaba.github.io/arthas/index.html 一.下载arthas-boot.jar,然后用java -jar的方式启动: wget htt ...
- Spring扩展点之BeanPostProcessor
前言 BeanPostProcessor接口是Spring中一个非常重要的接口,它的接口定义如下 public interface BeanPostProcessor { Object postPro ...
- vue通过Blob实现下载文件
需求是这样的...... 具体实现,前端拿到后端返回回来的数据,然后通过Blob实现下载,文件内容样式啥的都是后端写的 script代码: 这里的data就是后端返回回来的数据,此方法兼容IE dow ...
- current transaction is aborted, commands ignored until end of transaction block
current transaction is aborted, commands ignored until end of transaction block Error updating datab ...
- 如何用StatSVN统计SVN服务器某项目的代码量
startsvn下载地址: https://sourceforge.net/projects/statsvn/?source=typ_redirect svn下载地址: https://www.vis ...