コード例 #1
0
static int lua_cocos2dx_TableView_setDataSource(lua_State* L)
{
    if (nullptr == L)
        return 0;

    int argc = 0;
    TableView* self = nullptr;

#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
    if (!tolua_isusertype(L,1,"cc.TableView",0,&tolua_err)) goto tolua_lerror;
#endif

    self = (TableView*)  tolua_tousertype(L,1,0);

#if COCOS2D_DEBUG >= 1
    if (nullptr == self)
    {
        tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_TableView_setDataSource'\n", nullptr);
        return 0;
    }
#endif

    argc = lua_gettop(L) - 1;

    if (0 == argc)
    {
        LUA_TableViewDataSource* dataSource = new (std::nothrow) LUA_TableViewDataSource();
        if (nullptr == dataSource)
            return 0;

        __Dictionary* userDict = static_cast<__Dictionary*>(self->getUserObject());
        if (nullptr == userDict)
        {
            userDict = new __Dictionary();
            if (NULL == userDict)
                return 0;

            self->setUserObject(userDict);
            userDict->release();
        }

        userDict->setObject(dataSource, KEY_TABLEVIEW_DATA_SOURCE);

        self->setDataSource(dataSource);

        dataSource->release();

        return 0;
    }

    luaL_error(L, "'setDataSource' function of TableView wrong number of arguments: %d, was expecting %d\n", argc, 0);
    return 0;

#if COCOS2D_DEBUG >= 1
tolua_lerror:
    tolua_error(L,"#ferror in function 'setDataSource'.",&tolua_err);
    return 0;
#endif
}
コード例 #2
0
ファイル: CCTableView.cpp プロジェクト: TheWindShan/HYFish
TableView* TableView::create(TableViewDataSource* dataSource, Size size, Node *container)
{
    TableView *table = new (std::nothrow) TableView();
    table->initWithViewSize(size, container);
    table->autorelease();
    table->setDataSource(dataSource);
    table->_updateCellPositions();
    table->_updateContentSize();

    return table;
}