-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
186 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"git.ignoreLimitWarning": true | ||
{ | ||
"git.ignoreLimitWarning": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,31 @@ | ||
LUA_STATICLIB := 3rd/lua/liblua.a | ||
LUA_LIB ?= $(LUA_STATICLIB) | ||
LUA_INC ?= 3rd/lua/ | ||
|
||
INC = -I./ -I$(LUA_INC) | ||
LIB += $(LUA_STATICLIB) -ldl | ||
CFLAGS = -g | ||
|
||
TARGET = skynet | ||
|
||
SKYNET_SRC = skynet-src | ||
SKYNET_OBJ = $(SKYNET_SRC)/skynet_main.o | ||
|
||
$(TARGET):$(SKYNET_OBJ) | ||
$(CXX) $(CFLAGS) $(INC) -o $@ $^ $(LIB) | ||
|
||
%.o:%.cpp | ||
$(CXX) $(CFLAGS) $(INC) -c -o $@ $< | ||
|
||
|
||
$(LUA_STATICLIB): | ||
cd 3rd/lua && $(MAKE) CC='$(CC) -std=gnu99' linux | ||
|
||
cleanall: | ||
cd 3rd/lua && $(MAKE) clean | ||
rm -f $(LUA_STATICLIB) | ||
LUA_STATICLIB := 3rd/lua/liblua.a | ||
LUA_LIB ?= $(LUA_STATICLIB) | ||
LUA_INC ?= 3rd/lua/ | ||
|
||
SKYNET_SRC = skynet-src | ||
INC = -I./ -I$(LUA_INC) -I$(SKYNET_SRC)/core/ | ||
LIB += $(LUA_STATICLIB) -ldl | ||
CFLAGS = -g | ||
|
||
TARGET = skynet | ||
|
||
SKYNET_OBJ = $(SKYNET_SRC)/skynet_main.o\ | ||
$(SKYNET_SRC)/core/skynet_loadconf.o | ||
|
||
$(TARGET):$(SKYNET_OBJ) | ||
$(CXX) $(CFLAGS) $(INC) -o $@ $^ $(LIB) | ||
|
||
%.o:%.cpp | ||
$(CXX) $(CFLAGS) $(INC) -c -o $@ $< | ||
|
||
$(LUA_STATICLIB): | ||
cd 3rd/lua && $(MAKE) CC='$(CC) -std=gnu99' linux | ||
|
||
clean: | ||
rm -f $(TARGET) | ||
rm -f $(SKYNET_SRC)/core/*.o | ||
rm -f $(SKYNET_SRC)/*.o | ||
|
||
cleanall: clean | ||
cd 3rd/lua && $(MAKE) clean | ||
rm -f $(LUA_STATICLIB) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
#include "skynet_loadconf.h" | ||
#include <assert.h> | ||
#include <string.h> | ||
#include <iostream> | ||
|
||
const char *LoadConf::load_config = "\ | ||
local result = {}\n\ | ||
local function getenv(name) return assert(os.getenv(name), [[os.getenv() failed: ]] .. name) end\n\ | ||
local sep = package.config:sub(1,1)\n\ | ||
local current_path = [[.]]..sep\n\ | ||
local function include(filename)\n\ | ||
local last_path = current_path\n\ | ||
local path, name = filename:match([[(.*]]..sep..[[)(.*)$]])\n\ | ||
if path then\n\ | ||
if path:sub(1,1) == sep then -- root\n\ | ||
current_path = path\n\ | ||
else\n\ | ||
current_path = current_path .. path\n\ | ||
end\n\ | ||
else\n\ | ||
name = filename\n\ | ||
end\n\ | ||
local f = assert(io.open(current_path .. name))\n\ | ||
local code = assert(f:read [[*a]])\n\ | ||
code = string.gsub(code, [[%$([%w_%d]+)]], getenv)\n\ | ||
f:close()\n\ | ||
assert(load(code,[[@]]..filename,[[t]],result))()\n\ | ||
current_path = last_path\n\ | ||
end\n\ | ||
setmetatable(result, { __index = { include = include } })\n\ | ||
local config_name = ...\n\ | ||
include(config_name)\n\ | ||
setmetatable(result, nil)\n\ | ||
return result\n\ | ||
"; | ||
|
||
bool LoadConf::load_config(const char* config_file) { | ||
int err = luaL_loadbufferx(L, load_config, strlen(load_config), "=[skynet config]", "t"); | ||
assert(err == LUA_OK); | ||
lua_pushstring(L, config_file); | ||
|
||
err = lua_pcall(L, 1, 1, 0); | ||
if (err) { | ||
std::cerr << lua_tostring(L, -1) << std::endl; | ||
return false; | ||
} | ||
|
||
lua_pushnil(L); | ||
while (lua_next(L, -2)) { | ||
int keyt = lua_type(L, -2); | ||
if (keyt != LUA_TSTRING) { | ||
std::cerr << "Invalid config table" << std::endl; | ||
return false; | ||
} | ||
|
||
const char* key = lua_tostring(L, -2); | ||
if (lua_type(L, -1) == LUA_TBOOLEAN) { | ||
int b = lua_toboolean(L, -1); | ||
|
||
} | ||
else { | ||
const char* value = lua_tostring(L, -1); | ||
if (value == NULL) { | ||
std::cerr << "Invalid config table key = " << key << std::endl; | ||
|
||
} | ||
} | ||
lua_pop(L, 1); | ||
} | ||
lua_pop(L, -1); | ||
return true; | ||
#include "skynet_loadconf.h" | ||
#include <assert.h> | ||
#include <string.h> | ||
#include <iostream> | ||
|
||
const char *LoadConf::load_config = "\ | ||
local result = {}\n\ | ||
local function getenv(name) return assert(os.getenv(name), [[os.getenv() failed: ]] .. name) end\n\ | ||
local sep = package.config:sub(1,1)\n\ | ||
local current_path = [[.]]..sep\n\ | ||
local function include(filename)\n\ | ||
local last_path = current_path\n\ | ||
local path, name = filename:match([[(.*]]..sep..[[)(.*)$]])\n\ | ||
if path then\n\ | ||
if path:sub(1,1) == sep then -- root\n\ | ||
current_path = path\n\ | ||
else\n\ | ||
current_path = current_path .. path\n\ | ||
end\n\ | ||
else\n\ | ||
name = filename\n\ | ||
end\n\ | ||
local f = assert(io.open(current_path .. name))\n\ | ||
local code = assert(f:read [[*a]])\n\ | ||
code = string.gsub(code, [[%$([%w_%d]+)]], getenv)\n\ | ||
f:close()\n\ | ||
assert(load(code,[[@]]..filename,[[t]],result))()\n\ | ||
current_path = last_path\n\ | ||
end\n\ | ||
setmetatable(result, { __index = { include = include } })\n\ | ||
local config_name = ...\n\ | ||
include(config_name)\n\ | ||
setmetatable(result, nil)\n\ | ||
return result\n\ | ||
"; | ||
|
||
bool LoadConf::load_config_file(const char* config_file) { | ||
int err = luaL_loadbufferx(L, load_config, strlen(load_config), "=[skynet config]", "t"); | ||
assert(err == LUA_OK); | ||
lua_pushstring(L, config_file); | ||
|
||
err = lua_pcall(L, 1, 1, 0); | ||
if (err) { | ||
std::cerr << lua_tostring(L, -1) << std::endl; | ||
return false; | ||
} | ||
|
||
lua_pushnil(L); | ||
while (lua_next(L, -2)) { | ||
int keyt = lua_type(L, -2); | ||
if (keyt != LUA_TSTRING) { | ||
std::cerr << "Invalid config table" << std::endl; | ||
return false; | ||
} | ||
|
||
const char* key = lua_tostring(L, -2); | ||
if (lua_type(L, -1) == LUA_TBOOLEAN) { | ||
int b = lua_toboolean(L, -1); | ||
|
||
} | ||
else { | ||
const char* value = lua_tostring(L, -1); | ||
if (value == NULL) { | ||
std::cerr << "Invalid config table key = " << key << std::endl; | ||
|
||
} | ||
} | ||
lua_pop(L, 1); | ||
} | ||
lua_pop(L, -1); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
extern "C" { | ||
#include <lua.h> | ||
#include <lualib.h> | ||
#include <lauxlib.h> | ||
} | ||
|
||
class LoadConf { | ||
public: | ||
LoadConf(struct lua_State *l = new luaL_newstate()) : L(l) { | ||
luaL_openlibs(L); // link lua libs | ||
} | ||
~LoadConf() { | ||
lua_close(L); | ||
} | ||
|
||
bool load_config(const char* config_file); | ||
|
||
private: | ||
struct lua_State *L; | ||
static const char *load_config; | ||
extern "C" { | ||
#include "lua.h" | ||
#include "lualib.h" | ||
#include "lauxlib.h" | ||
} | ||
|
||
class LoadConf { | ||
public: | ||
LoadConf(struct lua_State *l) : L(l) { | ||
luaL_openlibs(L); // link lua libs | ||
} | ||
~LoadConf() { | ||
lua_close(L); | ||
} | ||
|
||
bool load_config_file(const char* config_file); | ||
|
||
private: | ||
struct lua_State *L; | ||
static const char *load_config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,63 @@ | ||
#include <iostream> | ||
#include <assert.h> | ||
#include <string.h> | ||
|
||
using namespace std; | ||
|
||
static const char * load_config = "\ | ||
local result = {}\n\ | ||
local function getenv(name) return assert(os.getenv(name), [[os.getenv() failed: ]] .. name) end\n\ | ||
local sep = package.config:sub(1,1)\n\ | ||
local current_path = [[.]]..sep\n\ | ||
local function include(filename)\n\ | ||
local last_path = current_path\n\ | ||
local path, name = filename:match([[(.*]]..sep..[[)(.*)$]])\n\ | ||
if path then\n\ | ||
if path:sub(1,1) == sep then -- root\n\ | ||
current_path = path\n\ | ||
else\n\ | ||
current_path = current_path .. path\n\ | ||
end\n\ | ||
else\n\ | ||
name = filename\n\ | ||
end\n\ | ||
local f = assert(io.open(current_path .. name))\n\ | ||
local code = assert(f:read [[*a]])\n\ | ||
code = string.gsub(code, [[%$([%w_%d]+)]], getenv)\n\ | ||
f:close()\n\ | ||
assert(load(code,[[@]]..filename,[[t]],result))()\n\ | ||
current_path = last_path\n\ | ||
end\n\ | ||
setmetatable(result, { __index = { include = include } })\n\ | ||
local config_name = ...\n\ | ||
include(config_name)\n\ | ||
setmetatable(result, nil)\n\ | ||
return result\n\ | ||
"; | ||
|
||
int main(int argc, char ** argv) { | ||
const char * config_file = NULL; | ||
if (argc > 1) { | ||
config_file = argv[1]; | ||
} else { | ||
cerr << "Need a config file." << endl; | ||
return 1; | ||
} | ||
|
||
struct lua_State *L = luaL_newstate(); | ||
luaL_openlibs(L); // link lua lib | ||
|
||
int err = luaL_loadbufferx(L, load_config, strlen(load_config), "=[skynet config]", "t"); | ||
assert(err == LUA_OK); | ||
lua_pushstring(L, config_file); | ||
|
||
err = lua_pcall(L, 1, 1, 0); | ||
if (err) { | ||
cerr << lua_tostring(L, -1) << endl; | ||
lua_close(L); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
#include <iostream> | ||
#include <assert.h> | ||
#include <string.h> | ||
#include "core/skynet_loadconf.h" | ||
|
||
using namespace std; | ||
|
||
static const char * load_config = "\ | ||
local result = {}\n\ | ||
local function getenv(name) return assert(os.getenv(name), [[os.getenv() failed: ]] .. name) end\n\ | ||
local sep = package.config:sub(1,1)\n\ | ||
local current_path = [[.]]..sep\n\ | ||
local function include(filename)\n\ | ||
local last_path = current_path\n\ | ||
local path, name = filename:match([[(.*]]..sep..[[)(.*)$]])\n\ | ||
if path then\n\ | ||
if path:sub(1,1) == sep then -- root\n\ | ||
current_path = path\n\ | ||
else\n\ | ||
current_path = current_path .. path\n\ | ||
end\n\ | ||
else\n\ | ||
name = filename\n\ | ||
end\n\ | ||
local f = assert(io.open(current_path .. name))\n\ | ||
local code = assert(f:read [[*a]])\n\ | ||
code = string.gsub(code, [[%$([%w_%d]+)]], getenv)\n\ | ||
f:close()\n\ | ||
assert(load(code,[[@]]..filename,[[t]],result))()\n\ | ||
current_path = last_path\n\ | ||
end\n\ | ||
setmetatable(result, { __index = { include = include } })\n\ | ||
local config_name = ...\n\ | ||
include(config_name)\n\ | ||
setmetatable(result, nil)\n\ | ||
return result\n\ | ||
"; | ||
|
||
int main(int argc, char ** argv) { | ||
const char * config_file = NULL; | ||
if (argc > 1) { | ||
config_file = argv[1]; | ||
} else { | ||
cerr << "Need a config file." << endl; | ||
return 1; | ||
} | ||
|
||
struct lua_State *L = luaL_newstate(); | ||
luaL_openlibs(L); // link lua lib | ||
|
||
int err = luaL_loadbufferx(L, load_config, strlen(load_config), "=[skynet config]", "t"); | ||
assert(err == LUA_OK); | ||
lua_pushstring(L, config_file); | ||
|
||
err = lua_pcall(L, 1, 1, 0); | ||
if (err) { | ||
cerr << lua_tostring(L, -1) << endl; | ||
lua_close(L); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |