| 1 |
#!/usr/bin/env lua |
| 2 |
-- -*- lua -*- |
| 3 |
|
| 4 |
local sys_lua_path = "@sys_lua_path@" |
| 5 |
if (sys_lua_path:sub(1,1) == "@") then |
| 6 |
sys_lua_path = package.path |
| 7 |
end |
| 8 |
|
| 9 |
local sys_lua_cpath = "@sys_lua_cpath@" |
| 10 |
if (sys_lua_cpath:sub(1,1) == "@") then |
| 11 |
sys_lua_cpath = package.cpath |
| 12 |
end |
| 13 |
|
| 14 |
package.path = sys_lua_path |
| 15 |
package.cpath = sys_lua_cpath |
| 16 |
|
| 17 |
local arg_0 = arg[0] |
| 18 |
_G._DEBUG = false |
| 19 |
local posix = require("posix") |
| 20 |
local readlink = posix.readlink |
| 21 |
local stat = posix.stat |
| 22 |
|
| 23 |
local st = stat(arg_0) |
| 24 |
while (st.type == "link") do |
| 25 |
local lnk = readlink(arg_0) |
| 26 |
if (arg_0:find("/") and (lnk:find("^/") == nil)) then |
| 27 |
local dir = arg_0:gsub("/[^/]*$","") |
| 28 |
lnk = dir .. "/" .. lnk |
| 29 |
end |
| 30 |
arg_0 = lnk |
| 31 |
st = stat(arg_0) |
| 32 |
end |
| 33 |
|
| 34 |
local ia,ja = arg_0:find(".*/") |
| 35 |
local LuaCommandName = false |
| 36 |
local LuaCommandName_dir = "./" |
| 37 |
if (ia) then |
| 38 |
LuaCommandName_dir = arg_0:sub(1,ja) |
| 39 |
LuaCommandName = arg_0:sub(ja+1) |
| 40 |
end |
| 41 |
|
| 42 |
package.path = LuaCommandName_dir .. "?.lua;" .. |
| 43 |
LuaCommandName_dir .. "../tools/?.lua;" .. |
| 44 |
LuaCommandName_dir .. "../tools/?/init.lua;" .. |
| 45 |
LuaCommandName_dir .. "../shells/?.lua;" .. |
| 46 |
LuaCommandName_dir .. "?/init.lua;" .. |
| 47 |
sys_lua_path |
| 48 |
package.cpath = LuaCommandName_dir .. "../lib/?.so;".. |
| 49 |
sys_lua_cpath |
| 50 |
|
| 51 |
require("strict") |
| 52 |
require("string_utils") |
| 53 |
require("serializeTbl") |
| 54 |
local dbg = require("Dbg"):dbg() |
| 55 |
if ( _VERSION ~= "Lua 5.1" ) then |
| 56 |
require("declare") |
| 57 |
declare("loadstring") |
| 58 |
loadstring = load |
| 59 |
end |
| 60 |
local json = require("json") |
| 61 |
local getenv = os.getenv |
| 62 |
local strfmt = string.format |
| 63 |
local concatTbl = table.concat |
| 64 |
local base64 = require("base64") |
| 65 |
local decode64 = base64.decode64 |
| 66 |
|
| 67 |
|
| 68 |
function main() |
| 69 |
-- dbg:activateDebug(1) |
| 70 |
local fn = arg[1] |
| 71 |
local f = io.open(fn) |
| 72 |
if (not f) then |
| 73 |
io.stderr:write("Error: ",fn,"not found!\n") |
| 74 |
exit(1) |
| 75 |
end |
| 76 |
|
| 77 |
local whole = f:read("*all") |
| 78 |
f:close() |
| 79 |
local tbl = json.decode(whole) |
| 80 |
local nblks = tonumber(tbl.env._ModuleTable_Sz_) |
| 81 |
local sA = {} |
| 82 |
local piece = "_ModuleTable%03d_" |
| 83 |
|
| 84 |
tbl.env._ModuleTable_Sz_ = nil |
| 85 |
for i = 1,nblks do |
| 86 |
local envNm = strfmt(piece,i) |
| 87 |
sA[#sA+1] = tbl.env[envNm] |
| 88 |
tbl.env[envNm] = nil |
| 89 |
end |
| 90 |
|
| 91 |
tbl.env.MT = decode64(concatTbl(sA)) |
| 92 |
|
| 93 |
|
| 94 |
local s = serializeTbl{ indent = true, name = "loadTbl", |
| 95 |
value = tbl} |
| 96 |
io.stdout:write(s) |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
end |
| 101 |
|
| 102 |
|
| 103 |
main() |