get options and unpack

This commit is contained in:
leaf corcoran 2013-01-02 17:23:29 -08:00
parent 4d56430d4f
commit 3ec2f18b6b
2 changed files with 29 additions and 2 deletions

View File

@ -1,4 +1,5 @@
local concat = table.concat local concat = table.concat
local unpack = unpack or table.unpack
local moon = { local moon = {
is_object = function(value) is_object = function(value)
return type(value) == "table" and value.__class return type(value) == "table" and value.__class
@ -173,6 +174,18 @@ local getfenv = getfenv or function(fn)
end end
return nil return nil
end 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 { return {
moon = moon, moon = moon,
pos_to_line = pos_to_line, pos_to_line = pos_to_line,
@ -184,5 +197,7 @@ return {
dump = dump, dump = dump,
debug_posmap = debug_posmap, debug_posmap = debug_posmap,
getfenv = getfenv, getfenv = getfenv,
setfenv = setfenv setfenv = setfenv,
get_options = get_options,
unpack = unpack
} }

View File

@ -1,6 +1,8 @@
import concat from table import concat from table
unpack = unpack or table.unpack
moon = moon =
is_object: (value) -> -- is a moonscript object is_object: (value) -> -- is a moonscript object
type(value) == "table" and value.__class type(value) == "table" and value.__class
@ -105,8 +107,18 @@ getfenv = getfenv or (fn) ->
i += 1 i += 1
nil 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, :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
} }