Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

lub 1.0.2 #2

Merged
merged 15 commits into from
Apr 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions .travis.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ env:
- TOOL="clang" # Use clang - TOOL="clang" # Use clang
- TOOL="i686-w64-mingw32" # 32bit MinGW - TOOL="i686-w64-mingw32" # 32bit MinGW
- TOOL="x86_64-w64-mingw32" # 64bit MinGW - TOOL="x86_64-w64-mingw32" # 64bit MinGW
- TOOL="arm-linux-gnueabihf" # ARM hard-float (hf), linux # This will always fail because lvm.c fails
# - TOOL="arm-linux-gnueabihf" # ARM hard-float (hf), linux


# Crosscompile builds may fail # Crosscompile builds may notfail
matrix: # matrix:
allow_failures: # allow_failures:
- env: TOOL="i686-w64-mingw32" # - env: TOOL="i686-w64-mingw32"
- env: TOOL="x86_64-w64-mingw32" # - env: TOOL="x86_64-w64-mingw32"
- env: TOOL="arm-linux-gnueabihf" # - env: TOOL="arm-linux-gnueabihf"


# Install dependencies # Install dependencies
install: install:
- git clone git://github.com/LuaDist/Tools.git ~/_tools - git clone git://github.com/LuaDist/Tools.git ~/_tools
# For testing "lub" depends on "lut"
- git clone git://github.com/lubyk/lut.git ~/_lut
- ln -sf ~/_lut/lut lut
- ln -sf ~/_lut/lut/init.lua lut.lua
- ~/_tools/travis/travis install - ~/_tools/travis/travis install


# Bootstap # Bootstap
Expand All @@ -31,7 +36,8 @@ before_script:


# Build the module # Build the module
script: script:
- ~/_tools/travis/travis build - ~/_tools/travis/travis build && (test -e ~/build/lubyk/lub/_test/bin/lua.exe || ~/build/lubyk/lub/_test/bin/lua test/all.lua)



# Execute additional tests or commands # Execute additional tests or commands
after_script: after_script:
Expand All @@ -45,7 +51,7 @@ branches:
# Notify the LuaDist Dev group if needed # Notify the LuaDist Dev group if needed
notifications: notifications:
recipients: recipients:
- luadist-dev@googlegroups.com - gaspard@teti.ch
email: email:
on_success: change on_success: change
on_failure: always on_failure: always
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include ( lua )


install ( install (
DIRECTORY lub/ DIRECTORY lub/
DESTINATION ${INSTALL_LMOD}/lub DESTINATION ${INSTALL_LMOD}/lub
COMPONENT Runtime COMPONENT Runtime
) )


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
lub lub [![Build Status](https://travis-ci.org/lubyk/lub.png)](https://travis-ci.org/lubyk/lub)
=== ===


Lubyk core library (provides autoloading, helpers). Lubyk core library (provides autoloading, helpers).
Expand Down
2 changes: 1 addition & 1 deletion dist.info
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
--- This file is part of Lubyk project --- This file is part of Lubyk project


name = "lub" name = "lub"
version = "1.0.0" version = "1.0.2"


desc = "Lubyk base module (autoload, template, helpers)" desc = "Lubyk base module (autoload, template, helpers)"
author = "Gaspard Bucher" author = "Gaspard Bucher"
Expand Down
13 changes: 13 additions & 0 deletions doc/index.html
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>lub</title>
</head>
<body>
<h3>Online documentation</h3>
<p><a href='http://doc.lubyk.org/lub.html'>doc.lubyk.org/lub.html</a></h1></p>

<h3>Generate</h3>
<pre>$ lua scripts/makedoc.lua</pre>
</body>
</html>
34 changes: 0 additions & 34 deletions lub-1.0.0-1.rockspec

This file was deleted.

33 changes: 33 additions & 0 deletions lub-1.0.2-1.rockspec
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,33 @@
package = "lub"
version = "1.0.2-1"
source = {
url = "http://lubyk.org/archive/lub-REL-1.0.2.tar.gz",
dir = 'lub-REL-1.0.2',
}
description = {
summary = "Lubyk base module.",
detailed = [[
lub: helper code, class declaration.

lub.Autoload: autoloading classes in modules.

lub.Dir: a simple directory traversal class.

lub.Template: a simple templating class.
]],
homepage = "http://lubyk.org",
license = "MIT"
}
dependencies = {
"lua >= 5.1, < 5.3",
"luafilesystem >= 1.5.0",
}
build = {
type = 'builtin',
modules = {
['lub' ] = 'lub/init.lua',
['lub.Autoload' ] = 'lub/Autoload.lua',
['lub.Dir' ] = 'lub/Dir.lua',
['lub.Template' ] = 'lub/Template.lua',
},
}
36 changes: 26 additions & 10 deletions lub/Template.lua
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
--]]------------------------------------------------------ --]]------------------------------------------------------
local lub = require 'lub' local lub = require 'lub'
local lib = lub.class 'lub.Template' local lib = lub.class 'lub.Template'
local NO_FENV = not rawget(_G, 'setfenv')
local private = {} local private = {}


-- Create a new template object ready to produce output by calling #run. The -- Create a new template object ready to produce output by calling #run. The
Expand All @@ -45,12 +46,7 @@ function lib.new(source)
file:close() file:close()
end end
setmetatable(self, lib) setmetatable(self, lib)
self.lua = private.parse(self, self.source) private.makeFunction(self, source)
self.func, self.err = loadstring(self.lua)
if self.err then
print(self.err)
assert(false, self.err)
end
return self return self
end end


Expand All @@ -66,17 +62,37 @@ function lib:run(env)
buffer_ = buffer_ .. indent .. string.gsub(str, '\n', indent) buffer_ = buffer_ .. indent .. string.gsub(str, '\n', indent)
end end
setmetatable(env, {__index = _G}) setmetatable(env, {__index = _G})
setfenv(self.func, env) local ok, err = pcall(function() self.func(env) end)
self.func() if not ok then
print(self.lua)
assert(false, err)
end
return buffer_ return buffer_
end end

function private:makeFunction(source)
local res = 'local function _fun_(env)\n'
if NO_FENV then
res = res..' local _ENV = env\n'
else
res = res..' setfenv(1, env)\n'
end
self.lua = res..private.parse(self, source)..'\nend\nreturn _fun_'
self.func, self.err = loadstring(self.lua)
if self.err then
print(self.lua)
assert(false, self.err)
end
-- We compile as a function so that we can pass 'env' as parameter.
self.func = self.func()
end


-- (internal). Return Lua code from the template string. The generated code -- (internal). Return Lua code from the template string. The generated code
-- outputs content by calling `env._out_` function. -- outputs content by calling `env._out_` function.
function private:parse(source) function private:parse(source)
local res = '' local res = ''

local eat_next_newline local eat_next_newline
--for text, block in string.gmatch(tmpl, "([^{]-)(%b{})") do
-- Find balanced { -- Find balanced {
for text, block in string.gmatch(source .. '{{}}', '([^{]-)(%b{})') do for text, block in string.gmatch(source .. '{{}}', '([^{]-)(%b{})') do
if text ~= '' then if text ~= '' then
Expand Down Expand Up @@ -110,7 +126,7 @@ function private:parse(source)
text = text .. '{' text = text .. '{'
block_text = private.parse(self, string.sub(block, 2, -1)) block_text = private.parse(self, string.sub(block, 2, -1))
end end
if text then if text and text ~= '' then
res = res .. string.format("_out_([=[%s]=])\n", text) .. block_text res = res .. string.format("_out_([=[%s]=])\n", text) .. block_text
else else
res = res .. block_text res = res .. block_text
Expand Down
12 changes: 6 additions & 6 deletions lub/init.lua
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ local gsub = string.gsub
local sub = string.sub local sub = string.sub
local match = string.match local match = string.match
local len = string.len local len = string.len
local TAIL_CALL = rawget(_G, 'setfenv') and '%(tail call%)' or '%(%.%.%.tail calls%.%.%.%)'


local CALL_TO_NEW = {__call = function(lib, ...) return lib.new(...) end} local CALL_TO_NEW = {__call = function(lib, ...) return lib.new(...) end}


local lib = {} local lib = {}
lub = lib


--[[------------------------------------------------------ --[[------------------------------------------------------


Expand All @@ -28,9 +28,9 @@ lub = lib
-- + lfs: luafilesystem -- + lfs: luafilesystem
local lfs = require 'lfs' local lfs = require 'lfs'


-- Current version for 'lub' module. Minor version numbers are never released -- Current version for 'lub' module. Odd minor version numbers are never
-- and are used during development. -- released and are used during development.
lib.VERSION = '1.0.0' lib.VERSION = '1.0.2'


-- # Class management -- # Class management
-- --
Expand Down Expand Up @@ -112,7 +112,7 @@ function lib.path(path, level)
local chr = sub(path, 1, 1) local chr = sub(path, 1, 1)
if chr == '|' or chr == '&' then if chr == '|' or chr == '&' then
local src = debug.getinfo(level).source local src = debug.getinfo(level).source
if src == '=(tail call)' then if src:match(TAIL_CALL) then
src = debug.getinfo(level + 1).source src = debug.getinfo(level + 1).source
end end
local s = match(src, '^@(.*)$') local s = match(src, '^@(.*)$')
Expand Down Expand Up @@ -456,7 +456,7 @@ end
function lib.log(...) function lib.log(...)
local trace = lib.split(debug.traceback(), '\n\t') local trace = lib.split(debug.traceback(), '\n\t')
local part = trace[3] local part = trace[3]
if part:match('%(tail call%)') then if part:match(TAIL_CALL) then
part = trace[4] part = trace[4]
end end
local file, line = match(part, '^([^:]+):([^:]+):') local file, line = match(part, '^([^:]+):([^:]+):')
Expand Down
4 changes: 3 additions & 1 deletion scripts/CMakeLists.txt.in
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ cmake_minimum_required ( VERSION 2.8 )
include ( cmake/dist.cmake ) include ( cmake/dist.cmake )
include ( lua ) include ( lua )


install(DIRECTORY {{mod.type}} install (
DIRECTORY {{mod.type}}/
DESTINATION ${INSTALL_LMOD}/{{mod.type}} DESTINATION ${INSTALL_LMOD}/{{mod.type}}
COMPONENT Runtime
) )


install_data ( README.md LICENSE ) install_data ( README.md LICENSE )
Expand Down
4 changes: 2 additions & 2 deletions scripts/dist.info.in
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
{% mod = require 'lub' %} {% mod = require 'lub' %}
--- This file is part of Lubyk project --- This file is part of Lubyk project


name = "Lub" name = "{{mod.type}}"
version = "{{mod.VERSION}}" version = "{{mod.VERSION}}"


desc = "Lubyk base module (autoload, template, helpers)" desc = "Lubyk base module (autoload, template, helpers)"
Expand All @@ -11,6 +11,6 @@ url = "http://lubyk.org"
maintainer = "Gaspard Bucher" maintainer = "Gaspard Bucher"


depends = { depends = {
"lua ~> 5.1", "lua ~> 5.1",
"luafilesystem >= 1.5.0", "luafilesystem >= 1.5.0",
} }
9 changes: 4 additions & 5 deletions scripts/makedoc.lua
Original file line number Original file line Diff line number Diff line change
@@ -1,17 +1,16 @@
local lub = require 'lub' local lut = require 'lut'
lub.Doc.make { lut.Doc.make {
sources = { sources = {
'lub', 'lub',
}, },
head = '<meta name="google-site-verification" content="p1ZrKNheIo5xMhrMOo9MxKaY2hL9LlyuPYyRnEl2QuM" />',
target = 'doc', target = 'doc',
format = 'html', format = 'html',
header = [[ <a href='http://lubyk.org'><img alt='lubyk logo' src='img/lubyk.png'/></a> <h1><a href='http://doc.lubyk.org'>Lubyk documentation</a></h1></a> ]], header = [[<h1><a href='http://doc.lubyk.org'>Lubyk documentation</a></h1></a> ]],
index = [=[ index = [=[
--[[-- --[[--
# Lubyk documentation # Lubyk documentation


## List of available modules in lubyk ## List of available modules
--]]-- --]]--
]=] ]=]
} }
36 changes: 17 additions & 19 deletions scripts/rockspec.in
Original file line number Original file line Diff line number Diff line change
@@ -1,37 +1,35 @@
{% mod = lub %} {% mod = lub %}
package = "Lub" package = "{{mod.type}}"
version = "{{mod.VERSION}}-1" version = "{{mod.VERSION}}-1"
source = { source = {
url = "http://lubyk.org/archive/REL-{{mod.VERSION}}.tar.gz", url = "http://lubyk.org/archive/{{mod.type}}-REL-{{mod.VERSION}}.tar.gz",
dir = '{{mod.type}}-REL-{{mod.VERSION}}', dir = '{{mod.type}}-REL-{{mod.VERSION}}',
} }
description = { description = {
summary = "Lubyk base module.", summary = "Lubyk base module.",
detailed = [[ detailed = [[
lub: helper code, class declaration. lub: helper code, class declaration.


lub.Autoload: autoloading classes in modules. lub.Autoload: autoloading classes in modules.


lub.Dir: a simple directory traversal class. lub.Dir: a simple directory traversal class.


lub.Template: a simple templating class. lub.Template: a simple templating class.
]], ]],
-- lub.Test: A simple yet powerful unit testing framework. homepage = "http://lubyk.org",
homepage = "http://lubyk.org", license = "MIT"
license = "MIT"
} }
dependencies = { dependencies = {
"lua ~> 5.1", "lua >= 5.1, < 5.3",
"luafilesystem >= 1.5.0", "luafilesystem >= 1.5.0",
} }
build = { build = {
type = 'builtin', type = 'builtin',
modules = { modules = {
{{string.format("[%-17s] = '%s/%s.lua'", "'"..mod.type.."'", mod.type, 'init')}},
{% for file in lfs.dir(mod.type) do %} {% for file in lfs.dir(mod.type) do %}
{% if file == 'init.lua' then %} {% if file ~= 'init.lua' and file:match('.lua$') then file = file:sub(1, -5) %}
['{{mod.type}}' ] = '{{mod.type}}/init.lua', {{string.format("[%-17s] = '%s/%s.lua'", "'"..mod.type..'.'..file.."'", mod.type, file)}},
{% elseif file:match('.lua$') then file = file:sub(1, -5) %}
['{{mod.type}}.{{file}}'] = '{{mod.type}}/{{file}}.lua',
{% end %} {% end %}
{% end %} {% end %}
}, },
Expand Down
9 changes: 3 additions & 6 deletions test/Dir_test.lua
Original file line number Original file line Diff line number Diff line change
@@ -1,13 +1,10 @@
--[[------------------------------------------------------ --[[------------------------------------------------------


lk.Dir test # lub.Dir test
--------

...


--]]------------------------------------------------------ --]]------------------------------------------------------
require 'lut' local lub = require 'lub'

local lut = require 'lut'
local should = lut.Test 'lub.Dir' local should = lut.Test 'lub.Dir'


function should.listFilesMatchingPattern() function should.listFilesMatchingPattern()
Expand Down
Loading