[SOLVED] Executing Lua code from external file in LÖVE?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED] Executing Lua code from external file in LÖVE?
So, I've made a small let's say "boilerplate" in LÖVE with variables, custom screen buffer and custom screen buffer functions. The question is, is it possible to like drag n drop a file into the executable and have the main application execute it like emulator a rom? Will it be still possible to access the functions and screen buffer? If so, how.
Last edited by Flamore on Thu Mar 19, 2020 5:48 pm, edited 1 time in total.
Re: Executing Lua code from external file in LÖVE?
This page shows several methods:
https://www.lua.org/pil/8.html
"dofile" will execute the file right away
"loadfile" will load it and hand you a function that you can call
"loadstring" does the trick if you have the code as text and not as file
Edit: Accessing global variables should work.
https://www.lua.org/pil/8.html
"dofile" will execute the file right away
"loadfile" will load it and hand you a function that you can call
"loadstring" does the trick if you have the code as text and not as file
Edit: Accessing global variables should work.
In soviet russia, code debugs you.
- zorg
- Party member
- Posts: 3470
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Executing Lua code from external file in LÖVE?
And on the löve side, it does have the love.filedropped callback if you rather drop a file onto the already running löve project's window.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Executing Lua code from external file in LÖVE?
Alright, gonna try these methods. Also i have heard that dofile isn't secure, is it just like some bias or something
- zorg
- Party member
- Posts: 3470
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Executing Lua code from external file in LÖVE?
technically, none of those are... but that depends on what you think "secure" is.
by the way, if you are using löve, two of those functions have "better" löve equivalents:
love.filesystem.load instead of loadfile;
dofile is basically the above, with an extra () at the end;
(better in terms of they will work even if you zip up your project into a .love file)
by the way, if you are using löve, two of those functions have "better" löve equivalents:
love.filesystem.load instead of loadfile;
dofile is basically the above, with an extra () at the end;
(better in terms of they will work even if you zip up your project into a .love file)
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Executing Lua code from external file in LÖVE?
I just wrote a simple function
But yeth dofile() does not support FileData just strings. Giving this error below.
Code: Select all
function love.filedropped(file)
local ext
ext = file:getExtension( )
if ext == "cart" then
dofile(file)
else
print("Filetype not supported")
end
end
Code: Select all
Error: main.lua:240: bad argument #1 to 'dofile' (string expected, got userdata)
stack traceback:
[string "boot.lua"]:637: in function <[string "boot.lua"]:633>
[C]: in function 'dofile'
main.lua:240: in function <main.lua:236>
[string "boot.lua"]:503: in function <[string "boot.lua"]:493>
[C]: in function 'xpcall'
Re: Executing Lua code from external file in LÖVE?
Try with dofile(file:getFilename())
Re: Executing Lua code from external file in LÖVE?
You can restart with love.event.quit("restart")
Who is online
Users browsing this forum: Google [Bot] and 3 guests