LOAD EXTERNAL LUA FILE (Solved!)

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
Darlex
Party member
Posts: 128
Joined: Sun Sep 24, 2017 10:02 am
Location: Chile
Contact:

LOAD EXTERNAL LUA FILE (Solved!)

Post by Darlex »

Example: If i have "something.lua" in C:\things\
How i can load it?
Last edited by Darlex on Mon Jan 07, 2019 8:52 pm, edited 2 times in total.
Hi! I wish you have an amazing day!
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: How i can load some external lua file?

Post by ivan »

Your game shouldn't load code from arbitrary locations - it's NOT safe to do that.
Furthermore "C:/" doesn't mean anything across other platforms like Linux and Android. You want your game to be cross platform, right?
Custom files could be loaded from the "AppData" folder but even that has to be done cautiously, preferably using sandboxing/setenv.
There may be workarounds and hacks, but generally speaking you want to keep your source code inside your game folder.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: How i can load some external lua file?

Post by pgimeno »

Ivan is right, but there are use cases for loading a Lua file from an arbitrary location. dofile("c:/things/something.lua") will load it, but note that if you execute it multiple times, it will be loaded multiple times. That's a difference with require(), which only loads it once.
User avatar
D0NM
Party member
Posts: 250
Joined: Mon Feb 08, 2016 10:35 am
Location: Zabuyaki
Contact:

Re: How i can load some external lua file?

Post by D0NM »

Darlex wrote: Fri Oct 26, 2018 1:00 am Example: If i have "something.lua" in C:\things\
How i can load it?
use this function
https://love2d.org/wiki/love.filesystem.load
Our LÖVE Gamedev blog Zabuyaki (an open source retro beat 'em up game). Twitter: @Zabuyaki.
:joker: LÖVE & Lua Video Lessons in Russian / Видео уроки по LÖVE и Lua :joker:
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: How i can load some external lua file?

Post by milon »

If you do want to learn the require function, see my post here:
viewtopic.php?f=3&t=85741#p223173
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Darlex
Party member
Posts: 128
Joined: Sun Sep 24, 2017 10:02 am
Location: Chile
Contact:

Re: [SOLVED]

Post by Darlex »

Thanks!
Hi! I wish you have an amazing day!
User avatar
Stifu
Party member
Posts: 106
Joined: Mon Mar 14, 2016 9:53 am
Contact:

Re: [SOLVED]

Post by Stifu »

Please don't delete your posts... They can be useful to other people later.
Zabuyaki, our upcoming beat 'em up: https://www.zabuyaki.com
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 48 guests