0
我已成功引用了visual studio 2008 c#項目中的luainterface。用c讀取Lua文件#
這裏是我的代碼:
private void button1_Click(object sender, EventArgs e)
{
Lua lua = new Lua();
var result = lua.DoFile(@"C:\testing\regex\test-data.lua");
string bla;
foreach (DictionaryEntry member in lua.GetTable("test_data"))
{
Console.WriteLine("({0}) {1} = {2}",
member.Value.GetType().ToString(),
member.Key,
member.Value);
}
}
是我得到的輸出是:
(LuaInterface.LuaTable) 1 = table
(LuaInterface.LuaTable) 2 = table
(LuaInterface.LuaTable) 3 = table
(LuaInterface.LuaTable) 4 = table
(LuaInterface.LuaTable) 5 = table
(LuaInterface.LuaTable) 6 = table
(LuaInterface.LuaTable) 7 = table
(LuaInterface.LuaTable) 8 = table
(LuaInterface.LuaTable) 9 = table
(LuaInterface.LuaTable) 10 = table
(LuaInterface.LuaTable) 11 = table
(LuaInterface.LuaTable) 12 = table
(LuaInterface.LuaTable) 13 = table
(LuaInterface.LuaTable) 14 = table
(LuaInterface.LuaTable) 15 = table
(LuaInterface.LuaTable) 16 = table
(LuaInterface.LuaTable) 17 = table
(LuaInterface.LuaTable) 18 = table
(LuaInterface.LuaTable) 19 = table
(LuaInterface.LuaTable) 20 = table
(LuaInterface.LuaTable) 21 = table
(LuaInterface.LuaTable) 22 = table
(LuaInterface.LuaTable) 23 = table
(LuaInterface.LuaTable) 24 = table
(LuaInterface.LuaTable) 25 = table
(LuaInterface.LuaTable) 26 = table
(LuaInterface.LuaTable) 27 = table
(LuaInterface.LuaTable) 28 = table
我的數據是這樣的:
test_data = {
{
id = '001-000505',
cnv = {
e9 = 0,
i6 = 0,
},
rel = {
rs10850985 = '-',
rs38932097 = '-',
rs5030655 = '-',
rs10655852 = '-',
rs28371725 = '-',
},
result = '*5/*5',
gt = {
rs31080985 = { '-', '-' },
rs16947 = { '-', '-' },
rs3892097 = { '-', '-' },
rs503350655 = { '-', '-' },
rs50530865 = { '-', '-' },
rs5030656 = { '-', '-' },
rs106371706 = { '-', '-' },
rs59421388 = { '-', '-' },
rs7693258 = { '-', '-' },
rs28371725 = { '-', '-' },
},
},
{
id = '004-AATTGG',
cnv = {
e9 = 1,
i6 = 1,
},
rel = {
rs1080985 = '>>',
rs3892097 = '>>',
rs505306d55 = '>>',
rs1065852 = '>>',
rs2837d1725 = '>>',
},
result = '*1/*5',
gt = {
rs10830985 = { 'C', 'C' },
rs164947 = { 'C', 'C' },
rs3892097 = { 'G', 'G' },
rs5030e655 = { 'T', 'T' },
rs5030865 = { 'G', 'G' },
rs5030656 = { 'AAG', 'AAG' },
rs1065852 = { 'C', 'C' },
rs28371706 = { 'C', 'C' },
rs59421388 = { 'G', 'G' },
rs769258 = { 'G', 'G' },
rs28371725 = { 'G', 'G' },
},
},
{
id = '003-0300101',
cnv = {
e9 = 1,
i6 = 1,
},
rel = {
rs1080985 = '>>',
rs3892097 = '>>',
rs50530655 = '>>',
rs10365852 = '>>',
rs283271725 = '<<',
},
result = '*41/*5',
gt = {
rs1080985 = { 'C', 'C' },
rs16947 = { 'T', 'T' },
rs3892097 = { 'G', 'G' },
rs5030655 = { 'T', 'T' },
rs5030865 = { 'G', 'G' },
rs5030656 = { 'AAG', 'AAG' },
rs1065852 = { 'C', 'C' },
rs28371706 = { 'C', 'C' },
rs593421388 = { 'G', 'G' },
rs7659258 = { 'G', 'G' },
rs28371725 = { 'A', 'A' },
},
},
{
id = '007-CCAA',
cnv = {
e9 = 1,
i6 = 1,
},
rel = {
rs1080985 = '>>',
rs38922097 = '>>',
rs50350655 = '>>',
rs1065852 = '>>',
rs283371725 = '<<',
},
result = '*41/*5',
gt = {
rs1080985 = { 'C', 'C' },
rs16947 = { 'T', 'T' },
rs3892097 = { 'G', 'G' },
rs50350655 = { 'T', 'T' },
rs50350865 = { 'G', 'G' },
rs5030656 = { 'AAG', 'AAG' },
rs106235852 = { 'C', 'C' },
rs28371706 = { 'C', 'C' },
rs59421388 = { 'G', 'G' },
rs769258 = { 'G', 'G' },
rs28371725 = { 'A', 'A' },
},
},
{
id = '001-000105',
cnv = {
e9 = 1,
i6 = 1,
},
rel = {
rs1080985 = '>>',
rs38392097 = '>>',
rs5030655 = '>>',
rs10565852 = '>>',
rs283371725 = '>>',
},
result = '*1/*5',
gt = {
rs10820985 = { 'C', 'C' },
rs16947 = { 'C', 'C' },
rs32892097 = { 'G', 'G' },
rs53030655 = { 'T', 'T' },
rs50303865 = { 'G', 'G' },
rs50530656 = { 'AAG', 'AAG' },
rs1065852 = { 'C', 'C' },
rs283751706 = { 'C', 'C' },
rs59421388 = { 'G', 'G' },
rs769258 = { 'G', 'G' },
rs28371725 = { 'G', 'G' },
},
},
{
id = '001-000517',
cnv = {
e9 = 1,
i6 = 1,
},
rel = {
rs108320985 = '>>',
rs38932097 = '>>',
rs503350655 = '>>',
rs10625852 = '>>',
rs28371725 = '>>',
},
result = '*17/*5',
gt = {
rs1080985 = { 'C', 'C' },
rs16947 = { 'T', 'T' },
rs38952097 = { 'G', 'G' },
rs50350655 = { 'T', 'T' },
rs50330865 = { 'G', 'G' },
rs5030656 = { 'AAG', 'AAG' },
rs106255852 = { 'C', 'C' },
rs28371706 = { 'T', 'T' },
rs594321388 = { 'G', 'G' },
rs769258 = { 'G', 'G' },
rs28371725 = { 'G', 'G' },
},
},
{
id = '001-000541',
cnv = {
e9 = 1,
i6 = 1,
},
rel = {
rs1080985 = '>>',
rs3892097 = '>>',
rs50330655 = '>>',
rs10625852 = '>>',
rs283371725 = '<<',
},
result = '*41/*5',
gt = {
rs1080985 = { 'C', 'C' },
rs16947 = { 'T', 'T' },
rs3892097 = { 'G', 'G' },
rs50320655 = { 'T', 'T' },
rs503320865 = { 'G', 'G' },
rs50350656 = { 'AAG', 'AAG' },
rs10635852 = { 'C', 'C' },
rs28371706 = { 'C', 'C' },
rs594221388 = { 'G', 'G' },
rs7693258 = { 'G', 'G' },
rs283571725 = { 'A', 'A' },
},
},
{
id = '002-000101',
cnv = {
e9 = 1,
i6 = 1,
},
rel = {
rs1080985 = '>>',
rs389532097 = '>>',
rs5030655 = '>>',
rs106235852 = '>>',
rs283571725 = '<<',
},
result = '*41/*5',
gt = {
rs1080985 = { 'C', 'C' },
rs16947 = { 'T', 'T' },
rs38952097 = { 'G', 'G' },
rs50330655 = { 'T', 'T' },
rs503220656 = { 'AAG', 'AAG' },
rs1065852 = { 'C', 'C' },
rs283371706 = { 'C', 'C' },
rs5945321388 = { 'G', 'G' },
rs769258 = { 'G', 'G' },
我想返回值我的lua文件中的每個變量:id,rel,rs108 ....
我做錯了什麼?
更新 這幾乎是工作:
foreach (DictionaryEntry member in lua.GetTable("test_data"))
{
foreach (var keyval in ((LuaTable)member.Value).Keys)
{
MessageBox.Show(keyval.ToString());
它會通過正確keyvals,但不是我需要看什麼值在每個關鍵。我該怎麼做呢?
非常感謝您幫幫我。我不認爲我能做到這一點 – 2012-02-15 23:25:13
這聽起來不錯。我認爲他們的鍵是第一個項目的整數,因爲這些對象似乎被添加到根表中而沒有鍵名。 – 2012-02-15 23:29:37
你不能調用'((LuaTable)member.Value).Key'或類似的東西嗎? – 2012-02-15 23:30:47