It is currently October 14th, 2024, 9:44 pm

What happens in a lua cycle.

Discuss the use of Lua in Script measures.
User avatar
jsmorley
Developer
Posts: 22856
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: What happens in a lua cycle.

Post by jsmorley »

That's not to say that for / next loops are not of huge value in Lua, they certainly are. Nor does it mean you can't ever embed bangs inside the loop, you can. Just understand that they all happen "at once".

Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[Lua]
Measure=Script
ScriptFile=#CURRENTPATH#Test.lua

[Meter1]
Meter=String
FontSize=12
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1

[Meter2]
Meter=String
Y=5R
FontSize=12
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1

[Meter3]
Meter=String
Y=5R
FontSize=12
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1

[Meter4]
Meter=String
Y=5R
FontSize=12
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1

[Meter5]
Meter=String
Y=5R
FontSize=12
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Lua:

Code: Select all

function Update()

	for a = 1, 5 do
		SKIN:Bang('!SetOption', 'Meter'..a, 'Text', 'This is meter '..a)
	end
	
	SKIN:Bang('!UpdateMeter', '*')
	SKIN:Bang('!Redraw')

end
1.png
You do not have the required permissions to view the files attached to this post.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: What happens in a lua cycle.

Post by kyriakos876 »

jsmorley wrote: December 12th, 2018, 3:14 pm No, the value of myCount in the Lua is not "forgotten". The Lua is not "closed". A Lua Script measure is never "closed" unless the skin is refreshed or unloaded.
Oh damn... So any global variables will reserve memory until a refresh or unload?
User avatar
jsmorley
Developer
Posts: 22856
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: What happens in a lua cycle.

Post by jsmorley »

kyriakos876 wrote: December 12th, 2018, 6:45 pm Oh damn... So any global variables will reserve memory until a refresh or unload?
Sure. Do you know how many variables you would have to define to have any appreciable or even detectable effect on memory?

If you envision each of these lines as being defined as Var(N)='whatever':

Code: Select all

42.7 percent of all statistics are made up on the spot.
99 percent of lawyers give the rest a bad name.
A bore is a man who deprives you of solitude without providing you with company.
A closed mouth gathers no foot.
A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila.
A conclusion is simply the place where you got tired of thinking.
A crisis is when you can't say "Let's forget the whole thing." 
A day without sunshine is like, night.
A diplomat is someone who can tell you to go to hell in such a way that you will look forward to the trip.
A flashlight is a case for holding dead batteries.
A live plowhorse is still better than a dead thoroughbred. 
A ship in the harbor is safe, but that is not what ships were made for.
A single fact can spoil a good argument.
Age and Treachery Will Always Overcome Youth and Skill
All extremists should be taken out and shot.
All generalizations are false, including this one.
All jobs require you to do things you'd rather not do. That's why they have to pay you.
All software is bug-free, assuming sufficiently clever definitions of "feature" and "expected behaviour".
An honest politician is one who, when he is bought, will stay bought.
An ID card is solely for the purpose of allowing the government to compel you to produce it.
And whose cruel idea was it for the word "Lisp" to have a "S" in it?
Any sufficiently advanced incompetence is indistinguishable from malice.
Any sufficiently advanced technology is indistinguishable from magic. 
Anybody who wants the presidency so much that he'll spend two years organizing and campaigning for it is not to be trusted with the office.
Anything worth taking seriously is worth making fun of.
Are the two e's in "bee" silent?
Artificial Intelligence usually beats real stupidity.
Atheism is a non-prophet organization.
Auntie Em, Hate you, hate Kansas, taking the dog. Dorothy.
Avenge yourself; live long enough to be a problem to your children. 
Be nice to your kids, for it is they who will choose your nursing home. 
Better to understand a little than to misunderstand a lot.
Bills travel through the mail at twice the speed of checks. 
Borrow money from pessimists-they don't expect it back. 
Change is inevitable, except from a vending machine.
Chaos, panic, and disorder - my work here is done.
Complex problems have simple, easy to understand wrong answers. 
Conscience is the inner voice that warns us somebody is looking.
Consciousness: That annoying time between naps.
Death is hereditary.
Democracy must be something more than two wolves and a sheep voting on what to have for dinner. – James Bovard
Despite the cost of living, have you noticed how popular it remains?
Diplomacy is the art of saying "nice doggy" until you can find a rock. 
Disappointment is anger for wimps.
Don't be irreplaceable; if you can't be replaced, you can't be promoted.
Don't be sexist; chicks hate that! 
Don't look back, they might be gaining on you.
Don't make me mad. I'm running out of places to hide the bodies.
Drawing on my fine command of language, I said nothing.
Eagles may soar, but weasels aren't sucked into jet engines. 
Employee of the month is a good example of how somebody can be both a winner and a loser at the same time.
Errors have been made. Others will be blamed.
Even the best of friends cannot attend each other's funeral.
Ever notice that "what the hell" is always the right decision?
Every day I get up and look through the Forbes list of the richest people in America. If I'm not on it, I go to work.
Everyone smiles in the same language.
Everything is funny, as long as it's happening to somebody else.
Experience is something you don't get until just after you need it.
First things first, but not necessarily in that order.
Five out of four people have a problem with fractions. 
For Sale: Parachute. Only used once, never opened, small stain.
Forgive your enemies, but never forget their names. 
Friends help you move. Real friends help you move bodies. 
Friends may come and go, but enemies accumulate. Thomas Jones 
Give me ambiguity or give me something else.
Giving money and power to government is like giving whiskey and car keys to teenage boys. – P.J. O'Rourke
Good judgment comes from bad experience and a lot of that comes from bad judgment.
Gravity: It's not just a good idea. It's the law.
Half the people in the world are above average.
Hard work has a future payoff. Laziness pays off now.
He who smiles in a crisis has found someone to blame.
Health nuts are going to feel stupid someday, lying in hospitals dying of nothing.
Hell hath no fury like the lawyer of a woman scorned. 
Help a man when he is in trouble, and he will remember you when he is in trouble again.
Hey, i was just talking about you. well, not about you specifically, about whores and hypocrisy.
How do you tell when you run out of invisible ink?
How does Teflon stick to the pan?
How many of you believe in telekinesis? Raise my hand.
I’m not a complete idiot, some parts are missing!
I’m writing a book. I’ve got the page numbers done.
I always wanted to be somebody, but now I realize I should have been more specific.
I am not infantile, you stinky poopyhead.
I asked God for a bike, but I know God doesn’t work that way. So I stole a bike and asked for forgiveness.
I can't remember if I'm the good twin or the evil one.
I couldn’t repair your brakes, so I made your horn louder.
I didn’t fight my way to the top of the food chain to be a vegetarian
I didn’t say it was your fault. I said I was going to blame you.
I do not know how the Third World War will be fought, but I know how the Fourth will: with sticks and stones.
I do not participate in any sport with ambulances at the bottom of a hill.
I don’t suffer from insanity. I enjoy every minute of it.
I don't have a solution but I admire the problem.
I don't have to outrun the bear. I only have to outrun you.
I don't mind the voices in my head, it's the ones in yours that bug me. 
I don't necessarily agree with everything I say.
I don't think I'm indecisive. . . 
I don't want to achieve immortality through my work; I want to achieve immortality through not dying. 
I feel like I’m diagonally parked in a parallel universe.
I get enough exercise just pushing my luck.
I hear voices in my head and they say they don't like you. 
I intend to live forever. So far, so good.
I just got lost in thought. It was unfamiliar territory.
I just thought of the best hyperbole
I love deadlines. I like the whooshing sound they make as they fly by.
I need someone really bad. Are you really bad?
I totally take back all those times I didn't want to nap when I was younger.
I used to be schizophrenic, but we're OK now.
I used to have an open mind but my brains kept falling out.
I used to listen to the voices in my head, but I ran out of places to hide the bodies.  
I used to think I was indecisive, but now I'm not so sure. 
I'd kill for a Nobel Peace Prize. 
I'm absolutely the single most modest person you will ever meet.
I'm having deja-vu and amnesia at the same time. It's like I think I've forgotten this before
I'm not crazy, I've just been in a very bad mood for 30 years.
I'm not tense, just terribly, terribly alert.
If someone says, "It's not the money, it's the principle of the thing," it's the money.
If after 2 hours in a poker game you are not sure who the pigeon is, you are.
If at first you don’t succeed, destroy all evidence that you tried.
If at first you don't succeed, skydiving is not for you.
If at first you don't succeed, try, try again. Then quit. No use being a damn fool about it.
If I agreed with you we’d both be wrong.
If I had known I was going to live this long, I'd have taken better care of myself. 
If I walked on water people would say I couldn't swim.
If ignorance is bliss, why aren't there more happy people?
If it holds water, it's craft. If it leaks, it's art.
If it isn't broken, fix it until it is.
If things get any worse, I'll have to ask you to stop helping me.
If we aren't supposed to eat animals, why are they made of meat? 
If you have two choices, and you eliminate one, you have zero choices.
If you can’t convince them, confuse them.
If you can read this, I can slam on my brakes and sue you!
If you have no specific destination in mind you can't be lost.
If you lend someone $20, and never see that person again, it was probably worth it.
If you must choose between two evils, pick the one you've never tried before.
If you tell the truth, you don't have to remember anything.
If you think nobody cares if you're alive, try missing a couple of car payments.
In nature, there are neither rewards nor punishments -- there are consequences.
Inside every older person is a younger person wondering, "What the heck happened?"
Instead of getting married again, I'm going to find a woman I don't like and just give her a house.
Is it time for your medication or mine?
Isn't it interesting that the same people who laugh at science fiction listen to weather forecasts and economists?
It ain't what they call you, it's what you answer to. 
It is bad luck to be superstitious.
It is easier to obtain forgiveness than permission!
It is not necessary to understand things in order to argue about them.
It is seldom that liberty of any kind is lost all at once.
It may be that my whole purpose in life is simply to serve as a warning to others. 
It's been lovely, but I have to scream now. 
It's better to have it and not need it than to need it and not have it. 
It's lonely at the top, but you eat better.
Just because you're paranoid doesn't mean they're not out to get you 
Just practising for my clown college audition.
Knowing too much about each other is exactly why people leave small towns and move to the city.
Knowledge is power, and power corrupts. So study hard and be evil.
Life can only be understood backwards; but it must be lived forwards.
Life is a terminal disease.
Life is what happens to you while you are making other plans.
Live each day as if it were the last day of your life, because so far, it is.
Living on Earth is expensive, But it does include a trip around the sun.
Lottery: A tax on people who are bad at math. 
Love may be blind, but marriage is a real eye opener.
Money isn't everything, but it sure keeps the kids in touch. 
Most problems are either unimportant or impossible to solve.
My kid had sex with your honor student. 
My wife keeps complaining I never listen to her (or something like that).
Never argue with a fool. Someone watching may not be able to tell the difference.
Never ask a barber if he thinks you need a haircut.
Never attribute to malice what can adequately be explained by stupidity. 
Never do your best card tricks for the group you play poker with. 
Never insult an alligator until after you have crossed the river.
Never put off till tomorrow what you can avoid all together.
Never test the depth of the water with both feet.
No good deed ever goes unpunished. 
No man would listen to you talk if he didn't know it was his turn next.
No one is listening until you make a mistake.
Nostalgia isn't what it use to be.
Not everything that can be counted counts, and not everything that counts can be counted
Nothing sucks more than that moment during an argument when you realize you're wrong.
Of all the things I've lost, it's my mind I miss the most. 
Oh Lord, give me patience, and GIVE IT TO ME NOW!
On your mark, get set, go away!
One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important.
One out of every four Americans is suffering from some form of mental illness. Think of your three best friends. If they're okay, then it's you.
Plan to be spontaneous, tomorrow.
Please don't lie to me, unless you're absolutely sure I'll never find out the truth.
Politicians and diapers have one thing in common. They should both be changed regularly, and for the same reason.
Politics is the gentle art of getting votes from the poor and campaign funds from the rich by promising to protect each from the other.
Pride is what we have. Vanity is what others have.
Problems cannot be solved by the same level of thinking that created them. - Albert Einstein
Procrastinate now.
Puritanism: The haunting fear that someone, somewhere may be happy.
Quickly, I must hurry, for there go my people and I am their leader.
Quoting one is plagiarism. Quoting many is research.
Reality is a crutch for people who can't handle drugs.
Rehab is for quitters.
Remember, if the logs float upstream, they are not logs. 
Remember, it's the second mouse that gets the cheese.
Rock is dead. Long live paper and scissors.
Sex without love is an empty experience, but, as empty experiences go, it's one of the best. 
Some days it's just not worth gnawing through the leather straps.
Some days you are the bug, some days you are the windshield.
Some part of the journey is going to be uphill. 
Some people are only alive because it is illegal to shoot them.
Someday, we'll look back on this, laugh nervously and change the subject.
Sometimes I think war is God's way of teaching us geography.
Stress is when you wake up screaming and you realize you weren't asleep.
Success always occurs in private and failure in full view.
Support mental health or I'll kill you
Taxation WITH representation isn't so hot, either!
Teamwork is wasting half of one's time explaining to others why they are wrong.
The amount of work to be done increases in proportion to the amount of work already completed.
The beatings will continue until morale improves.
The Bible was written by the same people who said the Earth was flat. 
The creative are slaves to their talent, and must answer when it summons. 
The fact that no one understands you doesn't mean you're an artist.
The first ninety percent of the task takes ninety percent of the time, and the last ten percent takes the other ninety percent.
The future will be better tomorrow.
The goal of science is to build better mousetraps. The goal of nature is to build better mice.
The IQ of the group is the lowest IQ of a member of the group divided by the number of people in the group. 
The last thing I want to do is hurt you. But it's still on the list.
The last time politics and religion were mixed, people were burned at the stake.
The lion and the lamb shall lie down together, but the lamb won't get much sleep. 
The nice thing about standards is, there are so many to choose from.
The only change reading about something on the internet will make in someone's opinion is from none to wrong.
The only substitute for good manners is fast reflexes.
The race is not always to the swift, nor the battle to the strong -- but that's usually the way to bet.
The trouble with doing something right the first time is that nobody appreciates how difficult it was. 
The trouble with life is there's no background music. 
The trouble with the gene pool is that there's no lifeguard.
There are 10 types of people in the world. Those who understand binary, and those who don't.
There are no rules here -- we're trying to accomplish something.
There has been an alarming increase in the number of things I know nothing about. 
There's an old proverb that says just about whatever you want it to.
There's never time to do it right, but always time to do it over!
There's no place like 127.0.0.1
They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.
Three out of four voices in my head said I should stay home and clean the guns. 
Time is nature's way of keeping everything from happening all at once.
Timing has an awful lot to do with the outcome of a rain dance.
To err is human, to blame it on somebody else shows management potential.
Today is the first day of the rest of your life. But so was yesterday, and look how you messed that up.
Too many freaks, not enough circuses.
Trust everybody, but cut the cards.
War does not determine who is right – only who is left.
Warning: Dates on calendar are closer than they appear.
We never really grow up, we only learn how to act in public.
We should forgive our enemies, but only after they've been taken out and shot.
We were born naked, wet and hungry. Then things got worse.
We will burn that bridge when we come to it.
Well, this day was a total waste of makeup.
What happens if you get scared half to death twice?
What if the hokey pokey really is what it's all about?
What's another word for Thesaurus?
Whatever kind of look you were going for, you missed.
When all is said and done, more is said than done.
When the government's boot is on your throat, whether it is a left boot or a right boot is of no consequence. – Gary Lloyd
When you are in deep water it's a good idea to keep your mouth shut.
When you gamble, you have to consider losing as one of the possibilities.
When you have eliminated the impossible, whatever remains, however improbable, must be the truth.
Why is "abbreviation" such a long word?
Women need a reason to have sex. Men just need a place
Wrinkled was not one of the things I wanted to be when I grew up!
You can get more with a kind word and a gun than you can with a kind word alone. 
You sound reasonable......time to up my medication.
You're just jealous because the voices only talk to ME.
Your theory is crazy, but it's not crazy enough to be true.
Your village called. They're missing their idiot.
Every organization is perfectly designed to get the results they are getting.
That's uhm.. 18kB of memory.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: What happens in a lua cycle.

Post by kyriakos876 »

jsmorley wrote: December 12th, 2018, 7:29 pm .
.
.
That's uhm.. 18kB of memory.
Are the tables the same? Because I have plenty of skins that parse more than 5MB files and hold them in a table. But I guess tables don't work like variables right?
User avatar
jsmorley
Developer
Posts: 22856
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: What happens in a lua cycle.

Post by jsmorley »

kyriakos876 wrote: December 12th, 2018, 7:56 pm Are the tables the same? Because I have plenty of skins that parse more than 5MB files and hold them in a table. But I guess tables don't work like variables right?
I'm not sure, but I expect that the full 5MB would be held in memory. I personally can't get too excited about even 5MB in the grand scheme of things. That is just line-noise in a system with 8-16GB of memory.

If you are creating the table in the Update() (or any other) function of the Script, feel free to nuke it just before you "return".

Code: Select all

function Update()
	myTable={}
	myTable[1] = 'Hello'
	myTable[2] = 'World'

	SKIN:Bang('!SetOption', 'MeterOne', 'Text', myTable[1])
	SKIN:Bang('!SetOption', 'MeterTwo', 'Text', myTable[2])
	myTable = nil
	return 
end
If you are creating and populating the table in Initialize(), which is run only once, it will simply have to stay in memory, to be available to Update() or other functions later. How could it not?

Code: Select all

function Initialize()
	myTable={}
	myTable[1] = 'Hello'
	myTable[2] = 'World'
end

function Update()
	SKIN:Bang('!SetOption', 'MeterOne', 'Text', myTable[1])
	SKIN:Bang('!SetOption', 'MeterTwo', 'Text', myTable[2])
	return 
end
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: What happens in a lua cycle.

Post by kyriakos876 »

Nuke it is then!
200.gif
You do not have the required permissions to view the files attached to this post.