Skip to content

Commit

Permalink
Examples: add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zer0main committed Feb 1, 2017
1 parent 353e9ee commit 7436248
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
10 changes: 10 additions & 0 deletions examples/hello/hello.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
-- This code is executed in constructor of new application.
-- It setups widgets of a start page shown to a user.
local luawt = require 'luawt'

-- app is an instance of WApplication
-- env is an instance of WEnvironment
local app, env = ...

function breakTheLine()
Expand All @@ -9,16 +13,22 @@ end

function mainApp()
app:setTitle('Hello!')
-- Use CSS style sheet file. Note that it should be in docroot
-- specified by WServer's options.
app:useStyleSheet('./common.css')
-- Enums are treated as numbers. 4 corresponds to AlignCenter.
app:root():setContentAlignment(4)
-- Create widgets.
local text = luawt.WText('Your name, please?')
breakTheLine()
local name_edit = luawt.WLineEdit(app:root())
breakTheLine()
name_edit:setFocus()
local button = luawt.WPushButton('Greet me', app:root())
-- Set CSS style classes (from common.css).
button:setStyleClass('button')
text:setStyleClass('my_text')
-- Setup singal handler.
button:clicked():connect(function()
text:setText('Hello there, ' .. name_edit:text())
end)
Expand Down
5 changes: 4 additions & 1 deletion examples/hello/main.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
local luawt = require 'luawt'

-- Get code of the application as a string.
local module_file = io.open('./examples/hello/hello.lua', 'r')
local code = module_file:read('*all')
module_file:close()

-- Create and start WServer.
-- `docroot` option is needed to find static resources (CSS in our case).
local server = luawt.WServer({
code = code,
ip = '0.0.0.0',
port = 12346,
docroot = './examples/',
docroot = './examples',
})
server:start()
server:waitForShutdown()
13 changes: 12 additions & 1 deletion examples/luacheck/luacheck.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
-- This code is executed in constructor of new application.
-- It setups widgets of a start page shown to a user.
local luacheck = require 'luacheck'
local luawt = require 'luawt'

-- app is an instance of WApplication
-- env is an instance of WEnvironment
local app, env = ...

app:setTitle('luacheck')
-- Use CSS style sheet file. Note that it should be in docroot
-- specified by WServer's options.
app:useStyleSheet('./common.css')

-- Enums are treated as numbers. 4 corresponds to AlignCenter.
app:root():setContentAlignment(4)
-- Create widgets.
local textarea = luawt.WTextArea(app:root())
app:root():addWidget(luawt.WBreak())
local button = luawt.WPushButton(app:root())
app:root():addWidget(luawt.WBreak())
button:setStyleClass('button')
button:setText('Check Lua syntax')
local result = luawt.WText(app:root())
-- Set CSS style classes (from common.css).
result:setStyleClass('my_text')
button:setStyleClass('button')

-- Setup signal handler.
button:clicked():connect(function()
-- Play with luacheck a bit.
local c = luacheck.check_strings({textarea:text()})
if c.fatals + c.errors + c.warnings > 0 then
local error_msg = ''
Expand Down
5 changes: 4 additions & 1 deletion examples/luacheck/main.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
local luawt = require 'luawt'

local module_file = io.open('./examples/luacheck/luacheck.lua')
-- Get code of the application as a string.
local module_file = io.open('./examples/luacheck/luacheck.lua', 'r')
local code = module_file:read('*all')
module_file:close()

-- Create and start WServer.
-- `docroot` option is needed to find static resources (CSS in our case).
local server = luawt.WServer({
code = code,
ip = '0.0.0.0',
Expand Down

0 comments on commit 7436248

Please sign in to comment.