如何将Lua数组元素导入C语言数组中?

2026-06-05 09:365阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计289个文字,预计阅读时间需要2分钟。

如何将Lua数组元素导入C语言数组中?

javascriptconst pricetagColors={ [3242]: [255, 0, 255], [6712]: [255, 255, 0]};

function getPricetagColor(itemnumber) { const [r, g, b]=[0, 0, 0]; if (pricetagColors[itemnumber]) { [r, g, b]=pricetagColors[itemnumber]; } return [r, g, b];}

local pricetagColors = { [3242] = {255, 0, 255}, [6712] = {255, 255, 0} } function getPricetagColor(itemnumber) local r, g, b = 0, 0, 0 if pricetagColors[itemnumber] then r, g, b = pricetagColors[itemnumber][1], pricetagColors[itemnumber][2], pricetagColors[itemnumber[3] end return {r, g, b} end

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

如何将Lua数组元素导入C语言数组中?

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

std::map<int, std::array<int, 3>> pricetagColors; pricetagColors[3242] = {255, 0, 255}; pricetagColors[6712] = {255, 255, 0}; int itemnumber = 3242, r, g, 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 }

本文共计289个文字,预计阅读时间需要2分钟。

如何将Lua数组元素导入C语言数组中?

javascriptconst pricetagColors={ [3242]: [255, 0, 255], [6712]: [255, 255, 0]};

function getPricetagColor(itemnumber) { const [r, g, b]=[0, 0, 0]; if (pricetagColors[itemnumber]) { [r, g, b]=pricetagColors[itemnumber]; } return [r, g, b];}

local pricetagColors = { [3242] = {255, 0, 255}, [6712] = {255, 255, 0} } function getPricetagColor(itemnumber) local r, g, b = 0, 0, 0 if pricetagColors[itemnumber] then r, g, b = pricetagColors[itemnumber][1], pricetagColors[itemnumber][2], pricetagColors[itemnumber[3] end return {r, g, b} end

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

如何将Lua数组元素导入C语言数组中?

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

std::map<int, std::array<int, 3>> pricetagColors; pricetagColors[3242] = {255, 0, 255}; pricetagColors[6712] = {255, 255, 0}; int itemnumber = 3242, r, g, 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 }