diff src/luan/modules/Thread.luan @ 1166:7ef40e1923b7

add back Thread.global allow metatables to have metatables
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 08 Feb 2018 02:22:51 -0700
parents 3ef883468fd0
children 9f5edbef3f55
line wrap: on
line diff
--- a/src/luan/modules/Thread.luan	Wed Feb 07 23:16:12 2018 -0700
+++ b/src/luan/modules/Thread.luan	Thu Feb 08 02:22:51 2018 -0700
@@ -53,4 +53,35 @@
 
 Thread.remove_global_callable = ThreadLuan.removeGlobalCallable
 
+
+local map = {}
+local fns = {}
+
+function fns.get(key)
+	return map[key]
+end
+
+function fns.put(key,value)
+	map[key] = value
+end
+
+Thread.global = {}  -- shared across threads
+local global_mt = {}
+set_metatable(Thread.global,global_mt)
+
+function global_mt.__index(_,key)
+	return global_mt.fns.get(key)
+end
+
+function global_mt.__new_index(_,key,value)
+	global_mt.fns.put(key,value)
+end
+
+function Thread.set_global_timeout(timeout)
+	global_mt.fns = Thread.global_callable("Thread.global",timeout,fns)
+end
+
+Thread.set_global_timeout(60000)  -- one minute
+
+
 return Thread