mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
config support include
This commit is contained in:
@@ -83,15 +83,20 @@ int sigign() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char * load_config = "\
|
static const char * load_config = "\
|
||||||
local config_name = ...\
|
local config_name = ...\n\
|
||||||
local f = assert(io.open(config_name))\
|
local f = assert(io.open(config_name))\n\
|
||||||
local code = assert(f:read \'*a\')\
|
local code = assert(f:read \'*a\')\n\
|
||||||
local function getenv(name) return assert(os.getenv(name), \'os.getenv() failed: \' .. name) end\
|
local function getenv(name) return assert(os.getenv(name), \'os.getenv() failed: \' .. name) end\n\
|
||||||
code = string.gsub(code, \'%$([%w_%d]+)\', getenv)\
|
code = string.gsub(code, \'%$([%w_%d]+)\', getenv)\n\
|
||||||
f:close()\
|
f:close()\n\
|
||||||
local result = {}\
|
local result = {}\n\
|
||||||
assert(load(code,\'=(load)\',\'t\',result))()\
|
local function include(filename)\n\
|
||||||
return result\
|
assert(loadfile(filename, \'t\', result))()\n\
|
||||||
|
end\n\
|
||||||
|
setmetatable(result, { __index = { include = include } })\n\
|
||||||
|
assert(load(code,\'=(load)\',\'t\',result))()\n\
|
||||||
|
setmetatable(result, nil)\n\
|
||||||
|
return result\n\
|
||||||
";
|
";
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -116,7 +121,7 @@ main(int argc, char *argv[]) {
|
|||||||
struct lua_State *L = luaL_newstate();
|
struct lua_State *L = luaL_newstate();
|
||||||
luaL_openlibs(L); // link lua lib
|
luaL_openlibs(L); // link lua lib
|
||||||
|
|
||||||
int err = luaL_loadstring(L, load_config);
|
int err = luaL_loadbufferx(L, load_config, strlen(load_config), "=[skynet config]", "t");
|
||||||
assert(err == LUA_OK);
|
assert(err == LUA_OK);
|
||||||
lua_pushstring(L, config_file);
|
lua_pushstring(L, config_file);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user