Is it possible to load a Lua file, and execute it in a safe environment where an error would not cause the main Löve instance to crash?
For example you have a file behavior.lua, you run your main Löve program, edit behavior.lua, hit a button to reload the file, and see changes in the game.
Is this possible?
Load lua code dynamically, safely
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- dreadkillz
- Party member
- Posts: 223
- Joined: Sun Mar 04, 2012 2:04 pm
- Location: USA
Re: Load lua code dynamically, safely
You can run coroutines like that. Any error in a coroutine will return it to the resume call.
http://www.lua.org/pil/9.1.html
EDIT: I forgot about the debug library. Try using that as I believe there's support for protected calls.
EDIT2: Silly me, see pcall in the PiL: http://www.lua.org/pil/8.4.html
http://www.lua.org/pil/9.1.html
Code: Select all
t = coroutine.create(function () return nil + 1 end)
print(coroutine.resume(t)) --> false, "error message"
EDIT2: Silly me, see pcall in the PiL: http://www.lua.org/pil/8.4.html
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Load lua code dynamically, safely
You want pcall, possibly in combination with setfenv.
Who is online
Users browsing this forum: No registered users and 63 guests