#!/usr/bin/env lua -- -*- lua -*- local sys_lua_path = "@sys_lua_path@" if (sys_lua_path:sub(1,1) == "@") then sys_lua_path = package.path end local sys_lua_cpath = "@sys_lua_cpath@" if (sys_lua_cpath:sub(1,1) == "@") then sys_lua_cpath = package.cpath end package.path = sys_lua_path package.cpath = sys_lua_cpath local arg_0 = arg[0] _G._DEBUG = false local posix = require("posix") local readlink = posix.readlink local stat = posix.stat local st = stat(arg_0) while (st.type == "link") do local lnk = readlink(arg_0) if (arg_0:find("/") and (lnk:find("^/") == nil)) then local dir = arg_0:gsub("/[^/]*$","") lnk = dir .. "/" .. lnk end arg_0 = lnk st = stat(arg_0) end local ia,ja = arg_0:find(".*/") local LuaCommandName = false local LuaCommandName_dir = "./" if (ia) then LuaCommandName_dir = arg_0:sub(1,ja) LuaCommandName = arg_0:sub(ja+1) end package.path = LuaCommandName_dir .. "?.lua;" .. LuaCommandName_dir .. "../tools/?.lua;" .. LuaCommandName_dir .. "../tools/?/init.lua;" .. LuaCommandName_dir .. "../shells/?.lua;" .. LuaCommandName_dir .. "?/init.lua;" .. sys_lua_path package.cpath = LuaCommandName_dir .. "../lib/?.so;".. sys_lua_cpath require("strict") require("string_utils") require("serializeTbl") local dbg = require("Dbg"):dbg() if ( _VERSION ~= "Lua 5.1" ) then require("declare") declare("loadstring") loadstring = load end local json = require("json") local getenv = os.getenv local strfmt = string.format local concatTbl = table.concat local base64 = require("base64") local decode64 = base64.decode64 function main() -- dbg:activateDebug(1) local fn = arg[1] local f = io.open(fn) if (not f) then io.stderr:write("Error: ",fn,"not found!\n") exit(1) end local whole = f:read("*all") f:close() local tbl = json.decode(whole) local nblks = tonumber(tbl.env._ModuleTable_Sz_) local sA = {} local piece = "_ModuleTable%03d_" tbl.env._ModuleTable_Sz_ = nil for i = 1,nblks do local envNm = strfmt(piece,i) sA[#sA+1] = tbl.env[envNm] tbl.env[envNm] = nil end tbl.env.MT = decode64(concatTbl(sA)) local s = serializeTbl{ indent = true, name = "loadTbl", value = tbl} io.stdout:write(s) end main()