[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Convert Pattern of String into Table with Values
- From: Hadriel Kaplan <HKaplan@...>
- Date: Sun, 3 Feb 2013 23:49:01 +0000
-- get simple list
local ElderScrollsInfo = {}
local Record
for indent, line in Ammo:gmatch'( *)(.-)\n' do
if line:find'^AMMO' then
ElderScrollsInfo[#ElderScrollsInfo+1] = {}
Record = ElderScrollsInfo[#ElderScrollsInfo]
end
local name, value = line:match'^(.-): (.*)$'
if name then
name = name:match'^(.-) %-' or name -- make names short
Record[name] = value
end
end
assert(#ElderScrollsInfo == 4)
-- unsorted printing of records/fields
for i, Record in ipairs(ElderScrollsInfo) do
print('Record #'..i)
for k,v in pairs(Record) do
print('\t'..k..'\t=\t'..v)
end
end
On Feb 3, 2013, at 4:04 PM, Billy Peacock <spooky_loco_pv@yahoo.com> wrote:
> Egor Skriptunoff <egor.skriptunoff <at> gmail.com> writes:
>
>>
>>
>> On Sun, Feb 3, 2013 at 8:14 PM, Billy Peacock <spooky_loco_pv <at> yahoo.com>
> wrote:
>> I am trying to collect a range of Data from a string, that holds Data Values
>> example..
>> assert(Table.Ammo.Signature == 'AMMO')
>> assert(Table.Ammo.['Data Size'] == 194)
>> If anyone has any input on how to help me, i would appreciate it alot
>>
>>
>> IMHO, LPEG is a bit overkill.Lua regexp support is enough here.Two versions:
>
> --------------------------
>
> Hi, i want to thank you for your advance technique its really nice. I appreciate
> it. Do you know how i could parse each record singularly?, because each record
> is placed after each other in a Text File
>
> Pastebin has 4 Records of 'AMMO' each different from the next
> Example: http://pastebin.com/SGmppN33
>
>