Hi I am trying to access a nested table sent from Lua to C. The table is:
arg =
{
MagicNumber = {MagicNumber, 0},
ProdNum = {ProdNum, 1},
LetterR = {LetterR, 0xc},
Revision = {Revision, 0xd},
Space1 = {Space1, 0xe},
MnfctrCode = {MnfctrCode, 0xf},
Hyphen1 = {Hyphen1, 0x12},
ZeroCode = {ZeroCode, 0x13},
Hyphen2 = {Hyphen2, 0x15},
MnfctrMnth = {MnfctrMnth, 0x16},
MnfctrYear = {MnfctrYear, 0x18},
SerialNum = {SerialNum, 0x1a},
Space2 = {Space2, 0x1e},
ChkSum = {ChkSum, 0x1f},
}
the table inside are both integer values, and the key in the table is a string. My code snippet is as ollows:
lua_pushnil(L);
while(lua_next(L, -2) != 0)
{
field = lua_tostring(L, -2);
printf("\n %d field = %s", i, field);
wrData[i-1] = lua_tonumber(L,-1);
printf("\n data = 0x%x", wrData[i-1]);
lua_pop(L, -1);
i++;
}
Am I missing anything, because the value I get back is 0x0
.
Alter this function to fit your needs, and call it with the table on the top of the stack.