/ld27

To get this branch, use:
bzr branch http://9ix.org/bzr/ld27

« back to all changes in this revision

Viewing changes to zoetrope/core/globals.lua

  • Committer: Josh C
  • Date: 2013-08-25 00:16:36 UTC
  • Revision ID: josh@9ix.org-20130825001636-xoivc9byo1mdx0fu
1 goal in each maze

Show diffs side-by-side

added added

removed removed

Lines of Context:
183
183
-- via http://www.gammon.com.au/forum/?id=9908
184
184
--
185
185
-- Arguments:
186
 
--              src - table to shuffle
 
186
--              table - table to shuffle
187
187
--
188
188
-- Returns:
189
189
--              table passed
190
190
 
191
 
function shuffleTable (src)
192
 
  local n = #src
 
191
function shuffleTable (table)
 
192
  local n = #table
193
193
 
194
194
  while n >= 2 do
195
195
    -- n is now the last pertinent index
196
196
    local k = math.random(n) -- 1 <= k <= n
197
197
    -- Quick swap
198
 
    src[n], src[k] = src[k], src[n]
 
198
    table[n], table[k] = table[k], table[n]
199
199
    n = n - 1
200
200
  end
201
201
 
202
 
  return src
203
 
end
204
 
 
205
 
--
206
 
--              src - table to inspect
207
 
--
208
 
--              string
209
 
 
210
 
function props (src)
211
 
        local result = {}
212
 
 
213
 
        for key, _ in pairs(src) do
214
 
                if type(key) ~= 'userdata' then 
215
 
                        table.insert(result, key)
216
 
                end
217
 
        end
218
 
 
219
 
        return table.concat(result, ', ')
 
202
  return table
220
203
end
221
204
 
222
205
-- Function: dump
250
228
 
251
229
                for key, value in pairs(source) do
252
230
                        if not ignore[value] then
253
 
                                if type(value) == 'table' then
254
 
                                        ignore[value] = true
255
 
                                end
256
 
 
257
231
                                local dumpValue = dump(value, ignore)
258
232
 
259
233
                                if dumpValue ~= '' then
260
234
                                        result = result .. '["' .. key .. '"] = ' .. dumpValue .. ', '
261
235
                                end
 
236
 
 
237
                                if type(value) == 'table' then
 
238
                                        ignore[value] = true
 
239
                                end
262
240
                        end
263
241
                end
264
242