Skip to content

Commit c325933

Browse files
committed
Add ltask.servicepath()
1 parent ed2f23e commit c325933

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lualib/service.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,10 @@ function ltask.no_response()
605605
session_coroutine_response[running_thread] = nil
606606
end
607607

608+
function ltask.servicepath(path)
609+
return ltask.call(SERVICE_ROOT, "servicepath", path)
610+
end
611+
608612
function ltask.spawn(name, ...)
609613
return ltask.call(SERVICE_ROOT, "spawn", name, ...)
610614
end
@@ -812,7 +816,7 @@ local function sys_service_init(t)
812816
-- The first system message
813817
_G.require = yieldable_require
814818
local initfunc = assert(load(t.initfunc))
815-
local func = assert(initfunc(t.name))
819+
local func = assert(initfunc(t.name, t.path))
816820
local handler = func(table.unpack(t.args))
817821
ltask.dispatch(handler)
818822
if service == nil then

service/root.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ local function spawn(t)
126126
ltask.syscall(address, "init", {
127127
initfunc = t.initfunc or config.initfunc,
128128
name = t.name,
129+
path = t.path,
129130
args = t.args or {},
130131
})
131132
return address
@@ -188,9 +189,16 @@ function S.tracelog(timeout)
188189
return tlog
189190
end
190191

192+
local SERVICE_PATH
193+
194+
function S.servicepath(path)
195+
SERVICE_PATH = path
196+
end
197+
191198
function S.spawn(name, ...)
192199
return spawn {
193200
name = name,
201+
path = SERVICE_PATH,
194202
args = {...},
195203
}
196204
end
@@ -206,6 +214,7 @@ end
206214
function S.uniqueservice(name, ...)
207215
return spawn_unique {
208216
name = name,
217+
path = SERVICE_PATH,
209218
args = {...},
210219
}
211220
end

0 commit comments

Comments
 (0)