/ld27

To get this branch, use:
bzr branch /bzr/ld27

« back to all changes in this revision

Viewing changes to zoetrope/core/globals.lua

  • Committer: Josh C
  • Date: 2014-07-03 14:41:57 UTC
  • Revision ID: josh@9ix.org-20140703144157-xydxt62xzcdq6bdk
cluke009 zoetrope + my spritebatch changes

Show diffs side-by-side

added added

removed removed

183
183
-- via http://www.gammon.com.au/forum/?id=9908
184
184
--
185
185
-- Arguments:
186
 
--              table - table to shuffle
 
186
--              src - table to shuffle
187
187
--
188
188
-- Returns:
189
189
--              table passed
190
190
 
191
 
function shuffleTable (table)
192
 
  local n = #table
 
191
function shuffleTable (src)
 
192
  local n = #src
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
 
    table[n], table[k] = table[k], table[n]
 
198
    src[n], src[k] = src[k], src[n]
199
199
    n = n - 1
200
200
  end
201
201
 
202
 
  return table
 
202
  return src
 
203
end
 
204
 
 
205
-- Function: props
 
206
-- Returns a string with a comma-delimited list of properties
 
207
-- for a table.
 
208
--
 
209
-- Arguments:
 
210
--              src - table to inspect
 
211
--
 
212
-- Returns:
 
213
--              string
 
214
 
 
215
function props (src)
 
216
        local result = {}
 
217
 
 
218
        for key, _ in pairs(src) do
 
219
                if type(key) ~= 'userdata' then 
 
220
                        table.insert(result, key)
 
221
                end
 
222
        end
 
223
 
 
224
        return table.concat(result, ', ')
203
225
end
204
226
 
205
227
-- Function: dump
228
250
 
229
251
                for key, value in pairs(source) do
230
252
                        if not ignore[value] then
 
253
                                if type(value) == 'table' then
 
254
                                        ignore[value] = true
 
255
                                end
 
256
 
231
257
                                local dumpValue = dump(value, ignore)
232
258
 
233
259
                                if dumpValue ~= '' then
234
260
                                        result = result .. '["' .. key .. '"] = ' .. dumpValue .. ', '
235
261
                                end
236
 
 
237
 
                                if type(value) == 'table' then
238
 
                                        ignore[value] = true
239
 
                                end
240
262
                        end
241
263
                end
242
264