Lume & Lurker : Utility functions and auto-hotswapping

Showcase your libraries, tools and other projects that help your fellow love users.
rxi
Prole
Posts: 47
Joined: Sun Mar 02, 2014 10:22 pm

Lume & Lurker : Utility functions and auto-hotswapping

Post by rxi »

Lume is a library containing a collection of functions geared towards game development. Check out the Readme file for a list of what it includes.
I've also written a small module named lurker which makes use of the lume.hotswap() function. The module detects changes in lua files in the project's directory and automatically calls the hotswap function on changed files. I've uploaded a video which shows it in action.

Both should be compatible with LÖVE 0.8.0 and 0.9.0.

Let me know what you think and if you find any issues.
Last edited by rxi on Fri Mar 07, 2014 1:41 pm, edited 1 time in total.
User avatar
adnzzzzZ
Party member
Posts: 305
Joined: Sun Dec 26, 2010 11:04 pm
Location: Porto Alegre, Brazil

Re: Lume : A Collection of functions geared towards gamedev

Post by adnzzzzZ »

This is extremely useful (lurker). It works perfectly on my somewhat complex project, although I'll have to do a bit of extra work to change values of already spawned objects, but I think it's worth it!

Image
Zarty55
Citizen
Posts: 79
Joined: Thu Jul 25, 2013 2:36 am

Re: Lume : A Collection of functions geared towards gamedev

Post by Zarty55 »

Just looked the functions, seems pretty nice. I'll probably add to my game, and still have to test the lurker thing, looks awesome! :D
User avatar
Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

Re: Lume : A Collection of functions geared towards gamedev

Post by Helvecta »

hotswapping, where have you been all of my life.

Thanks for sharing with us Rxi, very nice! :D
rxi
Prole
Posts: 47
Joined: Sun Mar 02, 2014 10:22 pm

Re: Lume : A Collection of functions geared towards gamedev

Post by rxi »

@adnzzzzZ

Really nice to see it in someone else's project (on a different platform, too)! Though my little demo video just focused on the love.update() function, I did write the lume.hotswap() function with larger projects in mind; I tested it on a couple of the proper-sized LÖVE projects and didn't find a case where it wouldn't work as expected. As far as I know no one has written hotswapping for Lua this way before.

That being said it won't work out well in some cases, but those cases tend to be things like image cache modules which reset their cache when they're reloaded. This didn't seem like much of a problem, as it would be unlikely that you would ever want to hotswap something like an image cache.

@Zarty55 @Helvecta

Let me know how you get along with it if you try it out!
Zarty55
Citizen
Posts: 79
Joined: Thu Jul 25, 2013 2:36 am

Re: Lume : A Collection of functions geared towards gamedev

Post by Zarty55 »

Wow! The lurker is REALLY awesome. I have maded changes in my code and it didn't even restarted the game, that thing is just... Wow! It's freaking awesome!

One thing that would be nice, is that it could have a "catchChange" and "applyChange". Then we could detect changes inside love.errhand and restart the game when there's a change in the code.

Also, I tend to save my code a lot, even when it's not necessary (Like I'm halfway typing a function and I save) maybe it could detect typing errors and wait to apply the changes? Oh man, this is so awesome!

I had some ideas for lume, but I forgot them haha. When I remember I will surely post them here!

Edit: A callback when lurker change things would be nice too, so we could reset window state when the conf.lua or the love.load(Which in some cases wouldn't be a good idea really) changes.

I'm just really excited at this, sorry for throwing things at you like this.

Edit2: I just realized there's more stuff in the github... Oh god, this is embarrasing hahaha :p

Edit3: Sorry... Again ._.' Saw that everything I suggested is already implemented.
rxi
Prole
Posts: 47
Joined: Sun Mar 02, 2014 10:22 pm

Re: Lume : A Collection of functions geared towards gamedev

Post by rxi »

Haha, I'm liking the enthusiasm @Zarty55.
Zarty55 wrote:One thing that would be nice, is that it could have a "catchChange" and "applyChange". Then we could detect changes inside love.errhand and restart the game when there's a change in the code.
Could you try and expand on what you meant by this? Lume already aborts gracefully if you accidentally code an error (and lurker prints out that the hotswap failed to the console), but this only works for syntax errors. Any mistakes that can't be detected when the file is loaded -- such as indexing a nil value in a function that hasn't been called yet -- raises an error when the function is called. I assume you're suggesting a work around using love.errhand for this? I haven't had a chance to play with love.errhand yet. Additionally, I'm unsure how it might work, for example, once love.errhand has been called I don't believe there would be a way of jumping back to the point where the error was raised, and so at best all it could do is restart the program -- this is basically what you are forced to do as it is. Do let me know if I am mistaken, though, as a solution besides being a bit careful would be nice!
Zarty55 wrote:A callback when lurker change things would be nice too, so we could reset window state when the conf.lua or the love.load(Which in some cases wouldn't be a good idea really) changes.
That's what the lurker.preswap and lurker.postswap callback functions are for, I'm not sure if your second edit meant you already spotted them or not. For window-state changes which would require love.load() to be called again, the game would be restarted anyway, in which case closing and opening the game isn't much different to that.

Edit: You made your 3rd edit while I was typing my reply, so I'm not sure if any of it is relevant now.
User avatar
adnzzzzZ
Party member
Posts: 305
Joined: Sun Dec 26, 2010 11:04 pm
Location: Porto Alegre, Brazil

Re: Lume : A Collection of functions geared towards gamedev

Post by adnzzzzZ »

Did you take a look at the way Cupid (https://love2d.org/wiki/Cupid) handles errors? I don't understand anything about what's going on under the hood in either Cupid or your library, but in Cupid the error handling is done pretty nicely I think.
Zarty55
Citizen
Posts: 79
Joined: Thu Jul 25, 2013 2:36 am

Re: Lume : A Collection of functions geared towards gamedev

Post by Zarty55 »

rxi wrote:-snip-
I did spot it haha.

I was just trying to more lazy than I am by trying to make the game to reopen itself when there's a error and something changed... For that I would just copy the current love.errhand and add that part in the "while true..." in the end. Even though I don't know if it would work, that's a whole new level of lazyness for me hahaha :p

Now that I took a better look at it I already saw that almost everything is in lurker. But still, would be nice to detect changes in the environment without changing anything.

Oh, playing a little bit with lurker.postswap I've noticed a kinda strange behavior. When I change lurker.postswap and lurker reloads(The game, not that I changed it inside the lurker.lua), it calls a old version of the postswap function. Any workaround to this?
rxi
Prole
Posts: 47
Joined: Sun Mar 02, 2014 10:22 pm

Re: Lume : A Collection of functions geared towards gamedev

Post by rxi »

adnzzzzZ wrote:Did you take a look at the way Cupid (https://love2d.org/wiki/Cupid) handles errors? I don't understand anything about what's going on under the hood in either Cupid or your library, but in Cupid the error handling is done pretty nicely I think.
Ah, just had a peek at it. It looks like it's wrapping the love callback functions with it's own, then calling whatever the love functions were in protected mode so that it can catch any raise errors -- this becomes a bit more difficult when hotswapping is involved, as if you hotswap a module that sets the callback function (like setting love.update() in main.lua, and hotswapping main.lua) it would overwrite the wrapping.

This doesn't mean it is impossible -- in fact, it just occurred to me I could check the wrapped functions and re-wrap them if they've been overwritten every time a hotswap occurs. I'll still have to give this a bit more thought and let it float around in my mind a bit before I have a go at implementing it, but I can't off the top of my head see any major issues that would occur with this.
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests