Page 1 of 1

How to run a lua file

Posted: Wed Aug 19, 2015 9:55 pm
by TheJebForge
I was searching it in wiki, but didn't found it. How do I run other lua file?

Re: How to run a lua file

Posted: Wed Aug 19, 2015 11:15 pm
by eqnox
im assuming you want to know how to take the folder that houses all of your lua files and run them in love. you just drag the folder into the love application icon on your desktop.

Re: How to run a lua file

Posted: Thu Aug 20, 2015 2:18 am
by arampl
TheJebForge wrote:I was searching it in wiki, but didn't found it.
Because it's not question about LÖVE. It's question about Lua.
TheJebForge wrote:How do I run other lua file?
Read PIL ("Programming in Lua" book). Read about "dofile", "loadstring", "require".

And if you want to run other .love file then you can "os.execute("love.exe other.love")" for example.

Re: How to run a lua file

Posted: Thu Aug 20, 2015 8:46 am
by NickRock
-On windows-
If you have lua installed you can just open a command prompt go to the directory you have the lua file

Code: Select all

cd Desktop
for example (if it's on desktop)
and then type

Code: Select all

lua main.lua
I don't know how to run lua programs in other operating systems because I only use Windows

I hope I that makes sense :P

Re: How to run a lua file

Posted: Thu Aug 20, 2015 11:59 am
by T-Bone
I'm pretty sure what OP is needing is just require. Say you have a file called "somescript.lua" in the same folder as "main.lua". Then somewhere in main.lua, you can call

Code: Select all

require "somescript"
And it will load and run the other script.

Re: How to run a lua file

Posted: Fri Aug 21, 2015 10:40 pm
by TheJebForge
I want to run other love script. Like options... Or actual game... Sorry for not accurate post.

Re: How to run a lua file

Posted: Sat Aug 22, 2015 12:20 am
by rmcode
Put something like this in a separate file:

Code: Select all

local Foo = {};

function Foo.someFunction()
    ...
end

return Foo;
and then in your main file:

Code: Select all

local Foo = require("Foo");

-- Call function from other module.
Foo.someFunction();
Also if you want to do options and stuff like that you should read about state managing:
https://en.wikipedia.org/wiki/State_management
http://gamedev.stackexchange.com/questi ... screen-etc

You can find some Libraries for LÖVE if you search the wiki and the forums. I usually use my own https://github.com/rm-code/screenmanager for different screens like main menu, game and options.

Re: How to run a lua file

Posted: Sat Aug 22, 2015 9:22 am
by TheJebForge
rmcode wrote:Put something like this in a separate file:

Code: Select all

local Foo = {};

function Foo.someFunction()
    ...
end

return Foo;
and then in your main file:

Code: Select all

local Foo = require("Foo");

-- Call function from other module.
Foo.someFunction();
Also if you want to do options and stuff like that you should read about state managing:
https://en.wikipedia.org/wiki/State_management
http://gamedev.stackexchange.com/questi ... screen-etc

You can find some Libraries for LÖVE if you search the wiki and the forums. I usually use my own https://github.com/rm-code/screenmanager for different screens like main menu, game and options.
Ok, I'll try to do so. thx