How to run a lua file

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
TheJebForge
Prole
Posts: 3
Joined: Wed Aug 19, 2015 9:52 pm

How to run a lua file

Post by TheJebForge »

I was searching it in wiki, but didn't found it. How do I run other lua file?
User avatar
eqnox
Prole
Posts: 44
Joined: Fri Jul 31, 2015 2:36 pm

Re: How to run a lua file

Post 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.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: How to run a lua file

Post 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.
User avatar
NickRock
Citizen
Posts: 76
Joined: Thu Dec 25, 2014 9:33 pm
Location: Earth
Contact:

Re: How to run a lua file

Post 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
Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeooow!!
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: How to run a lua file

Post 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.
TheJebForge
Prole
Posts: 3
Joined: Wed Aug 19, 2015 9:52 pm

Re: How to run a lua file

Post by TheJebForge »

I want to run other love script. Like options... Or actual game... Sorry for not accurate post.
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: How to run a lua file

Post 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.
TheJebForge
Prole
Posts: 3
Joined: Wed Aug 19, 2015 9:52 pm

Re: How to run a lua file

Post 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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], VXDev and 1 guest