1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
--
-- This is file `lualibs.lua',
-- generated with the docstrip utility.
--
-- The original source files were:
--
-- lualibs.dtx (with options: `lua')
-- This is a generated file.
--
-- Copyright (C) 2009 by PRAGMA ADE / ConTeXt Development Team
--
-- See ConTeXt's mreadme.pdf for the license.
--
-- This work consists of the main source file lualibs.dtx
-- and the derived file lualibs.lua.
--
do
local lualibs_module = {
name = "lualibs",
version = 0.93,
date = "2010/05/10",
description = "Lua additional functions.",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "See ConTeXt's mreadme.pdf for the license",
}
if luatexbase then
luatexbase.provides_module(lualibs_module)
end
end
kpse.set_program_name("luatex")
local function load_lualibs_module(filename)
local path = kpse.find_file(filename)
if not path then
texio.write_nl(string.format("lualibs: error: cannot find file %s", filename))
return
end
texio.write_nl('log', string.format("lualibs: loading file %s", path))
--if (tex and tex.luatexversion and tex.luatexversion > 44)
-- or (status and status.luatex_version and status.luatex_version > 44) then
-- require(filename)
--else
dofile(path)
--end
end
load_lualibs_module("lualibs-string.lua")
load_lualibs_module("lualibs-lpeg.lua")
load_lualibs_module("lualibs-boolean.lua")
load_lualibs_module("lualibs-number.lua")
load_lualibs_module("lualibs-math.lua")
load_lualibs_module("lualibs-table.lua")
load_lualibs_module("lualibs-aux.lua")
load_lualibs_module("lualibs-io.lua")
load_lualibs_module("lualibs-os.lua")
load_lualibs_module("lualibs-file.lua")
load_lualibs_module("lualibs-md5.lua")
load_lualibs_module("lualibs-dir.lua")
load_lualibs_module("lualibs-unicode.lua")
load_lualibs_module("lualibs-utils.lua")
load_lualibs_module("lualibs-dimen.lua")
load_lualibs_module("lualibs-url.lua")
load_lualibs_module("lualibs-set.lua")
load_lualibs_module("lualibs-dimen.lua")
fpath = file
fpath.split = file.split_path
lfs.is_readable = file.is_readable
lfs.is_writable = file.is_writable
function string:stripspaces()
return (self:gsub("^%s*(.-)%s*$", "%1"))
end
lpeg.space = lpeg.S(" \t\f\v")
lpeg.newline = lpeg.P("\r\n") + lpeg.P("\r") +lpeg.P("\n")
function table.contains_value(t, val)
if t then
for k, v in pairs(t) do
if v==val then
return true
end
end
end
return false
end
function table.contains_key(t, key)
if t then
for k, v in pairs(t) do
if k==key then
return true
end
end
end
return false
end
function table.value_position(t, val)
if t then
local i=1
for k, v in pairs(t) do
if v==val then
return i
end
i=i+1
end
end
return 0
end
function table.key_position(t, key)
if t then
local i=1
for k,v in pairs(t) do
if k==key then
return i
end
i = i+1
end
end
return -1
end
function table.remove_key(t, k)
local p = table.key_position(t,k)
if p ~= -1 then
table.remove(t, table.key_position(t,k))
end
end
function fpath.normalize_sep(str)
return str:gsub("\\", "/")
end
function fpath.localize_sep(str)
if os.type == 'windows' or os.type == 'msdos' then
return str:gsub("/", "\\")
else
return str:gsub("\\", "/")
end
end
--
-- End of File `lualibs.lua'.
|