Skip to content
Snippets Groups Projects
Commit 0499c418 authored by Luigi Scarso's avatar Luigi Scarso
Browse files

clean up -- !!! WARNING: WORK IN PROGRESS !!!

parent e70ef608
No related branches found
No related tags found
No related merge requests found
......@@ -36,13 +36,13 @@ int lua_active = 0;
#define Luas_open(name,luaopen_lib) \
lua_pushcfunction(L, luaopen_lib); \
lua_pushstring(L, name); \
lua_call(L, 1, 0);
lua_call(L, 1, 0);
#else
#define Luas_load(Luas,getS,ls,lua_id) \
lua_load(Luas,getS,ls,lua_id,NULL);
#define Luas_open(name,luaopen_lib) \
luaL_requiref(L, name, luaopen_lib, 1); \
lua_pop(L, 1);
lua_pop(L, 1);
#endif
@ @c
......@@ -293,8 +293,6 @@ void luainterpreter(void)
lua_pushcfunction(L,luatex_loadfile);
lua_setglobal(L, "loadfile");
luatex_md5_lua_open(L); /* this also loads some lua code */
open_oslibext(L);
open_strlibext(L);
open_lfslibext(L);
......@@ -677,5 +675,5 @@ LUA_API int lua_compare (lua_State *L, int o1, int o2, int op) {
return i;
}
@ @c
@ @c
#endif
/* generated from and by luatex-core.lua */
#include "lua.h"
#include "lauxlib.h"
......@@ -5,7 +7,6 @@ int load_luatex_core_lua (lua_State * L);
int load_luatex_core_lua (lua_State * L)
{
/* generated from and by luatex-core.lua */
static unsigned char luatex_core_lua[] = {
0x2d, 0x2d, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x20, 0x3d,
......@@ -227,7 +228,33 @@ int load_luatex_core_lua (lua_State * L)
0x73, 0x2e, 0x73, 0x70, 0x61, 0x77, 0x6e, 0x7c, 0x6f, 0x73, 0x2e, 0x65, 0x78, 0x65, 0x63, 0x5d,
0x20, 0x61, 0x6c, 0x72, 0x65, 0x61, 0x64, 0x79, 0x20, 0x61, 0x72, 0x65, 0x20, 0x73, 0x68, 0x65,
0x6c, 0x6c, 0x65, 0x73, 0x63, 0x61, 0x70, 0x65, 0x20, 0x61, 0x77, 0x61, 0x72, 0x65, 0x29, 0x0a,
0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x00
0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x69, 0x66, 0x20, 0x6d, 0x64, 0x35, 0x20, 0x74, 0x68, 0x65,
0x6e, 0x0a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x75, 0x6d,
0x20, 0x20, 0x20, 0x20, 0x3d, 0x20, 0x6d, 0x64, 0x35, 0x2e, 0x73, 0x75, 0x6d, 0x0a, 0x20, 0x20,
0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x67, 0x73, 0x75, 0x62, 0x20, 0x20, 0x20, 0x3d,
0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x0a, 0x20, 0x20, 0x20,
0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x20, 0x3d, 0x20,
0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x0a, 0x20, 0x20,
0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x79, 0x74, 0x65, 0x20, 0x20, 0x20, 0x3d,
0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x0a, 0x0a, 0x20, 0x20,
0x20, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6d, 0x64, 0x35, 0x2e, 0x73,
0x75, 0x6d, 0x68, 0x65, 0x78, 0x61, 0x28, 0x6b, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x28, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73,
0x75, 0x6d, 0x28, 0x6b, 0x29, 0x2c, 0x20, 0x22, 0x2e, 0x22, 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63,
0x74, 0x69, 0x6f, 0x6e, 0x28, 0x63, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x61,
0x74, 0x28, 0x22, 0x25, 0x30, 0x32, 0x78, 0x22, 0x2c, 0x62, 0x79, 0x74, 0x65, 0x28, 0x63, 0x29,
0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x29, 0x29, 0x0a,
0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x75, 0x6e,
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6d, 0x64, 0x35, 0x2e, 0x73, 0x75, 0x6d, 0x48, 0x45, 0x58,
0x41, 0x28, 0x6b, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74,
0x75, 0x72, 0x6e, 0x20, 0x28, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x75, 0x6d, 0x28, 0x6b, 0x29,
0x2c, 0x20, 0x22, 0x2e, 0x22, 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28,
0x63, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72,
0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x28, 0x22, 0x25, 0x30,
0x32, 0x58, 0x22, 0x2c, 0x62, 0x79, 0x74, 0x65, 0x28, 0x63, 0x29, 0x29, 0x0a, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x29, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65,
0x6e, 0x64, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x00
};
return luaL_dostring(L, (const char*) luatex_core_lua);
}
}
\ No newline at end of file
if not modules then modules = { } end modules ['luatex-core'] = {
version = 1.04,
comment = "companion to luatex",
author = "Hans Hagen & Luigi Scarso",
copyright = "LuaTeX Development Team",
}
-- This file overloads some Lua functions. The readline variants provide the same
-- functionality as LuaTeX <= 1.04 and doing it this way permits us to keep the
-- original io libraries clean. Performance is probably even a bit better now.
local type, next, getmetatable, require = type, next, getmetatable, require
local find, gsub = string.find, string.gsub
local io_open = io.open
local io_popen = io.popen
local fio_readline = fio.readline
local fio_checkpermission = fio.checkpermission
local fio_recordfilename = fio.recordfilename
local mt = getmetatable(io.stderr)
local saferoption = false
local shellescape = status.shell_escape -- 0 1 2
local restricted = status.shell_restricted -- 0 1
local kpseused = status.kpse_used -- 0 1
local function luatex_io_open(name,how)
if not how then
how = "r"
end
local f = io_open(name,how)
if f then
if type(how) == "string" and find(how,"w") then
fio_recordfilename(name,"w")
else
fio_recordfilename(name,"r")
end
end
return f
end
local function luatex_io_open_readonly(name,how)
if how then
how = "r"
else
how = gsub(how,"[^rb]","")
if how == "" then
how = "r"
end
end
local f = io_open(name,how)
if f then
fio_recordfilename(name,"r")
end
return f
end
local function luatex_io_popen(name,...)
local okay, found = fio_checkpermission(name)
if okay and found then
return io_popen(found,...)
end
end
local function luatex_io_lines(name)
local f = io_open(name,'r')
if f then
return function()
return fio_readline(f)
end
end
end
local function luatex_io_readline(f)
return function()
return fio_readline(f)
end
end
io.saved_lines = io.lines
mt.saved_lines = mt.lines
io.lines = luatex_io_lines
mt.lines = luatex_io_readline
if kpseused == 1 then
io.open = luatex_io_open
io.popen = luatex_io_popen
if saferoption then
os.execute = nil
os.spawn = nil
os.exec = nil
io.popen = nil
io.open = luatex_io_open_readonly
os.rename = nil
os.remove = nil
io.tmpfile = nil
io.output = nil
lfs.chdir = nil
lfs.lock = nil
lfs.touch = nil
lfs.rmdir = nil
lfs.mkdir = nil
end
if saferoption or shellescape == 0 or (shellescape == 1 and restricted == 1) then
local ffi = require("ffi")
for k, v in next, ffi do
if k ~= 'gc' then
ffi[k] = nil
end
ffi = nil
end
end
-- todo: os.execute
-- todo: os.spawn
-- todo: os.exec
else
-- We assume management to be provided by the replacement of kpse. This is the
-- case in ConTeXt.
end
-- if not modules then modules = { } end modules ['luatex-core'] = {
-- version = 1.001,
-- comment = 'companion to luatex',
-- author = 'Hans Hagen & Luigi Scarso',
-- copyright = 'LuaTeX Development Team',
-- }
LUATEXCOREVERSION = 1.001
-- This file overloads some Lua functions. The readline variants provide the same
-- functionality as LuaTeX <= 1.04 and doing it this way permits us to keep the
-- original io libraries clean. Performance is probably even a bit better now.
local type, next, getmetatable, require = type, next, getmetatable, require
local find, gsub = string.find, string.gsub
local io_open = io.open
local io_popen = io.popen
local io_line = io.lines
local fio_readline = fio.readline
local fio_checkpermission = fio.checkpermission
local fio_recordfilename = fio.recordfilename
local mt = getmetatable(io.stderr)
local mt_lines = mt.lines
local saferoption = status.safer_option
local shellescape = status.shell_escape -- 0 (disabled) 1 (restricted) 2 (everything)
local kpseused = status.kpse_used -- 0 1
io.saved_open = io_open -- can be protected
io.saved_popen = io_popen -- can be protected
io.saved_lines = io_lines -- always readonly
mt.saved_lines = mt_lines -- always readonly
local function luatex_io_open(name,how)
if not how then
how = 'r'
end
local f = io_open(name,how)
if f then
if type(how) == 'string' and find(how,'w') then
fio_recordfilename(name,'w')
else
fio_recordfilename(name,'r')
end
end
return f
end
local function luatex_io_open_readonly(name,how)
if how then
how = 'r'
else
how = gsub(how,'[^rb]','')
if how == '' then
how = 'r'
end
end
local f = io_open(name,how)
if f then
fio_recordfilename(name,'r')
end
return f
end
local function luatex_io_popen(name,...)
local okay, found = fio_checkpermission(name)
if okay and found then
return io_popen(found,...)
end
end
local function luatex_io_lines(name)
local f = io_open(name,'r')
if f then
return function()
return fio_readline(f)
end
end
end
local function luatex_io_readline(f)
return function()
return fio_readline(f)
end
end
io.lines = luatex_io_lines
mt.lines = luatex_io_readline
-- We assume management to be provided by the replacement of kpse. This is the
-- case in ConTeXt.
if kpseused == 1 then
io.open = luatex_io_open
io.popen = luatex_io_popen
if saferoption then
os.execute = nil
os.spawn = nil
os.exec = nil
os.setenv = nil
os.tempdir = nil
io.popen = nil
io.open = nil
os.rename = nil
os.remove = nil
io.tmpfile = nil
io.output = nil
lfs.chdir = nil
lfs.lock = nil
lfs.touch = nil
lfs.rmdir = nil
lfs.mkdir = nil
io.saved_popen = nil
io.saved_open = luatex_io_open_readonly
end
if saferoption or shellescape ~= 2 then
local ffi = require('ffi')
for k, v in next, ffi do
if k ~= 'gc' then
ffi[k] = nil
end
ffi = nil
end
end
-- os.[execute|os.spawn|os.exec] already are shellescape aware)
end
if md5 then
local sum = md5.sum
local gsub = string.gsub
local format = string.format
local byte = string.byte
function md5.sumhexa(k)
return (gsub(sum(k), ".", function(c)
return format("%02x",byte(c))
end))
end
function md5.sumHEXA(k)
return (gsub(sum(k), ".", function(c)
return format("%02X",byte(c))
end))
end
end
if utilities and utilities.merger and utilities.merger.compact then
local byte, format, gmatch = string.byte, string.format, string.gmatch
local concat = table.concat
local data = gsub(io.loaddata('luatex-core.lua'),'if%s+utilities.*','')
local t = { }
local r = { }
local n = 0
local d = gsub(data,'\r\n','\n') -- be nice for unix
local s = utilities.merger.compact(d) -- no comments and less spaces
t[#t+1] = '/* generated from and by luatex-core.lua */'
t[#t+1] = ''
-- t[#t+1] = format('/*\n\n%s\n\n*/',d)
-- t[#t+1] = ''
t[#t+1] = '#include "lua.h"'
t[#t+1] = '#include "lauxlib.h"'
t[#t+1] = ''
t[#t+1] = 'int load_luatex_core_lua (lua_State * L);'
t[#t+1] = ''
t[#t+1] = 'int load_luatex_core_lua (lua_State * L)'
t[#t+1] = '{'
t[#t+1] = ' static unsigned char luatex_core_lua[] = {'
for c in gmatch(d,'.') do
if n == 16 then
n = 1
t[#t+1] = ' ' .. concat(r,', ') .. ','
else
n = n + 1
end
r[n] = format('0x%02x',byte(c))
end
n = n + 1
r[n] = '0x00'
t[#t+1] = ' ' .. concat(r,', ',1,n)
t[#t+1] = ' };'
-- t[#t+1] = format('unsigned int luatex_core_lua_len = 0x%x;',#d+1)
t[#t+1] = ' return luaL_dostring(L, (const char*) luatex_core_lua);'
t[#t+1] = '}'
io.savedata('luatex-core.c',concat(t,'\n'))
io.savedata('luatex-core-stripped.lua',s)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment