最も簡易な構造luaデータテーブル
1867 ワード
print(" lua ")
local tbTest =
{
colKey = {sn=1, name=2, age=3, phone=4},
snKey = {[1001]=1,[1002]=2,[1003]=3},
[1] = {1001," ",31,18087777777},
[2] = {1002," ",33,18908888888},
[3] = {1003," ",35,13699999999},
}
print(#tbTest," ")
--print(tbTest["colKey"]["name"])
--print(tbTest[1].phone)
--
local function g_tab(_tb, _idx, _colKey)
local colIdx = _tb["colKey"][_colKey]
--print(colIdx)
if not colIdx then
return
end
local result = _tb[_idx][colIdx]
print(result)
return result
end
-- sn
local function g_tabSn(_tb, _sn, _colKey)
local colIdx = _tb["colKey"][_colKey]
--print(colIdx)
if not colIdx then
return
end
local snRowIdx = _tb["snKey"][_sn]
local result = _tb[snRowIdx][colIdx]
print(result)
return result
end
g_tab(tbTest, 1, "name")
g_tab(tbTest, 1, "age")
g_tab(tbTest, 1, "phone")
g_tab(tbTest, 2, "name")
g_tab(tbTest, 2, "age")
g_tab(tbTest, 2, "phone")
g_tab(tbTest, 3, "name")
g_tab(tbTest, 3, "age")
g_tab(tbTest, 3, "phone")
print(" ============= ")
g_tabSn(tbTest, 1001, "name")
g_tabSn(tbTest, 1001, "age")
g_tabSn(tbTest, 1001, "phone")
g_tabSn(tbTest, 1002, "name")
g_tabSn(tbTest, 1002, "age")
g_tabSn(tbTest, 1002, "phone")
g_tabSn(tbTest, 1003, "name")
g_tabSn(tbTest, 1003, "age")
g_tabSn(tbTest, 1003, "phone")
print(" ")
しゅつりょく
lua
3
31
18087777777
33
18908888888
35
13699999999
=============
31
18087777777
33
18908888888
35
13699999999