i am trying to read a ini file with in use with lua script. what ever i tryed i can not find a way to retrive the table info from the ini file.
filename is 'categories.lua'
Code: Select all
function ReadIni(inputfilename)
inputfile = SKIN:MakePathAbsolute(inputfilename)
local file = assert(io.open(inputfile, 'r'), 'Unable to open ' .. inputfile)
local tbl, section = {}
local num = 0
for line in file:lines() do
num = num + 1
if not line:match('^%s-;') then
local key, command = line:match('^([^=]+)=(.+)')
if line:match('^%s-%[.+') then
section = line:match('^%s-%[([^%]]+)'):lower()
if not tbl[section] then tbl[section] = {} end
elseif key and command and section then
tbl[section][key:lower():match('^%s*(%S*)%s*$')] = command:match('^%s*(.-)%s*$')
elseif #line > 0 and section and not key or command then
print(num .. ': Invalid property or value.')
end
end
end
if not section then print('No sections found in ' .. inputfile) end
file:close()
Value = tbl
--Value = inputfilename
--Value = inputfile
SKIN:Bang('!Update')
end
function Initialize()
Value = 2
end
function PassThrough(Number)
if Number then
Value = Number
else
Value = 1
end
SKIN:Bang('!Update')
end
function Reset()
Value =
SKIN:Bang('!Update')
end
function Update()
if Value then
return Value
else
return '10'
end
end
Code: Select all
[rainmeter]
update=1000
[variables]
inputfile=txt.ini
Table[section2][parameter1] = 'hmm oke'
Table[section1][parameter2] = 'yes?'
[measurescripting]
measure=script
scriptfile=categories.lua
dynamicvariables=1
updatedivider=1
[meterdisplay]
meter=string
measurename=measurescripting
fontsize=15
fontcolor=0,0,0,255
solidcolor=255,255,255,255
text=%1
w=650
h=50
leftmouseupaction=[!commandmeasure measurescripting ReadIni('#inputfile#')]
;leftmouseupaction=[!commandmeasure measurescripting Reset()]
;leftmouseupaction=[!commandmeasure measurescripting PassThrough(10)]
dynamicvariables=1
updatedivider=1
Code: Select all
[section1]
parameter1='cool'
parameter2='nice'
[section2]
parameter1='change'
parameter2='going'
thank you for your time.