加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

lua数组进入c数组

发布时间:2020-12-14 21:44:32 所属栏目:大数据 来源:网络整理
导读:local pricetagColors = { [3242] = {255,255},[6712] = {255,255,0} } function getPricetagColor(itemnumber) local r,g,b = 0,0 if pricetagColors[itemnumber] then r,b = pricetagColors[itemnumber][1],pricetagColors[itemnumber][2],pricetagColors[
local pricetagColors = {
    [3242] = {255,255},[6712] = {255,255,0}
 }

 function getPricetagColor(itemnumber)
    local r,g,b = 0,0

    if pricetagColors[itemnumber] then
        r,b = pricetagColors[itemnumber][1],pricetagColors[itemnumber][2],pricetagColors[itemnumber[3]
    end

    return {r,b}
 end

好吧,所以我正试着一步一步进入C.
现在我想弄清楚C中的(复杂?)数组是如何创建的.
由于我不知道如何以另一种方式解释它,我在LUA中做到了,因为这是我最熟悉的.
这个函数并不重要,重要的是数组,因为我现在已经搜索了几个小时,但是我无法弄清楚如何获得你在C中用lua看到的数组.

解决方法

看起来你在问题中所拥有的东西等同于std :: map< int,std :: array< int,3>>.

std::map<int,std::array<int,3>> pricetagColors;
pricetagColors[3242] = {255,255};
pricetagColors[6712] = {255,0};

int itemnumber = 3242,r,b;
if (pricetagColors.find(itemnumber) != pricetagColors.end())
{
    r = pricetagColors[itemnumber][0];
    g = pricetagColors[itemnumber][1];
    b = pricetagColors[itemnumber][2]; //Note that the comma operator could be used here,//but it isn't really an idiomatic C++ use
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读