From 9975bdfd2ca33f4d1f566cd8784060281d8d11e1 Mon Sep 17 00:00:00 2001 From: Douglas Creager Date: Fri, 6 May 2011 16:31:35 -0400 Subject: [PATCH] Add additional code to llthreads bootstrap This patch lets you add additional code to the beginning of the bootstrap function executed within each new llthread. This is needed, for instance, if you've installed lua-zmq via luarocks; in this case, you need to require "luarocks.loader" before you can require "zmq". So you can do something like: if package.loaded["luarocks.loader"] then zmq.threads.set_bootstrap_prelude([[require "luarocks.loader"]]) end --- src/threads.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/threads.lua b/src/threads.lua index 1fe033d..99257ea 100644 --- a/src/threads.lua +++ b/src/threads.lua @@ -40,9 +40,12 @@ function thread_mt:join() return self.thread:join() end -local bootstrap_code = [[ +local bootstrap_pre = [[ local action, action_arg, parent_ctx = ... local func +]] + +local bootstrap_post = [[ -- copy parent ZeroMQ context to this child thread. local zmq = require"zmq" @@ -69,6 +72,8 @@ end return func(select(4, ...)) ]] +local bootstrap_code = bootstrap_pre..bootstrap_post + local function new_thread(ctx, action, action_arg, ...) -- convert ZMQ_Ctx to lightuserdata. if ctx then @@ -82,6 +87,10 @@ end module(...) +function set_bootstrap_prelude(code) + bootstrap_code = bootstrap_pre .. code .. bootstrap_post +end + function runfile(ctx, file, ...) return new_thread(ctx, 'runfile', file, ...) end