Skip to content

Commit

Permalink
* add Lambda module.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.dotswitch.net/var/svn/dotswitch/projects/library/plugins/purl@2122 c432a1ab-ec09-0410-8e5f-fb625be92370
  • Loading branch information
nanki committed Oct 28, 2008
1 parent 792f6e3 commit 3cbdf8d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/purl.rb
Expand Up @@ -10,6 +10,7 @@ def initialize(options = {})
load_feature Features::Arithmetic
load_feature Features::Conversion
load_feature Features::Stack
load_feature Features::Lambda
load_feature Features::Image
load_feature Features::Effect
load_feature Features::Resize
Expand Down
33 changes: 33 additions & 0 deletions lib/purl/features/lambda.rb
@@ -0,0 +1,33 @@
module Purl
module Features::Lambda
class << self
include ::Purl::Features::Limit

def operators
[
Op.new(:call, 1),
Op.new(:times, 2),
Op.new(:each, -1),
]
end

def call(macro)
Result.new(*macro.dispatch)
end

def times(macro, n)
n = [@max_n, n].min
Result.new(*(macro.dispatch * n))
end

def each(*stack)
n = [@max_n, stack.pop].min
macro = stack.pop
op = macro.dispatch

stack.concat stack.slice!(-n, n).map{|v| [v, *op]}.flatten
Result.new(*stack)
end
end
end
end
6 changes: 4 additions & 2 deletions lib/purl/features/limit.rb
Expand Up @@ -2,15 +2,17 @@ module Purl
module Features::Limit
def self.included(base)
base.class_eval do
attr_reader :max_width, :max_height
attr_reader :max_width, :max_height, :max_n
def options=(options)
options = {
:max_width => 1024,
:max_height => 1024
:max_height => 1024,
:max_n => 10,
}.merge(options)

@max_width = options[:max_width]
@max_height = options[:max_height]
@max_n = options[:max_n]
end
end
end
Expand Down

0 comments on commit 3cbdf8d

Please sign in to comment.