| 117 | | --- Create a new or get an already existing thread local store associated with |
| 118 | | -- the current active coroutine. A thread local store is private a table object |
| 119 | | -- whose values can't be accessed from outside of the running coroutine. |
| 120 | | -- @return Table value representing the corresponding thread local store |
| 121 | | function threadlocal() |
| 122 | | local tbl = {} |
| 123 | | |
| 124 | | local function get(self, key) |
| 125 | | local t = rawget(self, coxpt[coroutine.running()] or coroutine.running() or 0) |
| | 117 | local tl_meta = { |
| | 118 | __mode = "k", |
| | 119 | |
| | 120 | __index = function(self, key) |
| | 121 | local t = rawget(self, coxpt[coroutine.running()] |
| | 122 | or coroutine.running() or 0) |
| 137 | | |
| 138 | | setmetatable(tbl, {__index = get, __newindex = set, __mode = "k"}) |
| 139 | | |
| 140 | | return tbl |
| | 134 | } |
| | 135 | |
| | 136 | --- Create a new or get an already existing thread local store associated with |
| | 137 | -- the current active coroutine. A thread local store is private a table object |
| | 138 | -- whose values can't be accessed from outside of the running coroutine. |
| | 139 | -- @return Table value representing the corresponding thread local store |
| | 140 | function threadlocal(tbl) |
| | 141 | return setmetatable(tbl or {}, tl_meta) |