It is currently April 18th, 2024, 9:07 pm

readini get table info from file

Get help with creating, editing & fixing problems with skins
Judian81
Posts: 180
Joined: May 6th, 2021, 2:57 pm

readini get table info from file

Post by Judian81 »

hellow rainmeter,

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

filename is table.ini

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

filename is txt.ini

Code: Select all

[section1]
parameter1='cool'
parameter2='nice'

[section2]
parameter1='change'
parameter2='going'



thank you for your time.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2603
Joined: March 23rd, 2015, 5:26 pm

Re: readini get table info from file

Post by SilverAzide »

Judian81 wrote: October 10th, 2022, 4:18 pm hellow rainmeter,

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.

thank you for your time.
You are mixing Lua code and Rainmeter .ini files together, which is incorrect. These lines...

Code: Select all

Table[section2][parameter1] = 'hmm oke'
Table[section1][parameter2] = 'yes?'
...will not work. This is not how you retrieve data from a Lua function. There may be other errors, I did not check further.
Gadgets Wiki GitHub More Gadgets...
User avatar
tass_co
Posts: 511
Joined: May 4th, 2020, 3:01 pm
Location: Ankara, TURKEY

Re: readini get table info from file

Post by tass_co »

Judian81 wrote: October 10th, 2022, 4:18 pm hellow rainmeter,

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.

thank you for your time.
I don't have enough knowledge for Lua script.
But I would like to share an example that I have done before.
Here is the script: It takes the data in the file line by line and writes it to the variables
I hope it helps a little bit in doing what you want :thumbup:

GIF 11.10.2022 14-10-15.gif
ReadFilewithLua_1.0.rmskin

Code: Select all

[Rainmeter]
Update=1000

[Variables]
ReadFile=#@#Values.ini
var1=
var2=
var3=
var4=
var5=
var6=
var7=

[MeaLua]
Measure=Script
ScriptFile=#@#Read.lua

[MtrBg]
Meter=Image
SolidColor=0,0,0
W=176
H=300
LeftMouseUpAction=[!CommandMeasure MeaLua "ReadValues()"]
DynamicVariables=1

[MtrFile]
Meter=String
SolidColor=105,100,255
FontColor=225,255,255
StringStyle=Bold
StringEffect=SHADOW
AntiAlias=1
X=0
Y=0
StringAlign=Left
Text=#var1##CRLF##var2##CRLF##var3##CRLF##var4##CRLF##var5##CRLF##var6##CRLF##var7##CRLF#
DynamicVariables=1
AntiAlias=1
LUA

Code: Select all

function Initialize()

end

function ReadValues()
	local FileName = SKIN:GetVariable('ReadFile')
	FilePath = SKIN:MakePathAbsolute(FileName)
	local file = io.open(FilePath, 'r')
	fLines = {}
		for line in file:lines() do
			table.insert(fLines, line)
		end
	local count = 0
	for line in io.lines(FilePath) do
	   count = count + 1
	end
	file:close()
	cLine = count - 1
	SKIN:Bang('!SetVariable', 'var1', fLines[cLine - 5])
	SKIN:Bang('!SetVariable', 'var2', fLines[cLine - 4])
	SKIN:Bang('!SetVariable', 'var3', fLines[cLine - 3])
	SKIN:Bang('!SetVariable', 'var4', fLines[cLine - 2])
	SKIN:Bang('!SetVariable', 'var5', fLines[cLine - 1])
	SKIN:Bang('!SetVariable', 'var6', fLines[cLine])
	SKIN:Bang('!SetVariable', 'var7', fLines[cLine + 1])
	
end
You do not have the required permissions to view the files attached to this post.
I don't know where i going from here, but i promise it won't be boring... :great:
Judian81
Posts: 180
Joined: May 6th, 2021, 2:57 pm

Re: readini get table info from file

Post by Judian81 »

tass_co wrote: October 11th, 2022, 11:11 am I don't have enough knowledge for Lua script.
But I would like to share an example that I have done before.
Here is the script: It takes the data in the file line by line and writes it to the variables
I hope it helps a little bit in doing what you want :thumbup:
thanks. it is just what i needed to have.
i can now open a folder with fileview. and choose one of the files. and read the 3 first lines. and that wil be enough. :great:
User avatar
tass_co
Posts: 511
Joined: May 4th, 2020, 3:01 pm
Location: Ankara, TURKEY

Re: readini get table info from file

Post by tass_co »

Judian81 wrote: October 11th, 2022, 3:16 pm thanks. it is just what i needed to have.
i can now open a folder with fileview. and choose one of the files. and read the 3 first lines. and that wil be enough. :great:
I'm glad I could help :great:
I don't know where i going from here, but i promise it won't be boring... :great: