Lume & Lurker : Utility functions and auto-hotswapping

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
MGinshe
Prole
Posts: 31
Joined: Sun Apr 17, 2011 3:50 am
Location: New Zealand

Re: Lume & Lurker : Utility functions and auto-hotswapping

Post by MGinshe »

Puzzlem00n wrote: If I put it at the top like that, you mean? It doesn't print any errors, it just plain stops working. I wish I could put it like that so I'd only have to require linen and then the other two would be automatic, but it just doesn't fly, apparently.

1) Yes, it's working now. 2) To be honest, I have no idea, I'm just running under the assumption that it's faster. 3) Not really.
if you never noticed lag spikes/jitters you probably won't see any differences. my laptop sits nicely at 60fps now, instead of dropping to ~30 every time lurker.scan() runs.

also, i'm working on another library that allows auto-reloading of middleclass entities. i'll have a demo up later on :D
User avatar
Positive07
Party member
Posts: 1015
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Lume & Lurker : Utility functions and auto-hotswapping

Post by Positive07 »

love.threaderror can catch thread errors if you need that. But! It is a callback so if the user is using threads and calls that function then it would override yours.

also it would be great if you could reload a thread with lurker/linen/lume... I don't know if that works right now but would be awesome

and the last thing is if you require a file, it is stored in the cache so the next time you require the same file, you don't need to reload it (bartbes said it in some other post)
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
rxi
Prole
Posts: 47
Joined: Sun Mar 02, 2014 10:22 pm

Re: Lume & Lurker : Utility functions and auto-hotswapping

Post by rxi »

Lume updates

Since the last "updates" post: (version 1.2.0 -> 1.4.0)
  • Adds lume.memoize()
  • Adds lume.combine()
  • Adds lume.match()
  • Adds lume.count()
  • Adds lume.uuid()
  • Adds lume.chain()
  • Adds lume.weightedchoice()
  • Changes lume.smooth()'s easing from cosine to cubic
  • lume.combine() now ignores nil arguments
  • lume.trace() now rounds numbers to 2 decimal places
  • lume.fn() now type checks argument
  • Adds proper handling of nil values passed to lume.trace()
  • Changes lume.split() to mimic python's str.split()
  • Fixes negative-index arguments in lume.slice()
  • Fixes error checking of invalid callable arguments which lack metatables
  • Fixes compatibility with Lua5.2 by using table.unpack() when unpack() is not available
  • Fixes use of lua pattern special characters in lume.split() and lume.trim()
  • Minor optimisation to lume.rgba()
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Lume & Lurker : Utility functions and auto-hotswapping

Post by Ref »

Just started looking at lume.
A little late to the party but isn't there an error in lume.each?

Code: Select all

function lume.each(t, fn, ...)
  if type(fn) == "string" then
    for _, v in pairs(t) do v[fn](v, ...) end
  else
    for _, v in pairs(t) do fn(v, ...) end
  end
  return t
end
Shouldn't the code in 'each' be:

Code: Select all

    for k, v in pairs(t) do t[k] = fn(v, ...) end
Could be way off but this works for me.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Lume & Lurker : Utility functions and auto-hotswapping

Post by Roland_Yonaba »

Ref wrote:Just started looking at lume.
A little late to the party but isn't there an error in lume.each?

Code: Select all

function lume.each(t, fn, ...)
  if type(fn) == "string" then
    for _, v in pairs(t) do v[fn](v, ...) end
  else
    for _, v in pairs(t) do fn(v, ...) end
  end
  return t
end
Shouldn't the code in 'each' be:

Code: Select all

    for k, v in pairs(t) do t[k] = fn(v, ...) end
Could be way off but this works for me.
Actually, I'd go for the Great rxi's implementation. I am no reference here, but as far as I could notice, each iterator is a common pattern in functionnal programming. And most of the time, the purpose is to apply a tranformation function on every element in a given collection (here, the table t).

What you proposed, Great Ref, behaves similarly to another common pattern in functional programming, which is called "mapping". The main difference between "map" and "each" is that map collects the result of each function call on every single argument of the original collection, and creates a new collection which is returned at the end. In your implementation, the new ollection is just overwritten over the original one. ;)

I have similar patterns implemented in moses.lua: see (_.each and _.map)
rxi
Prole
Posts: 47
Joined: Sun Mar 02, 2014 10:22 pm

Re: Lume & Lurker : Utility functions and auto-hotswapping

Post by rxi »

Ref wrote:Just started looking at lume.
A little late to the party but isn't there an error in lume.each?
[...]
Shouldn't the code in 'each' be:

Code: Select all

    for k, v in pairs(t) do t[k] = fn(v, ...) end
Could be way off but this works for me.
You may want to take another look at lume.each()'s section in the README.md.

What you described was closer to lume.map(), though map creates a new table rather than changing the table in place.

Edit: Looks like Roland_Yonaba snook in a response while I was writing mine! Hopefully it all makes double sense now.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Lume & Lurker : Utility functions and auto-hotswapping

Post by Ref »

Well aware of the difference between 'each' and 'map'.
My only point is that:

Code: Select all

function move(x,a,b) return a*x+b end
t={1,2,3}
tb=lume.each(t, move, 10, 20)
for i=1,#tb do print(tb[i]) end
does nothing as 'each' only returns the original, unmodified table.

Edit: Appears that I'm trying to use 'each' in a way that it was not intended. Looks like 'each' is just a way to feed parameters into a function, not to modify the contents of a table - My Bad!
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Lume & Lurker : Utility functions and auto-hotswapping

Post by bartbes »

Ref wrote:Well aware of the difference between 'each' and 'map'.
[snip]
Edit: Appears that I'm trying to use 'each' in a way that it was not intended. Looks like 'each' is just a way to feed parameters into a function, not to modify the contents of a table - My Bad!
But that is the difference between each and map!
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Lume & Lurker : Utility functions and auto-hotswapping

Post by Kasperelo »

More people need to know about this! It's so useful!
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Google [Bot] and 4 guests