mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
get options and unpack
This commit is contained in:
parent
4d56430d4f
commit
3ec2f18b6b
@ -1,4 +1,5 @@
|
||||
local concat = table.concat
|
||||
local unpack = unpack or table.unpack
|
||||
local moon = {
|
||||
is_object = function(value)
|
||||
return type(value) == "table" and value.__class
|
||||
@ -173,6 +174,18 @@ local getfenv = getfenv or function(fn)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
local get_options
|
||||
get_options = function(...)
|
||||
local count = select("#", ...)
|
||||
local opts = select(count, ...)
|
||||
if type(opts) == "table" then
|
||||
return opts, unpack({
|
||||
...
|
||||
}, nil, count - 1)
|
||||
else
|
||||
return { }, ...
|
||||
end
|
||||
end
|
||||
return {
|
||||
moon = moon,
|
||||
pos_to_line = pos_to_line,
|
||||
@ -184,5 +197,7 @@ return {
|
||||
dump = dump,
|
||||
debug_posmap = debug_posmap,
|
||||
getfenv = getfenv,
|
||||
setfenv = setfenv
|
||||
setfenv = setfenv,
|
||||
get_options = get_options,
|
||||
unpack = unpack
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
|
||||
import concat from table
|
||||
|
||||
unpack = unpack or table.unpack
|
||||
|
||||
moon =
|
||||
is_object: (value) -> -- is a moonscript object
|
||||
type(value) == "table" and value.__class
|
||||
@ -105,8 +107,18 @@ getfenv = getfenv or (fn) ->
|
||||
i += 1
|
||||
nil
|
||||
|
||||
-- moves the last argument to the front if it's a table, or returns empty table
|
||||
-- inserted to the front of args
|
||||
get_options = (...) ->
|
||||
count = select "#", ...
|
||||
opts = select count, ...
|
||||
if type(opts) == "table"
|
||||
opts, unpack {...}, nil, count - 1
|
||||
else
|
||||
{}, ...
|
||||
|
||||
{
|
||||
:moon, :pos_to_line, :get_closest_line, :get_line, :reversed, :trim, :split,
|
||||
:dump, :debug_posmap, :getfenv, :setfenv
|
||||
:dump, :debug_posmap, :getfenv, :setfenv, :get_options, :unpack
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user