Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
specials
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
JoyJ
specials
Commits
41286f6c
Commit
41286f6c
authored
Jan 31, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new
parent
7653ed75
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
673 additions
and
0 deletions
+673
-0
legend/c94016752.lua
legend/c94016752.lua
+54
-0
legend/special.lua
legend/special.lua
+195
-0
legend/underscore.lua
legend/underscore.lua
+424
-0
No files found.
legend/c94016752.lua
0 → 100644
View file @
41286f6c
--深淵の宣告者
function
c94016752
.
initial_effect
(
c
)
--Activate
local
e1
=
Effect
.
CreateEffect
(
c
)
e1
:
SetCategory
(
CATEGORY_TOGRAVE
)
e1
:
SetType
(
EFFECT_TYPE_ACTIVATE
)
e1
:
SetCode
(
EVENT_FREE_CHAIN
)
e1
:
SetCountLimit
(
1
,
94016752
+
EFFECT_COUNT_CODE_OATH
)
e1
:
SetCost
(
c94016752
.
cost
)
e1
:
SetTarget
(
c94016752
.
target
)
e1
:
SetOperation
(
c94016752
.
activate
)
c
:
RegisterEffect
(
e1
)
end
function
c94016752
.
cost
(
e
,
tp
,
eg
,
ep
,
ev
,
re
,
r
,
rp
,
chk
)
if
chk
==
0
then
return
Duel
.
CheckLPCost
(
tp
,
1500
)
end
Duel
.
PayLPCost
(
tp
,
1500
)
end
function
c94016752
.
target
(
e
,
tp
,
eg
,
ep
,
ev
,
re
,
r
,
rp
,
chk
)
if
chk
==
0
then
return
Duel
.
GetTurnCount
()
>
1
end
Duel
.
Hint
(
HINT_SELECTMSG
,
tp
,
HINTMSG_ATTRIBUTE
)
local
att
=
Duel
.
AnnounceAttribute
(
tp
,
1
,
0xff
)
Duel
.
Hint
(
HINT_SELECTMSG
,
tp
,
HINTMSG_RACE
)
local
rc
=
Duel
.
AnnounceRace
(
tp
,
1
,
RACE_ALL
)
e
:
SetLabel
(
att
)
Duel
.
SetTargetParam
(
rc
)
end
function
c94016752
.
tgfilter
(
c
,
rc
,
att
)
return
c
:
IsFaceup
()
and
c
:
IsRace
(
rc
)
and
c
:
IsAttribute
(
att
)
and
c
:
IsAbleToGrave
()
end
function
c94016752
.
activate
(
e
,
tp
,
eg
,
ep
,
ev
,
re
,
r
,
rp
)
local
att
=
e
:
GetLabel
()
local
rc
=
Duel
.
GetChainInfo
(
0
,
CHAININFO_TARGET_PARAM
)
local
g
=
Duel
.
GetMatchingGroup
(
c94016752
.
tgfilter
,
1
-
tp
,
LOCATION_MZONE
,
0
,
nil
,
rc
,
att
)
if
g
:
GetCount
()
>
0
then
Duel
.
Hint
(
HINT_SELECTMSG
,
1
-
tp
,
HINTMSG_TOGRAVE
)
local
sg
=
g
:
Select
(
1
-
tp
,
1
,
1
,
nil
)
Duel
.
HintSelection
(
sg
)
local
code
=
sg
:
GetFirst
():
GetCode
()
if
Duel
.
SendtoGrave
(
sg
,
REASON_RULE
)
~=
0
then
local
e1
=
Effect
.
CreateEffect
(
e
:
GetHandler
())
e1
:
SetType
(
EFFECT_TYPE_FIELD
)
e1
:
SetProperty
(
EFFECT_FLAG_PLAYER_TARGET
)
e1
:
SetCode
(
EFFECT_CANNOT_ACTIVATE
)
e1
:
SetTargetRange
(
0
,
1
)
e1
:
SetValue
(
c94016752
.
aclimit
)
e1
:
SetLabel
(
code
)
e1
:
SetReset
(
RESET_PHASE
+
PHASE_END
)
Duel
.
RegisterEffect
(
e1
,
tp
)
end
end
end
function
c94016752
.
aclimit
(
e
,
re
,
tp
)
return
re
:
GetHandler
():
IsCode
(
e
:
GetLabel
())
and
re
:
IsActiveType
(
TYPE_MONSTER
)
end
legend/special.lua
0 → 100644
View file @
41286f6c
Duel
.
LoadScript
(
"underscore.lua"
)
function
validMonster
(
c
)
return
c
:
IsType
(
TYPE_MONSTER
)
end
local
AllHints
=
{
70
,
-- monster immune
Auxiliary
.
Stringid
(
88616795
,
0
),
-- spell immune
Auxiliary
.
Stringid
(
88616795
,
1
),
-- trap immune
Auxiliary
.
Stringid
(
33883834
,
0
),
-- battle destroy
Auxiliary
.
Stringid
(
45420955
,
3
),
-- effect destroy
1102
,
-- banish/hand/deck
Auxiliary
.
Stringid
(
45420955
,
4
),
-- target
Auxiliary
.
Stringid
(
74640994
,
3
),
-- cannot disable
Auxiliary
.
Stringid
(
900787
,
0
),
-- atk/def up
}
local
buffEffectsList
=
{
{
{
code
=
EFFECT_IMMUNE_EFFECT
,
value
=
function
(
e
,
te
)
return
te
:
GetOwner
()
~=
e
:
GetOwner
()
and
te
:
IsActiveType
(
TYPE_MONSTER
)
end
,
}
},
{
{
code
=
EFFECT_IMMUNE_EFFECT
,
value
=
function
(
e
,
te
)
return
te
:
GetOwner
()
~=
e
:
GetOwner
()
and
te
:
IsActiveType
(
TYPE_SPELL
)
end
,
}
},
{
{
code
=
EFFECT_IMMUNE_EFFECT
,
value
=
function
(
e
,
te
)
return
te
:
GetOwner
()
~=
e
:
GetOwner
()
and
te
:
IsActiveType
(
TYPE_TRAP
)
end
,
}
},
{
{
code
=
EFFECT_INDESTRUCTABLE_BATTLE
,
value
=
1
,
}
},
{
{
code
=
EFFECT_INDESTRUCTABLE_EFFECT
,
value
=
1
,
}
},
{
{
code
=
EFFECT_CANNOT_REMOVE
,
value
=
1
,
},
{
code
=
EFFECT_CANNOT_TO_DECK
,
value
=
1
,
},
{
code
=
EFFECT_CANNOT_TO_HAND
,
value
=
1
,
},
},
{
{
code
=
EFFECT_CANNOT_BE_EFFECT_TARGET
,
value
=
1
,
}
},
{
{
code
=
EFFECT_CANNOT_DISABLE
,
value
=
1
,
}
},
{
{
code
=
EFFECT_SET_BASE_ATTACK
,
value
=
function
(
e
,
c
)
return
math.max
(
c
:
GetTextAttack
(),
0
)
+
2000
end
,
},
{
code
=
EFFECT_SET_BASE_DEFENSE
,
value
=
function
(
e
,
c
)
return
math.max
(
c
:
GetTextDefense
(),
0
)
+
2000
end
,
}
},
}
function
isPlayerMissedOwner
(
p
)
return
not
Duel
.
IsPlayerAffectedByEffect
(
tp
,
10000020
+
p
)
end
function
inititialize
()
local
choices
=
{}
local
monsters
=
{}
local
buffOptions
=
{}
for
p
=
0
,
1
do
monsters
[
p
]
=
Duel
.
GetMatchingGroup
(
validMonster
,
p
,
LOCATION_DECK
,
0
,
1
,
nil
)
end
if
_
.
every
({
monsters
[
0
],
monsters
[
1
]},
function
(
g
)
return
#
g
==
0
end
)
then
Duel
.
Win
(
PLAYER_NONE
,
0x2
)
return
end
for
p
=
0
,
1
do
local
g
=
monsters
[
p
]
if
#
g
==
0
then
Duel
.
Win
(
1
-
p
,
0x2
)
end
end
for
p
=
0
,
1
do
Duel
.
Hint
(
MSG_HINT
,
p
,
HINTMSG_TOFIELD
)
choices
[
p
]
=
monsters
[
p
]:
Select
(
p
,
1
,
1
,
nil
):
GetFirst
()
buffOptions
[
p
]
=
Duel
.
SelectOption
(
p
,
table.unpack
(
AllHints
))
+
1
end
for
p
=
0
,
1
do
local
c
=
choices
[
p
]
local
pos
=
Duel
.
SelectPosition
(
p
,
c
,
POS_FACEUP
)
Duel
.
MoveToField
(
c
,
p
,
p
,
LOCATION_MZONE
,
pos
,
true
)
local
e1
=
Effect
.
CreateEffect
(
c
)
e1
:
SetType
(
EFFECT_TYPE_FIELD
)
e1
:
SetCode
(
10000020
+
p
)
e1
:
SetProperty
(
EFFECT_FLAG_SET_AVAILABLE
+
EFFECT_FLAG_CLIENT_HINT
+
EFFECT_FLAG_CANNOT_DISABLE
+
EFFECT_FLAG_PLAYER_TARGET
+
EFFECT_FLAG_IGNORE_IMMUNE
)
e1
:
SetRange
(
LOCATION_ONFIELD
)
e1
:
SetTargetRange
(
1
,
1
)
e1
:
SetDescription
(
1016
)
c
:
RegisterEffect
(
e1
,
true
)
local
presetEffects
=
{
EFFECT_UNRELEASABLE_EFFECT
,
EFFECT_UNRELEASABLE_NONSUM
,
EFFECT_UNRELEASABLE_SUM
,
EFFECT_CANNOT_BE_FUSION_MATERIAL
,
EFFECT_CANNOT_BE_SYNCHRO_MATERIAL
,
EFFECT_CANNOT_BE_XYZ_MATERIAL
,
EFFECT_CANNOT_BE_LINK_MATERIAL
}
for
_
,
effectCode
in
ipairs
(
presetEffects
)
do
local
e1
=
Effect
.
CreateEffect
(
c
)
e1
:
SetType
(
EFFECT_TYPE_SINGLE
)
e1
:
SetCode
(
effectCode
)
e1
:
SetProperty
(
EFFECT_FLAG_SET_AVAILABLE
+
EFFECT_FLAG_CANNOT_DISABLE
+
EFFECT_FLAG_IGNORE_IMMUNE
)
e1
:
SetValue
(
1
)
c
:
RegisterEffect
(
e1
,
true
)
end
local
buffOption
=
buffOptions
[
p
]
--Debug.Message(buffOption)
local
buffEffects
=
buffEffectsList
[
buffOption
]
--Debug.Message(type(buffEffects))
local
hintGiven
=
false
for
_
,
buffEffect
in
ipairs
(
buffEffects
)
do
local
flags
=
EFFECT_FLAG_SET_AVAILABLE
+
EFFECT_FLAG_CANNOT_DISABLE
if
not
hintGiven
then
flags
=
flags
+
EFFECT_FLAG_CLIENT_HINT
end
local
e1
=
Effect
.
CreateEffect
(
c
)
e1
:
SetDescription
(
AllHints
[
buffOption
])
e1
:
SetType
(
EFFECT_TYPE_SINGLE
)
e1
:
SetCode
(
buffEffect
.
code
)
e1
:
SetProperty
(
flags
)
e1
:
SetValue
(
buffEffect
.
value
)
c
:
RegisterEffect
(
e1
,
true
)
end
end
local
e1
=
Effect
.
GlobalEffect
()
e1
:
SetType
(
EFFECT_TYPE_FIELD
+
EFFECT_TYPE_CONTINUOUS
)
e1
:
SetProperty
(
EFFECT_FLAG_IGNORE_IMMUNE
)
e1
:
SetCode
(
EVENT_ADJUST
)
e1
:
SetOperation
(
function
()
if
isPlayerMissedOwner
(
0
)
and
isPlayerMissedOwner
(
1
)
then
Duel
.
Win
(
PLAYER_NONE
,
0x13
)
return
end
for
p
=
0
,
1
do
if
isPlayerMissedOwner
(
p
)
then
Duel
.
Win
(
1
-
p
,
0x13
)
return
end
end
end
)
Duel
.
RegisterEffect
(
e1
,
0
)
end
function
Auxiliary
.
PreloadUds
()
local
e1
=
Effect
.
GlobalEffect
()
e1
:
SetType
(
EFFECT_TYPE_FIELD
+
EFFECT_TYPE_CONTINUOUS
)
e1
:
SetProperty
(
EFFECT_FLAG_IGNORE_IMMUNE
)
e1
:
SetCode
(
EVENT_ADJUST
)
e1
:
SetOperation
(
function
(
e
)
inititialize
()
e
:
Reset
()
end
)
Duel
.
RegisterEffect
(
e1
,
0
)
end
legend/underscore.lua
0 → 100644
View file @
41286f6c
-- Copyright (c) 2009 Marcus Irven
--
-- Permission is hereby granted, free of charge, to any person
-- obtaining a copy of this software and associated documentation
-- files (the "Software"), to deal in the Software without
-- restriction, including without limitation the rights to use,
-- copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following
-- conditions:
--
-- The above copyright notice and this permission notice shall be
-- included in all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-- OTHER DEALINGS IN THE SOFTWARE.
--- Underscore is a set of utility functions for dealing with
-- iterators, arrays, tables, and functions.
local
Underscore
=
{
funcs
=
{}
}
Underscore
.
__index
=
Underscore
function
Underscore
.
__call
(
_
,
value
)
return
Underscore
:
new
(
value
)
end
function
Underscore
:
new
(
value
,
chained
)
return
setmetatable
({
_val
=
value
,
chained
=
chained
or
false
},
self
)
end
function
Underscore
.
iter
(
list_or_iter
)
if
type
(
list_or_iter
)
==
"function"
then
return
list_or_iter
end
local
i
=
0
return
function
()
i
=
i
+
1
return
list_or_iter
[
i
]
end
end
function
Underscore
.
range
(
start_i
,
end_i
,
step
)
if
end_i
==
nil
then
end_i
=
start_i
start_i
=
1
end
step
=
step
or
1
local
list
=
{}
for
i
=
start_i
,
end_i
,
step
do
table.insert
(
list
,
i
)
end
local
range_iter
=
Underscore
.
iter
(
list
)
return
Underscore
:
new
(
range_iter
)
end
--- Identity function. This function looks useless, but is used throughout Underscore as a default.
-- @name _.identity
-- @param value any object
-- @return value
-- @usage _.identity("foo")
-- => "foo"
function
Underscore
.
identity
(
value
)
return
value
end
-- chaining
function
Underscore
:
chain
()
self
.
chained
=
true
return
self
end
function
Underscore
:
value
()
return
self
.
_val
end
-- iter
function
Underscore
.
funcs
.
each
(
list
,
func
)
for
i
in
Underscore
.
iter
(
list
)
do
func
(
i
)
end
return
list
end
function
Underscore
.
funcs
.
map
(
list
,
func
)
local
mapped
=
{}
for
i
in
Underscore
.
iter
(
list
)
do
mapped
[
#
mapped
+
1
]
=
func
(
i
)
end
return
mapped
end
function
Underscore
.
funcs
.
reduce
(
list
,
memo
,
func
)
for
i
in
Underscore
.
iter
(
list
)
do
memo
=
func
(
memo
,
i
)
end
return
memo
end
function
Underscore
.
funcs
.
detect
(
list
,
func
)
for
i
in
Underscore
.
iter
(
list
)
do
if
func
(
i
)
then
return
i
end
end
return
nil
end
function
Underscore
.
funcs
.
select
(
list
,
func
)
local
selected
=
{}
for
i
in
Underscore
.
iter
(
list
)
do
if
func
(
i
)
then
selected
[
#
selected
+
1
]
=
i
end
end
return
selected
end
function
Underscore
.
funcs
.
reject
(
list
,
func
)
local
selected
=
{}
for
i
in
Underscore
.
iter
(
list
)
do
if
not
func
(
i
)
then
selected
[
#
selected
+
1
]
=
i
end
end
return
selected
end
function
Underscore
.
funcs
.
all
(
list
,
func
)
func
=
func
or
Underscore
.
identity
-- TODO what should happen with an empty list?
for
i
in
Underscore
.
iter
(
list
)
do
if
not
func
(
i
)
then
return
false
end
end
return
true
end
function
Underscore
.
funcs
.
any
(
list
,
func
)
func
=
func
or
Underscore
.
identity
-- TODO what should happen with an empty list?
for
i
in
Underscore
.
iter
(
list
)
do
if
func
(
i
)
then
return
true
end
end
return
false
end
function
Underscore
.
funcs
.
include
(
list
,
value
)
for
i
in
Underscore
.
iter
(
list
)
do
if
i
==
value
then
return
true
end
end
return
false
end
function
Underscore
.
funcs
.
invoke
(
list
,
function_name
,
...
)
local
args
=
{
...
}
Underscore
.
funcs
.
each
(
list
,
function
(
i
)
i
[
function_name
](
i
,
unpack
(
args
))
end
)
return
list
end
function
Underscore
.
funcs
.
pluck
(
list
,
propertyName
)
return
Underscore
.
funcs
.
map
(
list
,
function
(
i
)
return
i
[
propertyName
]
end
)
end
function
Underscore
.
funcs
.
min
(
list
,
func
)
func
=
func
or
Underscore
.
identity
return
Underscore
.
funcs
.
reduce
(
list
,
{
item
=
nil
,
value
=
nil
},
function
(
min
,
item
)
if
min
.
item
==
nil
then
min
.
item
=
item
min
.
value
=
func
(
item
)
else
local
value
=
func
(
item
)
if
value
<
min
.
value
then
min
.
item
=
item
min
.
value
=
value
end
end
return
min
end
).
item
end
function
Underscore
.
funcs
.
max
(
list
,
func
)
func
=
func
or
Underscore
.
identity
return
Underscore
.
funcs
.
reduce
(
list
,
{
item
=
nil
,
value
=
nil
},
function
(
max
,
item
)
if
max
.
item
==
nil
then
max
.
item
=
item
max
.
value
=
func
(
item
)
else
local
value
=
func
(
item
)
if
value
>
max
.
value
then
max
.
item
=
item
max
.
value
=
value
end
end
return
max
end
).
item
end
function
Underscore
.
funcs
.
to_array
(
list
)
local
array
=
{}
for
i
in
Underscore
.
iter
(
list
)
do
array
[
#
array
+
1
]
=
i
end
return
array
end
function
Underscore
.
funcs
.
reverse
(
list
)
local
reversed
=
{}
for
i
in
Underscore
.
iter
(
list
)
do
table.insert
(
reversed
,
1
,
i
)
end
return
reversed
end
function
Underscore
.
funcs
.
sort
(
iter
,
comparison_func
)
local
array
=
iter
if
type
(
iter
)
==
"function"
then
array
=
Underscore
.
funcs
.
to_array
(
iter
)
end
table.sort
(
array
,
comparison_func
)
return
array
end
-- arrays
function
Underscore
.
funcs
.
first
(
array
,
n
)
if
n
==
nil
then
return
array
[
1
]
else
local
first
=
{}
n
=
math.min
(
n
,
#
array
)
for
i
=
1
,
n
do
first
[
i
]
=
array
[
i
]
end
return
first
end
end
function
Underscore
.
funcs
.
rest
(
array
,
index
)
index
=
index
or
2
local
rest
=
{}
for
i
=
index
,
#
array
do
rest
[
#
rest
+
1
]
=
array
[
i
]
end
return
rest
end
function
Underscore
.
funcs
.
slice
(
array
,
start_index
,
length
)
local
sliced_array
=
{}
start_index
=
math.max
(
start_index
,
1
)
local
end_index
=
math.min
(
start_index
+
length
-
1
,
#
array
)
for
i
=
start_index
,
end_index
do
sliced_array
[
#
sliced_array
+
1
]
=
array
[
i
]
end
return
sliced_array
end
function
Underscore
.
funcs
.
flatten
(
array
)
local
all
=
{}
for
ele
in
Underscore
.
iter
(
array
)
do
if
type
(
ele
)
==
"table"
then
local
flattened_element
=
Underscore
.
funcs
.
flatten
(
ele
)
Underscore
.
funcs
.
each
(
flattened_element
,
function
(
e
)
all
[
#
all
+
1
]
=
e
end
)
else
all
[
#
all
+
1
]
=
ele
end
end
return
all
end
function
Underscore
.
funcs
.
push
(
array
,
item
)
table.insert
(
array
,
item
)
return
array
end
function
Underscore
.
funcs
.
pop
(
array
)
return
table.remove
(
array
)
end
function
Underscore
.
funcs
.
shift
(
array
)
return
table.remove
(
array
,
1
)
end
function
Underscore
.
funcs
.
unshift
(
array
,
item
)
table.insert
(
array
,
1
,
item
)
return
array
end
function
Underscore
.
funcs
.
join
(
array
,
separator
)
return
table.concat
(
array
,
separator
)
end
-- objects
function
Underscore
.
funcs
.
keys
(
obj
)
local
keys
=
{}
for
k
,
v
in
pairs
(
obj
)
do
keys
[
#
keys
+
1
]
=
k
end
return
keys
end
function
Underscore
.
funcs
.
values
(
obj
)
local
values
=
{}
for
k
,
v
in
pairs
(
obj
)
do
values
[
#
values
+
1
]
=
v
end
return
values
end
function
Underscore
.
funcs
.
extend
(
destination
,
source
)
for
k
,
v
in
pairs
(
source
)
do
destination
[
k
]
=
v
end
return
destination
end
function
Underscore
.
funcs
.
is_empty
(
obj
)
return
next
(
obj
)
==
nil
end
-- Originally based on penlight's deepcompare() -- http://luaforge.net/projects/penlight/
function
Underscore
.
funcs
.
is_equal
(
o1
,
o2
,
ignore_mt
)
local
ty1
=
type
(
o1
)
local
ty2
=
type
(
o2
)
if
ty1
~=
ty2
then
return
false
end
-- non-table types can be directly compared
if
ty1
~=
'table'
then
return
o1
==
o2
end
-- as well as tables which have the metamethod __eq
local
mt
=
getmetatable
(
o1
)
if
not
ignore_mt
and
mt
and
mt
.
__eq
then
return
o1
==
o2
end
local
is_equal
=
Underscore
.
funcs
.
is_equal
for
k1
,
v1
in
pairs
(
o1
)
do
local
v2
=
o2
[
k1
]
if
v2
==
nil
or
not
is_equal
(
v1
,
v2
,
ignore_mt
)
then
return
false
end
end
for
k2
,
v2
in
pairs
(
o2
)
do
local
v1
=
o1
[
k2
]
if
v1
==
nil
then
return
false
end
end
return
true
end
-- functions
function
Underscore
.
funcs
.
compose
(
...
)
local
function
call_funcs
(
funcs
,
...
)
if
#
funcs
>
1
then
return
funcs
[
1
](
call_funcs
(
_
.
rest
(
funcs
),
...
))
else
return
funcs
[
1
](
...
)
end
end
local
funcs
=
{
...
}
return
function
(
...
)
return
call_funcs
(
funcs
,
...
)
end
end
function
Underscore
.
funcs
.
wrap
(
func
,
wrapper
)
return
function
(
...
)
return
wrapper
(
func
,
...
)
end
end
function
Underscore
.
funcs
.
curry
(
func
,
argument
)
return
function
(
...
)
return
func
(
argument
,
...
)
end
end
function
Underscore
.
functions
()
return
Underscore
.
keys
(
Underscore
.
funcs
)
end
-- add aliases
Underscore
.
methods
=
Underscore
.
functions
Underscore
.
funcs
.
for_each
=
Underscore
.
funcs
.
each
Underscore
.
funcs
.
collect
=
Underscore
.
funcs
.
map
Underscore
.
funcs
.
inject
=
Underscore
.
funcs
.
reduce
Underscore
.
funcs
.
foldl
=
Underscore
.
funcs
.
reduce
Underscore
.
funcs
.
filter
=
Underscore
.
funcs
.
select
Underscore
.
funcs
.
every
=
Underscore
.
funcs
.
all
Underscore
.
funcs
.
some
=
Underscore
.
funcs
.
any
Underscore
.
funcs
.
head
=
Underscore
.
funcs
.
first
Underscore
.
funcs
.
tail
=
Underscore
.
funcs
.
rest
local
function
wrap_functions_for_oo_support
()
local
function
value_and_chained
(
value_or_self
)
local
chained
=
false
if
getmetatable
(
value_or_self
)
==
Underscore
then
chained
=
value_or_self
.
chained
value_or_self
=
value_or_self
.
_val
end
return
value_or_self
,
chained
end
local
function
value_or_wrap
(
value
,
chained
)
if
chained
then
value
=
Underscore
:
new
(
value
,
true
)
end
return
value
end
for
fn
,
func
in
pairs
(
Underscore
.
funcs
)
do
Underscore
[
fn
]
=
function
(
obj_or_self
,
...
)
local
obj
,
chained
=
value_and_chained
(
obj_or_self
)
return
value_or_wrap
(
func
(
obj
,
...
),
chained
)
end
end
end
wrap_functions_for_oo_support
()
_
=
Underscore
:
new
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment