1、CCTableView中的lua绑定
LUA_TableViewDataSource在TestLua里有例子,有个TableView的例子
function TableViewTestLayer.cellSizeForTable(table,idx)return 60,60
end结合下面的C++代码发现第一个是width,第二是height
virtual CCSize tableCellSizeForIndex(CCTableView *table, unsigned int idx){if (NULL != table ){int nHandler = table->getScriptHandler(CCTableView::kTableCellSizeForIndex);if (0 != nHandler){CCArray* resultArray = CCArray::create();if (NULL != resultArray){CCLuaEngine::defaultEngine()->executeTableViewEvent(CCTableView::kTableCellSizeForIndex, table,&idx,resultArray);CCAssert(resultArray->count() == 2, "tableCellSizeForIndex Array count error");CCDouble* width = dynamic_cast(resultArray->objectAtIndex(0));CCDouble* height = dynamic_cast (resultArray->objectAtIndex(1));if (NULL != width && NULL != height){return CCSizeMake((float)width->getValue(), (float)height->getValue());}}}}return CCSizeMake(0,0);}
2、获取点击的sender
点击时发送的sender没有传回,可以在CCLuaEngine里的executeNodeEvent,executeNodeTouchEvent,executeNodeTouchesEvent
里加上下面两句。
event["tag"]=CCLuaValue::intValue(pNode->getTag());
event["target"]=CCLuaValue::ccobjectValue(pNode,"CCNode”);