mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add lua loader
This commit is contained in:
40
lualib/loader.lua
Normal file
40
lualib/loader.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
local args = {}
|
||||
for word in string.gmatch(..., "%S+") do
|
||||
table.insert(args, word)
|
||||
end
|
||||
|
||||
local main, pattern
|
||||
|
||||
local err = {}
|
||||
for pat in string.gmatch(LUA_SERVICE, "([^;]+);*") do
|
||||
local filename = string.gsub(pat, "?", args[1])
|
||||
local f, msg = loadfile(filename)
|
||||
if not f then
|
||||
table.insert(err, msg)
|
||||
else
|
||||
pattern = pat
|
||||
main = f
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not main then
|
||||
error(table.concat(err, "\n"))
|
||||
end
|
||||
|
||||
LUA_SERVICE = nil
|
||||
package.path , LUA_PATH = LUA_PATH
|
||||
package.cpath , LUA_CPATH = LUA_CPATH
|
||||
|
||||
local service_path = string.match(pattern, "(.*/)[^/?]+$")
|
||||
if service_path then
|
||||
package.path = service_path .. ";" .. package.path
|
||||
end
|
||||
|
||||
if LUA_PRELOAD then
|
||||
local f = assert(loadfile(LUA_PRELOAD))
|
||||
f(table.unpack(args))
|
||||
LUA_PRELOAD = nil
|
||||
end
|
||||
|
||||
main(select(2, table.unpack(args)))
|
||||
Reference in New Issue
Block a user