Mercurial > wow > ouroloot
comparison LibFarmbuyer.lua @ 6:df3e27edbd60
Much work on history tab.
| author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
|---|---|
| date | Wed, 15 Jun 2011 03:59:13 +0000 |
| parents | 822b6ca3ef89 |
| children | 5ee4edd24c13 |
comparison
equal
deleted
inserted
replaced
| 5:7adbc59de8fe | 6:df3e27edbd60 |
|---|---|
| 42 | 42 |
| 43 - DoOnceNextUpdate(f) | 43 - DoOnceNextUpdate(f) |
| 44 Runs F on the next frame refresh cycle. Multiple calls in one cycle will | 44 Runs F on the next frame refresh cycle. Multiple calls in one cycle will |
| 45 stack LIFO. Calls *while* processing the stack are safe, and will be stacked | 45 stack LIFO. Calls *while* processing the stack are safe, and will be stacked |
| 46 up for the next cycle. | 46 up for the next cycle. |
| 47 ]] | 47 |
| 48 | 48 - safecall (func, ...) |
| 49 local MAJOR, MINOR = "LibFarmbuyer", 7 | 49 A modified copy of the xpcall wrapper duplicated in every Ace3 file in the |
| 50 whole damn library. | |
| 51 | |
| 52 - new(...), del(t), copy(t), clear() | |
| 53 Ditto for table recycling. | |
| 54 ]] | |
| 55 | |
| 56 local MAJOR, MINOR = "LibFarmbuyer", 9 | |
| 50 assert(LibStub,MAJOR.." requires LibStub") | 57 assert(LibStub,MAJOR.." requires LibStub") |
| 51 local lib = LibStub:NewLibrary(MAJOR, MINOR) | 58 local lib = LibStub:NewLibrary(MAJOR, MINOR) |
| 52 if not lib then return end | 59 if not lib then return end |
| 53 | 60 |
| 54 _G[MAJOR] = lib | 61 _G[MAJOR] = lib |
| 55 | 62 |
| 56 ---------------------------------------------------------------------- | 63 ---------------------------------------------------------------------- |
| 64 --[[ | |
| 65 Recycling functions yoinked from AceConfigDialog and tweaked | |
| 66 ]] | |
| 57 local new, del, copy, clear | 67 local new, del, copy, clear |
| 68 do | |
| 69 local pool = setmetatable({},{__mode="k"}) | |
| 70 function clear() | |
| 71 wipe(pool) | |
| 72 end | |
| 73 function new(...) -- slightly modified variant, takes optional initializers | |
| 74 local t = next(pool) | |
| 75 if t then | |
| 76 pool[t] = nil | |
| 77 for i = 1, select('#',...) do | |
| 78 t[i] = select(i,...) | |
| 79 end | |
| 80 return t | |
| 81 else | |
| 82 return {...} | |
| 83 end | |
| 84 end | |
| 85 function copy(t) | |
| 86 local c = new() | |
| 87 for k, v in pairs(t) do | |
| 88 c[k] = v | |
| 89 end | |
| 90 return c | |
| 91 end | |
| 92 function del(t) | |
| 93 wipe(t) | |
| 94 pool[t] = true | |
| 95 end | |
| 96 end | |
| 97 lib.new, lib.del, lib.copy, lib.clear = new, del, copy, clear | |
| 58 | 98 |
| 59 | 99 |
| 60 ---------------------------------------------------------------------- | 100 ---------------------------------------------------------------------- |
| 61 --[[ | 101 --[[ |
| 62 safeprint | 102 safeprint |
| 212 end | 252 end |
| 213 end | 253 end |
| 214 | 254 |
| 215 | 255 |
| 216 ---------------------------------------------------------------------- | 256 ---------------------------------------------------------------------- |
| 217 -- Recycling functions yoinked from AceConfigDialog and tweaked | 257 --[[ |
| 258 safecall | |
| 259 ]] | |
| 218 do | 260 do |
| 219 local pool = setmetatable({},{__mode="k"}) | 261 local xpcall = xpcall |
| 220 function clear() | 262 |
| 221 wipe(pool) | 263 local function errorhandler(err) |
| 222 end | 264 --return geterrorhandler()(err) |
| 223 function new(...) -- slightly modified variant, takes optional initializers | 265 --print("in error handler", err) |
| 224 local t = next(pool) | 266 return err |
| 225 if t then | 267 end |
| 226 pool[t] = nil | 268 |
| 227 for i = 1, select('#',...) do | 269 local template = ([[ |
| 228 t[i] = select(i,...) | 270 local xpcall, eh = ... |
| 229 end | 271 local method, ARGS |
| 230 return t | 272 local function call() return method(ARGS) end |
| 231 else | 273 |
| 232 return {...} | 274 local function dispatch (func, ...) |
| 233 end | 275 method = func |
| 234 end | 276 if not method then return end |
| 235 function copy(t) | 277 ARGS = ... |
| 236 local c = new() | 278 return xpcall (call, eh) |
| 237 for k, v in pairs(t) do | 279 end |
| 238 c[k] = v | 280 |
| 239 end | 281 return dispatch |
| 240 return c | 282 ]]):gsub('\t',' ') |
| 241 end | 283 |
| 242 function del(t) | 284 local function CreateDispatcher(argCount) |
| 243 wipe(t) | 285 local ARGS = {} |
| 244 pool[t] = true | 286 for i = 1, argCount do ARGS[i] = "arg"..i end |
| 245 end | 287 local code = template:gsub("ARGS", table.concat(ARGS, ", ")) |
| 246 end | 288 return assert(loadstring(code, "LibF/safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler) |
| 289 end | |
| 290 | |
| 291 local Dispatchers = setmetatable({ | |
| 292 [0] = function(func) | |
| 293 return xpcall (func, errorhandler) | |
| 294 end | |
| 295 }, { | |
| 296 __index = function (Ds, argCount) | |
| 297 local dispatcher = CreateDispatcher(argCount) | |
| 298 Ds[argCount] = dispatcher | |
| 299 return dispatcher | |
| 300 end | |
| 301 }) | |
| 302 | |
| 303 function lib.safecall (func, ...) | |
| 304 if type(func) == 'function' then | |
| 305 return Dispatchers[select('#', ...)](func, ...) | |
| 306 end | |
| 307 end | |
| 308 end | |
| 309 | |
| 310 | |
| 311 ---------------------------------------------------------------------- | |
| 247 | 312 |
| 248 -- vim: noet | 313 -- vim: noet |
