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已购卖并 ...
随机推荐
- JVM 的垃圾回收器详解
Parallel Scavenge(Paraller):Parallel Scavenge和ParNew关注的点不一样:ParNew关注的是尽可能缩短暂停的时间,Parallel Scavenge关注 ...
- MySQL job/定时任务/event 学习
参考文章: https://blog.csdn.net/qq_21108311/article/details/82589850 https://blog.csdn.net/qq_27238185/a ...
- Bootstrap3-导航
Bootstrap 导航 1. 定义导航组件 基本结构: <!-- 基本导航组件 --> <ul class="nav"> <li class=&qu ...
- 记一次CSS反爬
目标网址:猫眼电影 主要流程 爬取每一个电影所对应的url 爬取具体电影所对应的源码 解析源码,并下载所对应的字体 使用 fontTools 绘制所对应的数字 运用机器学习的方法识别对应的数字 在源码 ...
- Servlet处理(jQuery)Ajax请求
1. jQuery jQuery是一个JavaScript函数库,极大的简化了JavaScript编程,很容易学习.jQuery是目前最流行的开源js框架,并且提供了大量的扩展. 2. Aja ...
- python基础知识(最基本)
保留字(关键字) False None True and as break class continue def elif else except finally for from global ...
- 【转载】Gradle学习 第七章:Java快速入门
转载地址:http://ask.android-studio.org/?/article/22 7.1. The Java plugin(Java插件) As we have seen, Gradle ...
- sql的日期格式化转化
1. DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据. DATE_FORMAT(date,format) 可以使用的格式有: 格式 描述 %a 缩写星期名 %b 缩写月名 %c 月 ...
- 使用gacutil把COM组件注册到全局缓存GAC中
我们在编写软件的时候,有时候需要调用COM组件,那就需要注册了,注册有两种,一种是使用regasm 在程序运行的时候注册,参考“pb调用C#编写的DLL类库“,不过受路径的限制.还有一种注册方式,使用 ...
- 并发编程(五)--GIL、死锁现象与递归锁、信号量、Event事件、线程queue
一.GIL全局解释器锁 1.什么是全局解释器锁 GIL本质就是一把互斥锁,相当于执行权限,每个进程内都会存在一把GIL,同一进程内的多个线程,必须抢到GIL之后才能使用Cpython解释器来执行自己的 ...