File: table.lua

package info (click to toggle)
widelands 1%3A17-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 332,404 kB
  • sloc: cpp: 104,978; python: 3,073; ada: 855; sh: 435; makefile: 225
file content (43 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
-- RST
-- table.lua
-- -------------
--
-- This script adds some functions that are useful to work with Lua tables as
-- Sets or Arrays

-- RST
-- .. function:: array_combine(arrays)
--
--    Takes all arguments which must be Lua Arrays (that is tables with integer
--    keys starting with index 1) and combines them into one single array.
--    This is must useful to combine arrays of Fields.
--
--    :arg arrays: any number of arrays
--    :returns: a new array with all values of all arguments
function array_combine(...) 
   local t = {}
   for _,arg in ipairs{...} do
      for _,v in ipairs(arg) do
         t[#t+1] = v
      end
   end
   return t
end
   
-- RST
-- .. function:: array_reverse(a)
--
--    Returns an array with the same values in reverse order
--
--    :arg a: One array object
--    :type a: :class:`array`
--
--    :returns: array with values in a in reversed order
function array_reverse(a)
   rv = {}
   for i=#a,1,-1 do
      rv[#rv+1] = a[i]
   end
   return rv
end