quick: iskindof使用注意
2024-09-17 18:06:32
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方法
最新文章
- 第一届山东省ACM——Phone Number(java)
- SSO 单点登录实现
- web前端书籍
- python基础:算法是什么
- HTML5+ 拍照上传 和选择文件上传
- Common Subsequence LCS
- Windows下使用xShell向远程Linux上传文件
- 夺命雷公狗—angularjs—21—解决angularjs压缩问题
- MIFARE系列4《组成图》
- iOS Architecture
- Disable keyboard input on Android TimePicker
- Bzoj 2789: [Poi2012]Letters 树状数组,逆序对
- js控件位置
- 论山寨手机与Android联姻的技术基础 【序】
- NProxy——Mac和Linux平台下的Fiddler
- 无需安装Mono的Jexus
- JMeter怎么使用代理服务器
- Chapter 16_4 私密性
- shell是什么,各种shell的初步认识,适用于初学者
- 初次配置git与github出现push不了的问题
热门文章
- JS 学习笔记
- 一、hexo+github搭建个人博客的过程记录
- 【leetcode-152】 乘积最大子序列
- Libs - 软件下载网站
- 解决:The web application [] registered the JDBC driver [] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
- 我为啥不想用Python
- 同步fifo与异步fifo
- Atlassian JIRA服务器模板注入漏洞复现(CVE-2019-11581)
- java 使用tess4j实现OCR的最简单样例
- Spark GraphX图算法应用【分区策略、PageRank、ConnectedComponents,TriangleCount】