A Fuse Powered Company

Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

[Lib/Lua] Moses (1.4.0)
Started by roland.yonaba Jul 14 2014 10:27 AM

* * * * * 2 votes
5 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

roland.yonaba

[GLOBAL: userInfoPane.html]
roland.yonaba
  • Starter
  • PipPipPipPipPipPip
  • 60 posts
  • Jedi

Hi all,

Moses bumped to version 1.4.0.
Moses is a Lua library mostly meant for functional programming, with Lua. It provides functions to operates on tables array-style, list-style, collection-style or object-style.

Here are some examples:

local _ = require 'moses'

-- Creates an array of values from 1 to 20
local t = _.range(1,20)

-- Filter even values
t = _.select(t, function(i,v) return v%2~=0 end)

-- Double all values
t = _.map(t, function(i,v) return v*2 end)

The code below does the exact same thing, but uses chaining:
 

local _ = require 'moses'
local t = _:chain(_.range(1,20))
  :select(function(i,v) return v%2~=0 end)
  :map(function(i,v) return v*2 end)
  :value()

Or let us consider a dataset of records:

local logs = {
  {name = 'Allan', timestamp = 00578},  {name = 'John', timestamp = 20578},
  {name = 'Ronald', timestamp = 00579}, {name = 'Ronald', timestamp = 30578},
  {name = 'John', timestamp = 0057},    {name = 'Allan', timestamp = 0678},
  {name = 'Allan', timestamp = 00278},  {name = 'Peter', timestamp = 06578},
  {name = 'Peter', timestamp = 30578},  {name = 'Allan', timestamp = 0878},
  {name = 'Steve', timestamp = 50578},  {name = 'John', timestamp = 078},
}

We want to find out how many times <em>Allan</em> got connected:

print(_.count(_.pluck(logs, 'name'), 'Allan')) --> 4

Or find out the max timestamp:

print(_.max(_.pluck(logs, 'timestamp'))) --> 578

Or get the list of the unique visitors to the database:
 

_.each(_.unique(_.pluck(logs, 'name')),print) --> 'Allan', 'John', 'Ronald', 'Peter', 'Steve'

or the same list, chaining style:

_(logs):pluck('name'):unique():each(print) --> 'Allan', 'John', 'Ronald', 'Peter', 'Steve'

Find a complete tutorial here on Moses' API. The documentation is also available online, on in HTML format bundled with the library.

Moses 1.4.0: source | Github | Url



[TOPIC: post.html]
#2

hgbrian

[GLOBAL: userInfoPane.html]
hgbrian
  • Pro
  • PipPipPipPipPipPip
  • 94 posts
  • Jedi

I use Moses a lot. It makes lua much more usable. It's great!



[TOPIC: post.html]
#3

roland.yonaba

[GLOBAL: userInfoPane.html]
roland.yonaba
  • Starter
  • PipPipPipPipPipPip
  • 60 posts
  • Jedi

I use Moses a lot. It makes lua much more usable. It's great!

 

Thanks for the kind words :)



[TOPIC: post.html]
#4

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Pro
  • PipPipPipPipPipPip
  • 992 posts
  • Jedi

Looks great, wish I had known about this sooner.



[TOPIC: post.html]
#5

r.delia

[GLOBAL: userInfoPane.html]
r.delia
  • Pro
  • PipPipPipPipPipPip
  • 129 posts
  • Jedi

This is just awesome! 

 

I've been playing with some 2.5d perspective stuff, and got to a point where I was trying to rotate plane (forest for now) around its Y axis.  This would look ok for 1/2 the rotation, but the trees would overlap at some points, ruining the 3d illusion:

 

 

I needed a way to sort my table of objects by using a value that was buried in the objects structure: Object.vector.z

 

...and then with this moses piece:

  _.each(_.sort(renderObjects.collection,
    function(a,b )
        if a.vector and b.vector then
           local testA,testB = a.vector.z,  b.vector.z
            return testA > testB
        else
            return true
        end
        
    end) ,
    function(i,v)
        
        if v.DO then
          --      print(i,renderObjects.distanceToCamera(v), v.vector.x,v.vector.y,v.vector.z)                    
            render(v)
            v.DG:toFront()
        end
        
    end )

 

I was able to make a custom table sorting function that uses the table object's z vectors  to compare the items in the table.

 

The following results:

 

 

Magic, I tell you......

 

Thanks again, Roland,  This , and your Jumper code are truly excellent . I really appreciate the quality of your work, and the attention to detail



[TOPIC: post.html]
#6

roland.yonaba

[GLOBAL: userInfoPane.html]
roland.yonaba
  • Starter
  • PipPipPipPipPipPip
  • 60 posts
  • Jedi

@rdelia : Thanks for the kind words. I spent some time watching those videos. Nice work indeed. :)




[topic_controls]
[/topic_controls]