cocos2d/cocos2d-x — pull request #1693 by dualface (2012-12-02 07:42:33+00:00)
Title: add tolua.isnull()

tolua.isnull() check Lua value's userdata is null.

Example:

-- create scene
local scene = CCScene:create()

-- add title to scene
local sprite = CCSprite:create("title.png")
sprite:setPosition(160, 240)
scene:addChild(sprite)

-- remove title after 5 seconds
local sharedScheduler = CCDirector:sharedDirector():getScheduler()
local handle
handle = sharedScheduler:scheduleScriptFunc(function()
sharedScheduler:unscheduleScriptEntry(handle)

-- if enter other scene before 5.0 seconds, sprite invalid
-- do more check
if not tolua.isnull(sprite) then
sprite:removeFromParentAndCleanup(true)
end
end, 5.0, false)