static int SendBinaryMessageToLua(int nHandler,const unsigned char* pTable,int nLength)
{
    if (NULL == pTable || nHandler <= 0) {
        return 0;
    }
    
    if (NULL == ScriptEngineManager::getInstance()->getScriptEngine()) {
        return 0;
    }
    
    LuaStack *pStack = LuaEngine::getInstance()->getLuaStack();
    if (NULL == pStack) {
        return 0;
    }

    lua_State *tolua_s = pStack->getLuaState();
    if (NULL == tolua_s) {
        return 0;
    }
    
    int nRet = 0;
    LuaValueArray array;
    for (int i = 0 ; i < nLength; i++) {
        LuaValue value = LuaValue::intValue(pTable[i]);
        array.push_back(value);
    }
    
    pStack->pushLuaValueArray(array);
    nRet = pStack->executeFunctionByHandler(nHandler, 1);
    pStack->clean();
    return nRet;
}
int lua_PluginFacebookLua_PluginFacebook_getFriends(lua_State* tolua_S)
{
    int argc = 0;
    bool ok  = true;

#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
#endif

#if COCOS2D_DEBUG >= 1
    if (!tolua_isusertable(tolua_S,1,"sdkbox.PluginFacebook",0,&tolua_err)) goto tolua_lerror;
#endif

    argc = lua_gettop(tolua_S) - 1;

    if (argc == 0)
    {
        if(!ok)
        {
            tolua_error(tolua_S,"invalid arguments in function 'lua_PluginFacebookLua_PluginFacebook_getFriends'", nullptr);
            return 0;
        }
        std::vector<sdkbox::FBGraphUser> ret = sdkbox::PluginFacebook::getFriends();
        LuaStack* stack = LUAENGINE->getLuaStack();
        LuaValueArray array;
        for (std::vector<sdkbox::FBGraphUser>::iterator it = ret.begin(); it != ret.end(); it++)
        {
            LuaValueDict dict;
            dict[FBGraphUser_ID]         = LuaValue::stringValue(it->uid);
            dict[FBGraphUser_NAME]       = LuaValue::stringValue(it->name);
            dict[FBGraphUser_FIRST_NAME] = LuaValue::stringValue(it->firstName);
            dict[FBGraphUser_LAST_NAME]  = LuaValue::stringValue(it->lastName);
            dict[FBGraphUser_INSTALLED]  = LuaValue::booleanValue(it->isInstalled);

            array.push_back(LuaValue::dictValue(dict));
        }

        stack->pushLuaValueArray(array);

        return 1;
    }
    luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "sdkbox.PluginFacebook:getFriends",argc, 0);
    return 0;
#if COCOS2D_DEBUG >= 1
    tolua_lerror:
    tolua_error(tolua_S,"#ferror in function 'lua_PluginFacebookLua_PluginFacebook_getFriends'.",&tolua_err);
#endif
    return 0;
}
예제 #3
0
static int lua_get_XMLHttpRequest_response(lua_State* L)
{
    LuaMinXmlHttpRequest* self = nullptr;
    
#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
    if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror;
#endif
    
    self = (LuaMinXmlHttpRequest*)  tolua_tousertype(L,1,0);
#if COCOS2D_DEBUG >= 1
    if (nullptr == self)
    {
        tolua_error(L,"invalid 'self' in function 'lua_get_XMLHttpRequest_response'\n", nullptr);
		return 0;
    }
#endif
    
    if (self->getResponseType() == LuaMinXmlHttpRequest::ResponseType::JSON)
    {
        if (self->getReadyState() != LuaMinXmlHttpRequest::DONE || self->getErrorFlag())
            return 0;
        
        lua_pushstring(L, self->getDataStr().c_str());
        return 1;
    }
    else if(self->getResponseType() == LuaMinXmlHttpRequest::ResponseType::ARRAY_BUFFER)
    {
        if (self->getReadyState() != LuaMinXmlHttpRequest::DONE || self->getErrorFlag())
            return 0;
        
        LuaStack *pStack = LuaEngine::getInstance()->getLuaStack();
        if (NULL == pStack) {
            return 0;
        }
        
        lua_State *tolua_s = pStack->getLuaState();
        if (NULL == tolua_s) {
            return 0;
        }
        
        LuaValueArray array;
        
        uint8_t* tmpData = new uint8_t[self->getDataSize()];
        if (nullptr == tmpData)
        {
            return 0;
        }
        
        self->getByteData(tmpData);
        
        for (int i = 0 ; i < self->getDataSize(); i++)
        {
            LuaValue value = LuaValue::intValue(tmpData[i]);
            array.push_back(value);
        }
        
        pStack->pushLuaValueArray(array);
        
        CC_SAFE_DELETE_ARRAY(tmpData);
        return 1;
    }
    else
    {
        lua_pushstring(L, self->getDataStr().c_str());
        return 1;
    }
    
#if COCOS2D_DEBUG >= 1
tolua_lerror:
    tolua_error(L,"#ferror in function 'lua_get_XMLHttpRequest_response'.",&tolua_err);
    return 0;
#endif
}