From 152b605c856112b074dc7b41651424c4170fc067 Mon Sep 17 00:00:00 2001 From: ame Date: Sat, 25 May 2024 04:08:59 -0500 Subject: fixed deepcopy --- docs/thread.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'docs') diff --git a/docs/thread.md b/docs/thread.md index 9f868cb..00619ea 100644 --- a/docs/thread.md +++ b/docs/thread.md @@ -1,5 +1,50 @@ # threads ** +## buffer + +'takes 'anything' + +a thread-safe object buffer to easily transfer things between threads + +full example: + +```lua +buffer = llib.thread.buffer({2, 3, 4}) +buffer:get() --{2, 3, 4} +... +buffer:set({3, 4, 5}) --get is now {3, 4, 5} +... +buffer:mod(function(obj) + for i=1,#obj do + obj[i] = obj[i] + 1 + end + return obj +end) --is now {4, 5, 6} +... +buffer:clean() -- calls __gc early +``` + +### get + +returns copy of the value in the buffer + +### set + +'takes 'anything' + +sets the value in the buffer + +### mod + +'takes a function, one parameter, one returns + +passes a copy of the value of the buffer, and sets the buffer to the value returned + +```lua +buffer:mod(function(obj) return 5) +--is the same as +buffer:set(5) +``` ## lock, unlock 'takes an integer -- cgit v1.2.3