[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Problems when traversing tables.
- From: "Nick Trout" <nick@...>
- Date: Tue, 15 May 2001 21:57:43 +0100
Hi, another strategy you could probably try is to use Lua to traverse your
tables. I generally use toLua with my applications as its dead easy to
expose your C/C++ API and include embedded Lua code in your app. You can
always wrap your code yourself and lua_dostring() your table parser though.
So you would "push" the data into your app with Lua from the table as
opposed to "pulling" the data from the table using the C API as you are
doing. The advantage of this is you are traversing the Lua tables in Lua so
you dont end up with lots of table parser code (which can be a bother to
maintain).
eg. (sketchy example :-) your C API would be something like (which would be
wrapped however...) :-
Block *createBlock(char *name);
void setTableSize(Block*,int x);
void setEntry(Block *,int index,int value);
and your Lua code is something like :-
for blockname,block in BLOCKS do
local b = createBlock(blockname)
setTableSize(b, getn(block))
for i,v in block do
setEntry(b, i-1, v)
end
end
Regards,
Nick
----- Original Message -----
From: Joakim Hansson
Maybe this is a trivial question, but I have spent quit a lot of
time trying to solve the following seemingly uncomplicated task:
I have a LUA program that looks like this:
------ Start of pasted file ------
IDENTIFIER_TXT = 'RX-EEPROM_DESCRIPTION';
NR_OF_BLOCKS = 3;
BLOCK_0 =
{
specific_length ={'Length', '1082', 'UINT16', 2, 0},
kalle ={'allan', '100', 'UINT16', 2, 0}
}
BLOCK_1 =
{
Code = {'Code' , '10' , 'UINT16', 2, 0},
Length = {'Length' , '1084', 'UINT16', 2, 0},
No_of_entries = {'No_entries', '12' , 'UINT8' , 1, 0}
}
BLOCK_2 =
{
id = {'Id' , 'RT' , 'ASC' , 2, 0},
bcd = {'-' , '0101', 'BCD' , 2, 0},
length = {'Length' , '0007', 'UINT16', 2, 1},
son_re = {'SON RE' , '80' , 'UINT16', 2, 2},
son_fe = {'SON FE' , '01' , 'UINT16', 2, 3},
sof_re = {'SOF RE' , '80' , 'UINT16', 2, 4},
sof_fe = {'SOF RE' , '01' , 'UINT16', 2, 5},
pll_clock_polarity = {'Pll Clock Polarity', '00' , 'UINT16', 2, 6},
pll_latch_polarity = {'Pll latch Polarity', '00' , 'UINT16', 2, 7},
prescale = {'Prescale' , '02' , 'UINT16', 2, 8}
}
---- End of pasted file ---