Skip to content

Commit

Permalink
Merge pull request #104 from starius/wt-config-optional
Browse files Browse the repository at this point in the history
WServer: wt_config is optional
  • Loading branch information
starius authored Jan 26, 2017
2 parents 6c78d04 + 51eba74 commit 820a6dd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,12 @@ local code = [[
]]

local luawt = require 'luawt'
local test = require 'luawt.test'

-- File with config for server.
local wt_config = test.baseConfig()

-- Start WServer with the code above.
local server = luawt.WServer({
code = code,
ip = '127.0.0.1',
port = 8080,
wt_config = wt_config,
})
server:start()
server:waitForShutdown()
Expand Down
12 changes: 6 additions & 6 deletions examples/hello/main.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
local test = require 'luawt.test'
local luawt = require 'luawt'

local module_file = io.open('./examples/hello/hello.lua', 'r')
local code = module_file:read('*all')
module_file:close()

local ip = '0.0.0.0'
local port = 12346
local wt_config = test.baseConfig()
local server = test.createServer(code, ip, port, wt_config)

local server = luawt.WServer({
code = code,
ip = '0.0.0.0',
port = 12346,
})
server:start()
server:waitForShutdown()
12 changes: 6 additions & 6 deletions examples/luacheck/main.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local test = require 'luawt.test'
local luawt = require 'luawt'

local code = [[
local app, env = ...
Expand All @@ -23,10 +23,10 @@ local code = [[
end)
]]

local ip = '0.0.0.0'
local port = 12345
local wt_config = test.baseConfig()
local server = test.createServer(code, ip, port, wt_config)

local server = luawt.WServer({
code = code,
ip = '0.0.0.0',
port = 12345,
})
server:start()
server:waitForShutdown()
11 changes: 8 additions & 3 deletions src/luawt/WServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ int luawt_WServer_make(lua_State* L) {
lua_getfield(L, 1, "port");
const char* port = luaL_checkstring(L, -1);
// get config
const char* config = 0;
lua_getfield(L, 1, "wt_config");
const char* config = luaL_checkstring(L, -1);
if (!lua_isnil(L, -1)) {
config = luaL_checkstring(L, -1);
}
// make argc, argv
typedef std::vector<const char*> Options;
Options opt;
Expand All @@ -69,8 +72,10 @@ int luawt_WServer_make(lua_State* L) {
opt.push_back("--http-port");
opt.push_back(port);
opt.push_back("--docroot=/usr/share/Wt");
opt.push_back("--config");
opt.push_back(config);
if (config) {
opt.push_back("--config");
opt.push_back(config);
}
opt.push_back(0);
WServer* server = reinterpret_cast<WServer*>(
lua_newuserdata(L, sizeof(WServer))
Expand Down

0 comments on commit 820a6dd

Please sign in to comment.