diff options
| author | ruki <[email protected]> | 2019-03-17 21:36:51 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-03-17 21:36:51 +0800 |
| commit | e35215c72fa78df798a88ca1cd9bed9bb36013d5 (patch) | |
| tree | 03e949b5e3eed833b3e04c869faa4a3f08b15ced /xmake/core | |
| parent | fb572ca825d47b0dd3612f824aefbd7eed7ba36a (diff) | |
bind package envs
Diffstat (limited to 'xmake/core')
| -rw-r--r-- | xmake/core/sandbox/modules/irpairs.lua | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/xmake/core/sandbox/modules/irpairs.lua b/xmake/core/sandbox/modules/irpairs.lua new file mode 100644 index 000000000..e498ae363 --- /dev/null +++ b/xmake/core/sandbox/modules/irpairs.lua @@ -0,0 +1,72 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file irpairs.lua +-- + +-- load modules +local table = require("base/table") + +-- irpairs +-- +-- .e.g +-- +-- @code +-- +-- for idx, val in irpairs({"a", "b", "c", "d", "e", "f"}) do +-- print("%d %s", idx, val) +-- end +-- +-- for idx, val in irpairs({"a", "b", "c", "d", "e", "f"}, function (v) return v:upper() end) do +-- print("%d %s", idx, val) +-- end +-- +-- for idx, val in irpairs({"a", "b", "c", "d", "e", "f"}, function (v, a, b) return v:upper() .. a .. b end, "a", "b") do +-- print("%d %s", idx, val) +-- end +-- +-- @endcode +function sandbox_irpairs(t, filter, ...) + + -- has filter? + local has_filter = type(filter) == "function" + + -- init iterator + local args = {...} + local iter = function (t, i) + if i > 1 then + i = i - 1 + local v = t[i] + if has_filter then + v = filter(v, unpack(args)) + end + return i, v + end + end + + -- return iterator and initialized state + t = table.wrap(t) + return iter, t, #t + 1 +end + +-- load module +return sandbox_irpairs + |
