Skip to content

Commit

Permalink
Merge pull request #9 from spc476/master
Browse files Browse the repository at this point in the history
Handle missing modules (lgi and lcurses);
Supports Lua 5.1 and Lua 5.2.
  • Loading branch information
PedroAlvesV authored May 10, 2017
2 parents 9eddfc7 + 2bde481 commit b9dcb2a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/abstk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@

local abstk = {}

local AbsGtk = require 'abstk.AbsGtk'
local AbsCurses = require 'abstk.AbsCurses'
local AbsGtk
local AbsCurses

do
local has_gtk, gtk_module = pcall(require,'abstk.AbsGtk')
local has_curses, curses_module = pcall(require,'abstk.AbsCurses')
if has_gtk then AbsGtk = gtk_module end
if has_curses then AbsCurses = curses_module end
end

local mode = nil

Expand All @@ -24,7 +31,7 @@ local mode = nil
function abstk.set_mode(arg)
if arg == 'curses' or arg == 'gtk' then
mode = arg
elseif os.getenv("DISPLAY") then
elseif os.getenv("DISPLAY") and AbsGtk then
mode = 'gtk'
else
mode = 'curses'
Expand Down Expand Up @@ -439,4 +446,4 @@ end

abstk.set_mode()

return abstk
return abstk
11 changes: 11 additions & 0 deletions src/abstk/AbsCurses.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
-- @see abstk
-------------------------------------------------

local utf8

if _VERSION < "Lua 5.3" then
local has_dep, utf8 = pcall(require, 'lua-utf8')
if not has_dep then
utf8 = { len = string.len }
end
else
utf8 = require 'utf8'
end

local AbsCurses = {}

local curses = require 'curses'
Expand Down
13 changes: 12 additions & 1 deletion src/abstk/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
-- @see AbsGtk
-------------------------------------------------

local utf8

if _VERSION < "Lua 5.3" then
local has_dep, utf8 = pcall(require, 'lua-utf8')
if not has_dep then
utf8 = { len = string.len }
end
else
utf8 = require 'utf8'
end

local util = {}

function util.make_list_items(make_item, list, default_value)
Expand Down Expand Up @@ -69,4 +80,4 @@ function util.debug(debug_message)
file:close()
end

return util
return util

0 comments on commit b9dcb2a

Please sign in to comment.