Hey I am working on an App using cocos2d-x. To give the app further functionalities I am currently working with Lua. This is my code which successfully generates a new scene:
function main()
local visibleSize = CCDirector:sharedDirector():getVisibleSize()
local origin = CCDirector:sharedDirector():getVisibleOrigin()
local cclog = function(...)
print(string.format(...))
end
-- create layer
local function createLuaSceneLayer()
local luaSceneLayer = CCLayer:create()
local function menuCallbackBack()
CCDirector:sharedDirector():popScene()
end
local size = CCDirector:sharedDirector():getWinSize();
local bg = CCLayerColor:create(ccc4(255,255,255,255))
luaSceneLayer:addChild(bg)
local backButton = CCMenuItemImage:create("arrow_left.png", "arrow_left.png")
backButton:setPosition(ccp(20, CCDirector:sharedDirector():getWinSize().height - 20) )
backButton:registerScriptTapHandler(menuCallbackBack)
local menu = CCMenu:createWithItem(backButton)
menu:setPosition(ccp(0, 0))
luaSceneLayer:addChild(menu,3)
local textLabel = CCLabelTTF:create("I am a Lua generated Label", "Thonburi", 20)
textLabel:setPosition(180 ,size.height -20)
textLabel:setColor(ccc3(0,0,0))
luaSceneLayer:addChild(textLabel)
local taskLabel = CCLabelTTF:create("Enter two numbers in the EditBoxes Below", "Thonburi", 20)
taskLabel:setPosition(160,size.height /7 * 6)
taskLabel:setColor(ccc3(0,0,0))
luaSceneLayer:addChild(taskLabel)
local mySprite = CCScale9Sprite:create("green_edit.png")
local textField1 = CCEditBox:create(CCSizeMake(200, 40), mySprite)
textField1:setPosition(40, 40)
textField1:setFontColor(ccBLACK);
textField1:setText("");
luaSceneLayer:addChild(textField1)
return luaSceneLayer
end
-- run
local luaScene = CCScene:create()
luaScene:addChild(createLuaSceneLayer())
CCDirector:sharedDirector():pushScene(luaScene)
end
xpcall(main, G__TRACKBACK)
Now I’d like to add a CCEditBox which requires a CCScale9Sprite. As soon as I open the Lua file my App crashes and I get the following error message:
PANIC: unprotected error in call to Lua API )
Why is it not possible to use CCScale9Sprite in combination with Lua?